rspec/rules/S6925/python/rule.adoc
2024-03-22 15:03:17 +01:00

35 lines
976 B
Plaintext

This rule raises an issue when the `validate_indices` argument is set for `tf.gather ` function call.
== Why is this an issue?
The `tf.gather` function allows you to gather slices from a tensor along a specified axis according to the indices provided.
The `validate_indices` argument is deprecated and setting its value has no effect. Indices are always validated on CPU and never validated on GPU.
== How to fix it
=== Code examples
==== Noncompliant code example
[source,python,diff-id=1,diff-type=noncompliant]
----
import tensorflow as tf
x = tf.constant([[1, 2], [3, 4]])
y = tf.gather(x, [1], validate_indices=True) # Noncompliant: validate_indices is deprecated
----
==== Compliant solution
[source,python,diff-id=1,diff-type=compliant]
----
import tensorflow as tf
x = tf.constant([[1, 2], [3, 4]])
y = tf.gather(x, [1]) # OK
----
== Resources
=== Documentation
* Tensorflow documentation - https://www.tensorflow.org/api_docs/python/tf/gather[tf.gather]