tensorflow/tensorflow

View on GitHub
tensorflow/python/ops/parallel_for/pfor.py

Summary

Maintainability
F
1 wk
Test Coverage

File pfor.py has 3878 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2018 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: Major
Found in tensorflow/python/ops/parallel_for/pfor.py - About 1 wk to fix

    Function __init__ has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in tensorflow/python/ops/parallel_for/pfor.py - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if reduce_output is not None:
                new_outputs = reduce_output
              # None of the inputs and control inputs were converted.
              elif ((not is_inside_loop or
                     (not is_stateful and not some_input_converted and
      Severity: Major
      Found in tensorflow/python/ops/parallel_for/pfor.py - About 1 hr to fix

        Function _process_body has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def _process_body(
        Severity: Major
        Found in tensorflow/python/ops/parallel_for/pfor.py - About 50 mins to fix

          Function _process_body has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def _process_body(self, inputs_stacked, new_indices, cond_stacked,
          Severity: Minor
          Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if converted_cinp != cinp:
                          some_control_input_converted = True
                        converted_control_ops.add(converted_cinp)
            Severity: Major
            Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

              Function _init_pfor has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                def _init_pfor(self, parent_pfor, indices, cond_stacked, inputs,
              Severity: Minor
              Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if output.dtype in (dtypes.resource, dtypes.variant):
                              if output not in self._direct_enters:
                                self._direct_enters.append(output)
                            else:
                              self._enters.append(output)
                Severity: Major
                Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                if not self._fallback_to_while_loop:
                                  message += ("Consider enabling the fallback_to_while_loop "
                                              "option to pfor, which may run slower.")
                                raise ValueError(message)
                  Severity: Major
                  Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                for t in cinp.outputs:
                                  added_to_stack |= _add_to_stack(t)
                              else:
                    Severity: Major
                    Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  for t in cinp.outputs:
                                    converted_t = self._conversion_map[t]
                                    if self._was_converted(t):
                                      some_control_input_converted = True
                                    converted_control_ops.add(converted_t.t.op)
                      Severity: Major
                      Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                    for old_output, new_output in zip(y_op.outputs, new_op.outputs):
                                      handle_data_util.copy_handle_data(old_output, new_output)
                                      new_outputs.append(wrap(new_output, False))
                                else:
                        Severity: Major
                        Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                          if loop_len is None:
                                            batch_dim = tensor_shape.TensorShape([None])
                                          else:
                                            batch_dim = tensor_shape.TensorShape(loop_len)
                                          output_shape = batch_dim.concatenate(output_shape)
                          Severity: Major
                          Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                            Function _process_cond_stacked has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              def _process_cond_stacked(self, conditions, indices, inputs, inputs_stacked,
                            Severity: Minor
                            Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                              Function _process_cond_stacked has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                def _process_cond_stacked(self, conditions, indices, inputs, inputs_stacked,
                              Severity: Minor
                              Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                            if (self._fallback_to_while_loop and not has_variant_outputs
                                                and not has_vectorized_variant_inputs):
                                              converter = functools.partial(
                                                  _fallback_converter, root_cause=root_cause, warn=self._warn)
                                            else:
                                Severity: Major
                                Found in tensorflow/python/ops/parallel_for/pfor.py - About 45 mins to fix

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

                                    def __init__(
                                  Severity: Minor
                                  Found in tensorflow/python/ops/parallel_for/pfor.py - About 35 mins to fix

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

                                      def _process_cond_unstacked(self, conditions, indices, inputs, output_tas):
                                    Severity: Minor
                                    Found in tensorflow/python/ops/parallel_for/pfor.py - About 35 mins to fix

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

                                        def _process_cond_unstacked(self, conditions, indices, inputs, output_tas):
                                      Severity: Minor
                                      Found in tensorflow/python/ops/parallel_for/pfor.py - About 35 mins to fix

                                        Function _stack has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                        def _stack(t, length):
                                          """stacks `t` `length` times."""
                                          # Note that this stacking may currently be triggered, for example, when a
                                          # loop invariant tensor with dtype variant is input to a while_loop which then
                                          # produces a loop dependent output. Simply stacking the variants may not be
                                        Severity: Minor
                                        Found in tensorflow/python/ops/parallel_for/pfor.py - About 35 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_variant_shapes_and_types has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                        def _parse_variant_shapes_and_types(t):
                                          """Extracts shape and dtype information from a variant tensor `t`."""
                                          shapes_and_types = _variant_handle_data(t)
                                          if shapes_and_types is None or not shapes_and_types:
                                            raise ValueError("Required handle data not set for {!r}".format(t))
                                        Severity: Minor
                                        Found in tensorflow/python/ops/parallel_for/pfor.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

                                        There are no issues that match your filters.

                                        Category
                                        Status