When I want to grow a possibly multi-dimensional tensor along one dimension this can be elegantly achieved with the repeat_interleave
function, e.g.
torch::Tensor x = torch::ones({2,3});
x.repeat_interleave(3,0);
Is there an equivalent for the regular repeat
function? So far, I always need to specify both dimensions explicitly, e.g.
x.repeat({3,1})
which is impractical when writing generic functions that should work for tensors with arbitrary dimensionality. What I do right now is this
switch (x.sizes().size()) {
case 1:
return x.repeat({3});
case 2:
return x.repeat({3,1});
case 3:
return x.repeat({3,1,1});
...
}
but that is of course not truly generic.