Tensor Roll / Circular Shift / Rotate
What does this implement/fix?
I couldn't see a roll/circular shift/rotate function for Tensors, so I tried to implement one.
I did this by taking a copy of TensorReverse.h and the relevant test, then editing them. I am sure there is vast room for improvement, but I wanted to get the MR up before I go to far, mostly in case it turns out there is a way to do this already.
Additional information
- It turns out the test for
.reverse()was missing from test/CMakeLists.txt. I added it. - I have disabled block access for
.roll()as I could not immediately see how to make that work. - I have not tried to do any optimizations such as detecting and ignoring identity rolls.
- I think I have the correct logic for calculating the wraps including negative rolls. But I would be very glad of someone checking that (line 142 in TensorRoll.h).
- I used the name
.roll()to match NumPy and Tensorflow..rotate()would be more common for C++, Matlab uses.circshift(). I vote for.roll()but am not strongly attached to it if others vote for something different.
Edited by Tobias Wood