3

What is the best (by which I mean the fastest and/or most efficient) way to perform a circular shift on a 2D Eigen array?

For example, I would like to circularly shift a ArrayXXd to the right. I think I can do something like the following:

circShiftRight (ArrayXXd &arraytoshift)
{
    Matrix<double, Dynamic, 1> tmp;

    tmp = arraytoshift.col (arraytoshift.cols ()-1);

    arraytoshift.rightCols(_radForceVelocity.cols()-1) = arraytoshift.leftCols(_radForceVelocity.cols()-1).eval ();

    arraytoshift.col(0) = tmp;
}

but will this work and is there a better way? I assume the .eval() is necessary to avoid Aliasing. I'm new to using the Eigen Library.

crobar
  • 2,810
  • 4
  • 28
  • 46
  • 1
    Better is just to index into the array with an offset and not move anything. – stark Sep 11 '18 at 15:16
  • @stark what I'm really doing is circular shift then replacing the first column with new values to implement a rolling history of data. – crobar Sep 11 '18 at 15:19
  • Comment still applies. Insert you new data at the offset, then increment the offset. Why move data unless you have to? – stark Sep 11 '18 at 15:20
  • @stark, I could maybe do this, can you post an answer with a basic example? – crobar Sep 11 '18 at 15:25

0 Answers0