How would one go to implement torch.Tensor.unfold(dim, size, step)
with non-integer step
? k
th slice should start at the index the closest to k * step
:
Here is an example with step = 1.3
x = torch.arange(10)
# tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
x.unfold(0, 2, 1.3)
# tensor([[0, 1], [1, 2], [3, 4], [4, 5], [5, 6], [6, 7], [8, 9]])
# ^ ^
Bonus point if it can be exported with torch.export.onnx
and works just fine with dynamic axes