def test_repeat_tile(self):
initial_shape = (8, 4)
repeats = ((3, 1, 1),
(3, 3, 3),
(1, 2, 1),
(2, 2, 2, 2))
def _generate_noncontiguous_input():
out = np.broadcast_to(np.random.random((1, 4)),
initial_shape)
assert not (out.flags.c_contiguous or out.flags.f_contiguous)
return out
for repeat in repeats:
for tensor in (torch.from_numpy(np.random.random(initial_shape)),
torch.from_numpy(_generate_noncontiguous_input()),):
self.assertEqual(tensor.repeat(*repeat).numpy(),
np.tile(tensor.numpy(), repeat))
评论列表
文章目录