Currently when attempting to slice a tensor or Variable object with a step different from 1 I get a Runtime Error:
RuntimeError: Trying to slice with a step of -1, but only a step of 1 is supported
Is support for this opperation coming anytime soon and what is the best way to reverse a tensor along an axis currently? Best I can come up with is doing it via index_select which is clunky and copies the tensor… Doing it via numpy is also not possible as from_numpy() doesn’t seem to work with negative strides.
Support for positive strides is added in this PR. Adding negative strides will need some additional work in our C backends, as they’re not ready for that yet.
I try to do image = image[:, :, ::-1], but it complains that ValueError: slice step has to be greater than 0. I try image = torch.from_numpy(image.numpy()[:, :, ::-1]), it still complains: RuntimeError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.
I’m afraid we still do not.
But if you want a clone of the Tensor, you can use torch.flip(). Note that this will return new memory, but will have the exact same behavior as data[..., ::-1].copy().