Eigen gotcha, aliasing using `rowwise` and `colwise`

Alec Jacobson

December 02, 2013

weblog/

I tried to shift a set of positions stored in a #V by 3 matrix V by subtracting the column minimum element from each column using:

V.rowwise() -= V.colwise().minCoeff();

Unfortunately this expression is aliased and doesn't execute correctly. I guess the right way---typical with Eigen---is to stick an eval() in there:

V.rowwise() -= V.colwise().minCoeff().eval();