tensorflow/tensorflow

View on GitHub
tensorflow/python/ops/ragged/dynamic_ragged_shape.py

Summary

Maintainability
F
1 wk
Test Coverage

File dynamic_ragged_shape.py has 2626 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: Major
Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 1 wk to fix

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

      def __init__(self,
                   row_partitions: Sequence[RowPartition],
                   inner_shape: core.TensorLike,
                   dtype: Optional[dtypes.DType] = None,
                   validate: bool = False,
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 3 hrs 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 _slice_shape has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      def _slice_shape(self, start, stop):
        """Returns a shape self[start:stop].
    
        If start == 0, then this truncates dimensions after stop.
        If start != 0, then this will return a shape with num_row_partitions == 0.
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 3 hrs 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 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, row_partitions: Tuple[RowPartitionSpec, ...],
                     static_inner_shape: tensor_shape.TensorShape,
                     dtype: dtypes.DType):
          """Create a Spec given row partitions, a static inner shape, and a dtype.
    
    
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 3 hrs 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 _dimension has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      def _dimension(self, index):
        """Return a dimension, if the dimension is not ragged (see __getitem__)."""
        rank = self.rank
        if not isinstance(index, int):
          raise TypeError("index should be an int")
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 2 hrs 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 unbatch has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def unbatch(self,
                  spec: "DynamicRaggedShape.Spec") -> "DynamicRaggedShape.Spec":
        if spec.num_row_partitions:
          result = []
          head = spec._row_partitions[0]  # pylint:disable=protected-access
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 2 hrs 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 from_lengths has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def from_lengths(cls,
                       lengths: Sequence[Union[Sequence[int], int]],
                       num_row_partitions=None,
                       dtype=dtypes.int64):
        """Creates a shape with the given lengths and num_row_partitions.
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 __getitem__ has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def __getitem__(self, index):
        """Returns a dimension or a slice of the shape.
    
        Ragged shapes can have ragged dimensions that depend upon other dimensions.
        Therefore, if you ask for a dimension that is ragged, this function returns
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 _from_tensor_shape has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def _from_tensor_shape(cls, shape: Any, num_row_partitions: int,
                               dtype: dtypes.DType) -> "DynamicRaggedShape.Spec":
          """Creates a `DynamicRaggedShape.Spec` corresponding to a `tf.TensorShape`.
    
          It is assumed that this is a `tf.TensorShape` coming from a
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 static_lengths has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def static_lengths(self, ragged_lengths=True):
        """Returns a list of statically known axis lengths.
    
        This represents what values are known. For each row partition, it presents
        either the uniform row length (if statically known),
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 _alt_inner_shape has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def _alt_inner_shape(self, new_inner_rank):
        """Get an alternative inner shape with higher or lower rank.
    
        For the rank of the inner shape to be be higher, the last few ragged
        dimensions must have uniform_row_length.
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 _dimension has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def _dimension(self, index: int) -> Optional[int]:
          """Get the size of dimension index, if known statically."""
          if index == 0:
            if self._row_partitions:
              return self._row_partitions[0].nrows
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 _with_num_row_partitions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def _with_num_row_partitions(self, num_row_partitions):
        """Creates an identical shape with the given num_row_partitions.
    
        Note that the shape must be statically refactorable to this rank.
        In particular:
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 55 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 _broadcast_dynamic_shape_extended_complete has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _broadcast_dynamic_shape_extended_complete(
    Severity: Minor
    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 45 mins to fix

      Consider simplifying this complex logical expression.
      Open

        if ((x_is_ragged and y_is_ragged) or
            (x_is_ragged and x.flat_values.shape.ndims <= y.shape.ndims) or
            (y_is_ragged and y.flat_values.shape.ndims <= x.shape.ndims)):
          shape_x = DynamicRaggedShape.from_tensor(x)
      Severity: Major
      Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

          if ((x_is_ragged and y_is_ragged) or
              (x_is_ragged and x.flat_values.shape.ndims <= y.shape.ndims) or
              (y_is_ragged and y.flat_values.shape.ndims <= x.shape.ndims)):
            shape_x = DynamicRaggedShape.from_tensor(x)
        Severity: Major
        Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 40 mins to fix

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

            def __init__(self,
          Severity: Minor
          Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 35 mins to fix

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

              def __init__(self,
            Severity: Minor
            Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 35 mins to fix

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

                  def _set_rank_if_unknown(self, new_rank: int) -> "DynamicRaggedShape.Spec":
                    """Ensures this has a known rank at least new_rank."""
                    if new_rank is None:
                      raise TypeError("new_rank is None, but expected int")
                    if new_rank < 0:
              Severity: Minor
              Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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

              Avoid too many return statements within this function.
              Open

                      return DynamicRaggedShape(
              Severity: Major
              Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return DynamicRaggedShape.Spec(
                Severity: Major
                Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return None
                  Severity: Major
                  Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return constant_op.constant(static_result, dtype=self.dtype)
                    Severity: Major
                    Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return array_ops.concat(
                      Severity: Major
                      Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return self.inner_shape[index - self.num_row_partitions]
                        Severity: Major
                        Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                    return self
                          Severity: Major
                          Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return DynamicRaggedShape._from_inner_shape(
                            Severity: Major
                            Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return self.row_partitions[index - 1].uniform_row_length()
                              Severity: Major
                              Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return tensor_shape.dimension_value(
                                Severity: Major
                                Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.py - About 30 mins to fix

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

                                    def batch(self, spec: "DynamicRaggedShape.Spec",
                                              batch_size) -> "DynamicRaggedShape.Spec":
                                      if spec.num_row_partitions:
                                        new_head = _batch_rp_spec_head(spec._row_partitions[0], batch_size)  # pylint:disable=protected-access
                                        new_tail = [_batch_rp_spec(rp, batch_size) for rp in spec._row_partitions]  # pylint:disable=protected-access
                                  Severity: Minor
                                  Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 is_uniform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    def is_uniform(self, axis):
                                      """Returns true if the indicated dimension is uniform."""
                                      if not isinstance(axis, int):
                                        raise TypeError("axis must be an integer")
                                      rank = self.rank
                                  Severity: Minor
                                  Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 _with_num_row_partitions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      def _with_num_row_partitions(
                                          self, new_num_row_partitions: int) -> "DynamicRaggedShape.Spec":
                                        """Change the number of row partitions in the spec."""
                                        rank = self.rank
                                        if rank is None:
                                  Severity: Minor
                                  Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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 _num_slices_in_dimension has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    def _num_slices_in_dimension(self, axis):
                                      """The total size of a dimension (like nvals).
                                  
                                      Effectively, this is self[:axis+1]._num_elements()
                                  
                                  
                                  Severity: Minor
                                  Found in tensorflow/python/ops/ragged/dynamic_ragged_shape.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