tensorflow/tensorflow

View on GitHub
tensorflow/lite/python/metrics/metrics_nonportable_test.py

Summary

Maintainability
F
4 days
Test Coverage

File metrics_nonportable_test.py has 471 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Minor
Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py - About 7 hrs to fix

    Function mock_ngrams has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def mock_ngrams(data, width, axis=-1, string_separator=' ', name=None):
      """This mock Ngrams lack the width attr, causing conversion to fail."""
    
      experimental_implements = [
          'name: "tftext:Ngrams"',
    Severity: Minor
    Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function mock_ngrams has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def mock_ngrams(data, width, axis=-1, string_separator=' ', name=None):
    Severity: Minor
    Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py - About 35 mins to fix

      Function convert_and_check_location_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def convert_and_check_location_info(self,
                                            converter,
                                            expected_type,
                                            expected_sources=None):
          # The custom attribute of ConverterError can't be accessed with
      Severity: Minor
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          def create_graph_with_custom_add(opname='CustomAdd'):
            custom_opdefs_str = (
                'name: \'' + opname +
                '\' input_arg: {name: \'Input1\' type: DT_FLOAT} '
                'input_arg: {name: \'Input2\' type: DT_FLOAT} output_arg: {name: '
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 1 other location - About 1 day to fix
      tensorflow/lite/python/lite_flex_test.py on lines 206..233

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 169.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

          with ops.Graph().as_default():
            in_tensor = array_ops.placeholder(
                shape=[None, 16, 16, 3], dtype=dtypes.float32, name='in_tensor')
            math_ops.add(in_tensor, in_tensor, name='add')
            sess = session.Session()
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 2 other locations - About 2 hrs to fix
      tensorflow/lite/python/lite_test.py on lines 150..154
      tensorflow/lite/python/lite_test.py on lines 207..211

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 61.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              @tf.function(input_signature=[
                  tf.TensorSpec(shape=[None, None, 2, 3, 3], dtype=tf.complex64),
                  tf.TensorSpec(shape=[None, None, 1, 3, 3], dtype=tf.complex64),
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 1 other location - About 2 hrs to fix
      tensorflow/lite/python/metrics/metrics_nonportable_test.py on lines 518..520

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 50.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          @tf.function(input_signature=[
              tf.TensorSpec(shape=[None, None, 2, 3, 3], dtype=tf.complex64),
              tf.TensorSpec(shape=[None, None, 1, 3, 3], dtype=tf.complex64),
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 1 other location - About 2 hrs to fix
      tensorflow/lite/python/metrics/metrics_nonportable_test.py on lines 540..542

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 50.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

          def calibration_gen():
            for _ in range(5):
              yield [np.random.uniform(-1, 1, size=(1, 5, 5, 3)).astype(np.float32)]
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 1 other location - About 1 hr to fix
      tensorflow/lite/python/lite_test.py on lines 891..893

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 47.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

          with ops.Graph().as_default():
            with session.Session() as sess:
              import_graph_def(new_graph, name='')
              saved_model.simple_save(sess, saved_model_dir, inputs, outputs)
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 2 other locations - About 1 hr to fix
      tensorflow/lite/python/lite_flex_test.py on lines 241..244
      tensorflow/lite/python/tflite_convert_test.py on lines 269..272

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 45.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        def test_converter_attempt_counter_increase_success(self):
          stub = metrics.TFLiteMetrics()
          stub.increase_counter_converter_attempt()
          self.assertEqual(metrics._counter_conversion_attempt.get_cell().value(), 1)
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 1 other location - About 1 hr to fix
      tensorflow/lite/python/metrics/metrics_nonportable_test.py on lines 93..96

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 42.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        def test_converter_success_counter_increase_success(self):
          stub = metrics.TFLiteMetrics()
          stub.increase_counter_converter_success()
          self.assertEqual(metrics._counter_conversion_success.get_cell().value(), 1)
      Severity: Major
      Found in tensorflow/lite/python/metrics/metrics_nonportable_test.py and 1 other location - About 1 hr to fix
      tensorflow/lite/python/metrics/metrics_nonportable_test.py on lines 88..91

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 42.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status