This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Eigen2 cwise() to Eigen3 array() and VectorXx

Tags: None
(comma "," separated)
jofellowson
Registered Member
Posts
2
Karma
0
Hi,
I'm migrating Eigen2 code to Eigen3. I have an eigen2 based code as this:

Matrix4d coeff;
Vector4d extents = coeff.cwise().abs() * Vector4d(0.0, 1.0, 1.0, 1.0);


I want to translate the above code to Eigen3:

Matrix4d coeff;
Vector4d extents = ((coeff.array().abs()).matrix()) * (Vector4d(0.0, 1.0, 1.0, 1.0).array().matrix());


Am I did correctly?

Jo
jitseniesen
Registered Member
Posts
204
Karma
2
This should give the correct result, but it is more complicated than necessary. For the first factor, you can use the .cwiseAbs() function, which also works for matrices. For the second factor, you take a Vector4d, turn it into an array and then back into a matrix; this just give you the matrix you started with. So instead you can write (not tested):
Code: Select all
Vector4d extents = coeff.cwiseAbs() * Vector4d(0.0, 1.0, 1.0, 1.0);
jofellowson
Registered Member
Posts
2
Karma
0
Thanks, jitseniesen. The removal of cwise() in Eigen3 from Eigen2 has been tricky for non-mathematical programming analysits (like me). If the Eigen2-based code
Code: Select all
Vector4d extents = coeff.cwise().abs() * Vector4d(0.0, 1.0, 1.0, 1.0);

can be upgraded to Eigen3 code:
Code: Select all
Vector4d extents = coeff.cwiseAbs() * Vector4d(0.0, 1.0, 1.0, 1.0);


I would assume that Eigen2's code like:
Code: Select all
Vector4d extents = coeff.cwise().inverse()

can be upgraded to Eigen3's code
Code: Select all
Vector4d extents = coeff.cwiseInverse()
or
Code: Select all
Vector4d extents = coeff.array().inverse()

jo


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]