MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _tile_one_dim

Function _tile_one_dim

imperative/python/megengine/functional/tensor.py:1140–1161  ·  view source on GitHub ↗
(inp, rep, axis)

Source from the content-addressed store, hash-verified

1138
1139
1140def _tile_one_dim(inp, rep, axis):
1141 shape = astensor1d(inp.shape, inp, dtype="int32", device=inp.device)
1142 # assume inp.ndim is not changed during trace
1143 max_axis = len(shape) - 1
1144
1145 base_shape, bcast_shape, target_shape = [], [], []
1146
1147 if axis != 0:
1148 base_shape.append(shape[:axis])
1149 bcast_shape.append(shape[:axis])
1150 target_shape.append(shape[:axis])
1151 base_shape.extend([[1,], shape[axis:]])
1152 bcast_shape.extend([rep, shape[axis:]])
1153 target_shape.append(shape[axis] * rep)
1154 if axis + 1 <= max_axis:
1155 target_shape.append(shape[axis + 1 :])
1156
1157 base_shape = astensor1d(base_shape)
1158 bcast_shape = astensor1d(bcast_shape)
1159 target_shape = astensor1d(target_shape)
1160 out = broadcast_to(inp.reshape(base_shape), bcast_shape).reshape(target_shape)
1161 return out
1162
1163
1164def tile(inp: Tensor, reps: Iterable[int]):

Callers 1

tileFunction · 0.85

Calls 4

astensor1dFunction · 0.85
broadcast_toFunction · 0.70
appendMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected