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
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,
- Read upRead up
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.
- Read upRead up
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.
- Read upRead up
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")
- Read upRead up
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
- Read upRead up
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.
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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),
- Read upRead up
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.
- Read upRead up
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
- Read upRead up
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:
- Read upRead up
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(
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)
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)
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self,
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self,
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:
- Read upRead up
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(
Avoid too many return
statements within this function. Open
return DynamicRaggedShape.Spec(
Avoid too many return
statements within this function. Open
return None
Avoid too many return
statements within this function. Open
return constant_op.constant(static_result, dtype=self.dtype)
Avoid too many return
statements within this function. Open
return array_ops.concat(
Avoid too many return
statements within this function. Open
return self.inner_shape[index - self.num_row_partitions]
Avoid too many return
statements within this function. Open
return self
Avoid too many return
statements within this function. Open
return DynamicRaggedShape._from_inner_shape(
Avoid too many return
statements within this function. Open
return self.row_partitions[index - 1].uniform_row_length()
Avoid too many return
statements within this function. Open
return tensor_shape.dimension_value(
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
- Read upRead up
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
- Read upRead up
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:
- Read upRead up
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()
- Read upRead up
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"