tensorflow/tensorflow

View on GitHub

Showing 8,379 of 21,083 total issues

Avoid too many return statements within this function.
Open

    return fb
Severity: Major
Found in tensorflow/lite/tools/visualize.py - About 30 mins to fix

    Method readCpusAllowedMask has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      public static int readCpusAllowedMask() throws IOException {
        // Determine how many CPUs there are total
        final String pathname = "/proc/self/status";
        final String resultPrefix = "Cpus_allowed:";
        File file = new File(pathname);
    Severity: Minor
    Found in tensorflow/lite/java/ovic/demo/app/OvicBenchmarkerActivity.java - 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

    Method classifyByteBuffer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      public OvicClassificationResult classifyByteBuffer(ByteBuffer imgData) {
        if (tflite == null) {
          throw new RuntimeException(TAG + ": ImageNet classifier has not been initialized; Failed.");
        }
        if (outputIsFloat == null) {

    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

    Method copyTo has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      void copyTo(Object dst) {
        if (dst == null) {
          if (hasDelegateBufferHandle(nativeHandle)) {
            return;
          }
    Severity: Minor
    Found in tensorflow/lite/java/src/main/java/org/tensorflow/lite/TensorImpl.java - 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

    Method throwIfDstShapeIsIncompatible has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      private void throwIfDstShapeIsIncompatible(Object dst) {
        if (isBuffer(dst)) {
          Buffer dstBuffer = (Buffer) dst;
          int bytes = numBytes();
          // Note that we allow the client to provide a ByteBuffer even for non-byte Tensors.
    Severity: Minor
    Found in tensorflow/lite/java/src/main/java/org/tensorflow/lite/TensorImpl.java - 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

    Method computeTopKLabels has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      private OvicClassificationResult computeTopKLabels() {
        if (labelList == null) {
          throw new RuntimeException("Label file has not been loaded.");
        }
        for (int i = 0; i < labelList.size(); ++i) {

    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

    Method copyTo has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      private void copyTo(Buffer dst) {
        // There is no base Buffer#put() method, so we have to ugly cast.
        if (dst instanceof ByteBuffer) {
          ((ByteBuffer) dst).put(buffer());
        } else if (dst instanceof FloatBuffer) {
    Severity: Minor
    Found in tensorflow/lite/java/src/main/java/org/tensorflow/lite/TensorImpl.java - 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

    Method throwIfSrcShapeIsIncompatible has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      private void throwIfSrcShapeIsIncompatible(Object src) {
        if (isBuffer(src)) {
          Buffer srcBuffer = (Buffer) src;
          int bytes = numBytes();
          // Note that we allow the client to provide a ByteBuffer even for non-byte Tensors.
    Severity: Minor
    Found in tensorflow/lite/java/src/main/java/org/tensorflow/lite/TensorImpl.java - 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

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

        def testMemoryStats(self):
          for device in self.backend.local_devices():
            stats = device.memory_stats()
            if (
                self.backend.platform != "tpu" or not tfrt_tpu
    Severity: Minor
    Found in third_party/xla/xla/python/xla_client_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

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

    def shape_from_pyval(pyval, layout: Sequence[int] | None = None):
      """Returns a Shape that describes a tuple-tree of Numpy arrays."""
    
      def convert(pyval):
        if isinstance(pyval, tuple):
    Severity: Minor
    Found in third_party/xla/xla/python/xla_client.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

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

    def _expand_cmakedefines(line, cmake_vars):
      """Expands #cmakedefine declarations, using a dictionary 'cmake_vars'."""
    
      # Handles #cmakedefine lines
      match = _CMAKE_DEFINE_REGEX.match(line)
    Severity: Minor
    Found in third_party/xla/third_party/llvm_openmp/expand_cmake_vars.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

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

    def create_inference_graph(wanted_words, sample_rate, clip_duration_ms,
                               clip_stride_ms, window_size_ms, window_stride_ms,
                               feature_bin_count, model_architecture, preprocess):
      """Creates an audio model with the nodes needed for inference.
    
    
    Severity: Minor
    Found in tensorflow/examples/speech_commands/freeze.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

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

    def _expand_cmakedefines(line, cmake_vars):
      """Expands #cmakedefine declarations, using a dictionary 'cmake_vars'."""
    
      # Handles #cmakedefine lines
      match = _CMAKE_DEFINE_REGEX.match(line)

    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 _expand_cmakedefines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def _expand_cmakedefines(line, cmake_vars):
      """Expands #cmakedefine declarations, using a dictionary 'cmake_vars'."""
    
      # Handles #cmakedefine lines
      match = _CMAKE_DEFINE_REGEX.match(line)
    Severity: Minor
    Found in third_party/llvm_openmp/expand_cmake_vars.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

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

      def test_positional_arguments(self, cycles, use_cpp_bindings):
        # TODO(b/264869228) Fix LoadTest
        if use_cpp_bindings:
          self.skipTest("Not implemented for cpp.")
    
    
    Severity: Minor
    Found in tensorflow/python/saved_model/load_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

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

      def testGetFeaturesForWav(self):
        tmp_dir = self.get_temp_dir()
        wav_dir = os.path.join(tmp_dir, "wavs")
        os.mkdir(wav_dir)
        self._saveWavFolders(wav_dir, ["a", "b", "c"], 1)
    Severity: Minor
    Found in tensorflow/examples/speech_commands/input_data_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

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

    def run_search(
        existing_samples: typing.Set[MatmulSize],
    ) -> typing.Sequence[MatmulTiming]:
      """Run search on a list of matmul configurations."""
      samples: typing.Sequence[MatmulSize] = [
    Severity: Minor
    Found in third_party/xla/xla/experiments/triton_autotuning/search.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

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

    def parse_hunks(diff: str) -> list[Hunk]:
      """Parses a diff into hunks.
    
      Arguments:
        diff: The raw output of git diff.
    Severity: Minor
    Found in third_party/xla/build_tools/lint/diff_parser.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

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

      def test_table_collections_untouched_eager(self, cycles, use_cpp_bindings):
        # TODO(b/264869228) Fix LoadTest
        if use_cpp_bindings:
          self.skipTest("Not implemented for cpp.")
    
    
    Severity: Minor
    Found in tensorflow/python/saved_model/load_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

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

      def __init__(
          self,
          namespace_whitelist=None,
          save_debug_info=False,
          function_aliases=None,
    Severity: Minor
    Found in tensorflow/python/saved_model/save_options.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

    Severity
    Category
    Status
    Source
    Language