Constructs a `RaggedTensor` by tiling a given `RaggedTensor`. The values of `input` are replicated `multiples[i]` times along the `i`th dimension (for each dimension `i`). For every dimension `axis` in `input`, the length of each output element in that dimension is the length of correspond
(input, multiples, name=None)
| 206 | # Tiling |
| 207 | #=============================================================================== |
| 208 | def tile(input, multiples, name=None): # pylint: disable=redefined-builtin |
| 209 | """Constructs a `RaggedTensor` by tiling a given `RaggedTensor`. |
| 210 | |
| 211 | The values of `input` are replicated `multiples[i]` times along the |
| 212 | `i`th dimension (for each dimension `i`). For every dimension `axis` in |
| 213 | `input`, the length of each output element in that dimension is the |
| 214 | length of corresponding input element multiplied by `multiples[axis]`. |
| 215 | |
| 216 | Args: |
| 217 | input: A `RaggedTensor`. |
| 218 | multiples: A 1-D integer `Tensor`. Length must be the same as the number of |
| 219 | dimensions in `input`. |
| 220 | name: A name for the operation (optional). |
| 221 | |
| 222 | Returns: |
| 223 | A `RaggedTensor` with the same type, rank, and ragged_rank as `input`. |
| 224 | |
| 225 | #### Example: |
| 226 | ```python |
| 227 | >>> rt = tf.ragged.constant([[1, 2], [3]]) |
| 228 | >>> ragged.tile(rt, [3, 2]) |
| 229 | [[1, 2, 1, 2], [3, 3], [1, 2, 1, 2], [3, 3], [1, 2, 1, 2], [3, 3]] |
| 230 | ``` |
| 231 | """ |
| 232 | with ops.name_scope(name, 'RaggedTile', [input, multiples]): |
| 233 | input = ragged_tensor.convert_to_tensor_or_ragged_tensor( |
| 234 | input, name='input') |
| 235 | if not ragged_tensor.is_ragged(input): |
| 236 | return array_ops.tile(input, multiples, name) |
| 237 | multiples = ragged_util.convert_to_int_tensor( |
| 238 | multiples, name='multiples', dtype=input.row_splits.dtype) |
| 239 | multiples.shape.assert_has_rank(1) |
| 240 | |
| 241 | # If the constant value of `multiples` is available, then we can use it |
| 242 | # to skip tiling dimensions where `multiples=1`. |
| 243 | const_multiples = tensor_util.constant_value(multiples) |
| 244 | |
| 245 | return ragged_tensor.RaggedTensor.from_nested_row_splits( |
| 246 | _tile_ragged_values(input, multiples, const_multiples), |
| 247 | _tile_ragged_splits(input, multiples, const_multiples), |
| 248 | validate=False) |
| 249 | |
| 250 | |
| 251 | def _tile_ragged_values(rt_input, multiples, const_multiples=None): |
no test coverage detected