In the use-case that I came across, I would start with a Tensor of size (1, 0) and increment the second dimension by one at each step of the algorithm. The first dimension also increase, but it isn’t as periodic. This use-case came up in beam search.
It is not a big deal. I just added a test based on the number of elements, which can
be obtained through numel.