Broadcasts a potentially ragged tensor to a ragged shape. Tiles `rt_input` as necessary to match the given shape. Behavior is undefined if `rt_input` is not broadcast-compatible with `shape`. Args: rt_input: The potentially ragged tensor to broadcast. shape: A `RaggedTensorDynamicSh
(rt_input, shape, broadcast_inner_dimensions=True)
| 474 | |
| 475 | |
| 476 | def broadcast_to(rt_input, shape, broadcast_inner_dimensions=True): |
| 477 | """Broadcasts a potentially ragged tensor to a ragged shape. |
| 478 | |
| 479 | Tiles `rt_input` as necessary to match the given shape. |
| 480 | |
| 481 | Behavior is undefined if `rt_input` is not broadcast-compatible with `shape`. |
| 482 | |
| 483 | Args: |
| 484 | rt_input: The potentially ragged tensor to broadcast. |
| 485 | shape: A `RaggedTensorDynamicShape` |
| 486 | broadcast_inner_dimensions: If false, then inner dimensions will not be |
| 487 | tiled. |
| 488 | |
| 489 | Returns: |
| 490 | A potentially ragged tensor whose values are taken from |
| 491 | `rt_input`, and whose shape matches `shape`. |
| 492 | """ |
| 493 | if not isinstance(shape, RaggedTensorDynamicShape): |
| 494 | raise TypeError('shape must be a RaggedTensorDynamicShape') |
| 495 | rt_input = ragged_tensor.convert_to_tensor_or_ragged_tensor(rt_input) |
| 496 | |
| 497 | # Broadcasting to a uniform shape. |
| 498 | if shape.num_partitioned_dimensions == 0: |
| 499 | return _broadcast_to_uniform_shape(rt_input, shape, |
| 500 | broadcast_inner_dimensions) |
| 501 | else: |
| 502 | return _broadcast_to_ragged_shape(rt_input, shape, |
| 503 | broadcast_inner_dimensions) |
| 504 | |
| 505 | |
| 506 | def _broadcast_to_uniform_shape(rt_input, shape, broadcast_inner_dimensions): |
no test coverage detected