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

Method with_values

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

Returns a copy of `self` with `values` replaced by `new_value`. Preserves cached row-partitioning tensors such as `self.cached_nrows` and `self.cached_value_rowids` if they have values. Args: new_values: Potentially ragged tensor to use as the `values` for the returned `R

(self, new_values)

Source from the content-addressed store, hash-verified

1223 #=============================================================================
1224
1225 def with_values(self, new_values):
1226 """Returns a copy of `self` with `values` replaced by `new_value`.
1227
1228 Preserves cached row-partitioning tensors such as `self.cached_nrows` and
1229 `self.cached_value_rowids` if they have values.
1230
1231 Args:
1232 new_values: Potentially ragged tensor to use as the `values` for the
1233 returned `RaggedTensor`. Must have `rank > 0`, and must have the same
1234 number of rows as `self.values`.
1235
1236 Returns:
1237 A `RaggedTensor`. `result.rank = 1 + new_values.rank`.
1238 `result.ragged_rank = 1 + new_values.ragged_rank`
1239 """
1240 new_values.shape.with_rank_at_least(1)
1241 self.values.shape[:1].assert_is_compatible_with(new_values.shape[:1])
1242 if (isinstance(new_values, RaggedTensor) and
1243 self._row_splits.dtype != new_values.row_splits.dtype):
1244 if not ragged_config.auto_cast_partition_dtype():
1245 raise ValueError("self and new_values have mismatched row_splits "
1246 "dtypes; use RaggedTensor.with_row_splits_dtype() to "
1247 "convert them to compatible dtypes.")
1248 new_values = new_values.with_row_splits_dtype(dtypes.int64)
1249 return self.with_row_splits_dtype(dtypes.int64).with_values(new_values)
1250 return RaggedTensor(
1251 new_values,
1252 self._row_splits,
1253 self._cached_row_lengths,
1254 self._cached_value_rowids,
1255 self._cached_nrows,
1256 internal=True)
1257
1258 def with_flat_values(self, new_values):
1259 """Returns a copy of `self` with `flat_values` replaced by `new_value`.

Callers 11

row_lengthsMethod · 0.95
with_flat_valuesMethod · 0.95
ragged_reduce_aggregateFunction · 0.80
gatherFunction · 0.80
_increase_ragged_rank_toFunction · 0.80
testWithValuesMethod · 0.80
unicode_encodeFunction · 0.80
ngramsFunction · 0.80
_ragged_tile_axisFunction · 0.80

Calls 4

with_row_splits_dtypeMethod · 0.95
with_rank_at_leastMethod · 0.80
RaggedTensorClass · 0.70

Tested by 1

testWithValuesMethod · 0.64