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

ternary operator fails with matrix reverse()

Tags: None
(comma "," separated)
guochow
Registered Member
Posts
1
Karma
0
Hillo there,
Just a simple example:
Code: Select all
Vector3f test0;
test0 << 1.f, 2.f, 3.f;
Vector3f test = ((1 < 0) ? (test0.reverse()) : test0);

test turns out to be (3.f, 2.f, 1.f) always.
I am using VS2013 update4 with Eigen 3.2.5. Can someone shed some light?
Thanks. xD
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Expressions templates are incompatible with the ternary operator. The problem is that the type of the ELSE expression must be the same as the type of the THEN expression. Since THEN is a Reverse<Vector3f>, the ELSE expression test0 is converted to a Reverse<Vector3f>, and therefore you're screwed ;) A workaround in this very particular case would be to call test0.reverse().eval(), but the safest and fastest is really to avoid this ternary operator with Eigen's expressions and use a if/else construct.
xding
Registered Member
Posts
3
Karma
0
How about type convension ?
Code: Select all
Vector3f test = 1 < 0 ? static_cast<Vector3f>(test0.reverse()) : test0;
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Nope, better use the respective ctor:

Vector3f test = 1 < 0 ? Vector3f(test0.reverse()) : test0;


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]