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)
| 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`. |