Tile the batch dimension of a (possibly nested structure of) tensor(s) t. Args: t: Tensor shaped [batch_size, ...] multiplier: Returns: A possibly nested structure of Tensor shaped [batch_size * multipler, ...]
(t, multiplier)
| 100 | |
| 101 | |
| 102 | def tile_batch(t, multiplier): |
| 103 | """Tile the batch dimension of a (possibly nested structure of) tensor(s) t. |
| 104 | |
| 105 | Args: |
| 106 | t: Tensor shaped [batch_size, ...] |
| 107 | multiplier: <int32> |
| 108 | |
| 109 | Returns: |
| 110 | A possibly nested structure of Tensor shaped [batch_size * multipler, ...] |
| 111 | """ |
| 112 | |
| 113 | def _tile_batch(t, multiplier): |
| 114 | """Core single-tensor implementation of tile_batch.""" |
| 115 | tensor = tf.convert_to_tensor(t) |
| 116 | tensor = tf.expand_dims(tensor, axis=1) |
| 117 | tile_dims = [1] * tensor.shape.ndims |
| 118 | tile_dims[1] = multiplier |
| 119 | tiled = tf.tile(tensor, tile_dims) |
| 120 | return tf.reshape(tiled, [-1] + shape(tensor)[2:]) |
| 121 | |
| 122 | return tf.nest.map_structure(lambda t_: _tile_batch(t_, multiplier), t) |
| 123 | |
| 124 | |
| 125 | def gather(src, indices): |
nothing calls this directly
no test coverage detected
searching dependent graphs…