From d036b082d1b1af7c5fca1af6c6b7c3159c974710 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:03:17 +0100 Subject: [PATCH] Create rule S6925 (#3634) --- rules/S6925/metadata.json | 2 ++ rules/S6925/python/metadata.json | 24 ++++++++++++++++++++++ rules/S6925/python/rule.adoc | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 rules/S6925/metadata.json create mode 100644 rules/S6925/python/metadata.json create mode 100644 rules/S6925/python/rule.adoc diff --git a/rules/S6925/metadata.json b/rules/S6925/metadata.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/rules/S6925/metadata.json @@ -0,0 +1,2 @@ +{ +} diff --git a/rules/S6925/python/metadata.json b/rules/S6925/python/metadata.json new file mode 100644 index 0000000000..bbf5114a55 --- /dev/null +++ b/rules/S6925/python/metadata.json @@ -0,0 +1,24 @@ +{ + "title": "The \"validate_indices\" argument should not be set for \"tf.gather\" function call", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-6925", + "sqKey": "S6925", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "MAINTAINABILITY": "HIGH", + "RELIABILITY": "MEDIUM" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S6925/python/rule.adoc b/rules/S6925/python/rule.adoc new file mode 100644 index 0000000000..909ff66401 --- /dev/null +++ b/rules/S6925/python/rule.adoc @@ -0,0 +1,34 @@ +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]