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

  1. It turns out the test for .reverse() was missing from test/CMakeLists.txt. I added it.
  2. I have disabled block access for .roll() as I could not immediately see how to make that work.
  3. I have not tried to do any optimizations such as detecting and ignoring identity rolls.
  4. 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).
  5. 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

Merge request reports

Loading