MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / row_lengths

Method row_lengths

tensorflow/python/ops/ragged/ragged_tensor.py:1104–1146  ·  view source on GitHub ↗

Returns the lengths of the rows in this ragged tensor. `rt.row_lengths()[i]` indicates the number of values in the `i`th row of `rt`. Args: axis: An integer constant indicating the axis whose row lengths should be returned. name: A name prefix for the returned tenso

(self, axis=1, name=None)

Source from the content-addressed store, hash-verified

1102 return self.row_splits[1:]
1103
1104 def row_lengths(self, axis=1, name=None):
1105 """Returns the lengths of the rows in this ragged tensor.
1106
1107 `rt.row_lengths()[i]` indicates the number of values in the
1108 `i`th row of `rt`.
1109
1110 Args:
1111 axis: An integer constant indicating the axis whose row lengths should be
1112 returned.
1113 name: A name prefix for the returned tensor (optional).
1114
1115 Returns:
1116 A potentially ragged integer Tensor with shape `self.shape[:axis]`.
1117
1118 Raises:
1119 ValueError: If `axis` is out of bounds.
1120
1121 #### Example:
1122 ```python
1123 >>> rt = ragged.constant([[[3, 1, 4], [1]], [], [[5, 9], [2]], [[6]], []])
1124 >>> rt.row_lengths(rt) # lengths of rows in rt
1125 tf.Tensor([2, 0, 2, 1, 0])
1126 >>> rt.row_lengths(axis=2) # lengths of axis=2 rows.
1127 <tf.RaggedTensor [[3, 1], [], [2, 1], [1], []]>
1128 ```
1129 """
1130 if self._cached_row_lengths is not None:
1131 return self._cached_row_lengths
1132
1133 with ops.name_scope(name, "RaggedRowLengths", [self]):
1134 axis = ragged_util.get_positive_axis(axis, self.shape.ndims)
1135 if axis == 0:
1136 return self.nrows()
1137 elif axis == 1:
1138 splits = self.row_splits
1139 return splits[1:] - splits[:-1]
1140 elif isinstance(self.values, RaggedTensor):
1141 return self.with_values(self.values.row_lengths(axis - 1))
1142 else:
1143 shape = array_ops.shape(self.values, out_type=self._row_splits.dtype)
1144 return self.with_values(
1145 array_ops.ones(shape[:axis - 1], self._row_splits.dtype) *
1146 shape[axis - 1])
1147
1148 def nested_row_lengths(self, name=None):
1149 """Returns a tuple containing the row_lengths for all ragged dimensions.

Callers 11

bounding_shapeMethod · 0.95
batch_gatherFunction · 0.80
testRowLengthsMethod · 0.80
testErrorsMethod · 0.80
boolean_maskFunction · 0.80
testFromRowLengthsMethod · 0.80
nested_row_lengthsMethod · 0.80

Calls 5

nrowsMethod · 0.95
with_valuesMethod · 0.95
onesMethod · 0.80
name_scopeMethod · 0.45
shapeMethod · 0.45