For Eigen 3.2.1 using p.abs(); just as you would use p.normalize , there is a compiler error in the lines
error: no member named 'abs' in 'Eigen :: Matrix' p.abs (); ~ ^
therefore, a vector in Eigen is nothing more than a matrix type. To calculate the absolute values โโof the matrix in Eigen, you can use the p.cwiseAbs() or p.array().abs(); array p.array().abs(); . Both of these absolute functions return a value, not the variable itself.
So the right way to do this is to do
p = p.cwiseAbs();
or
p = p.array().abs();
source share