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

operator+ : compilation error

Tags: None
(comma "," separated)
rtrepos
Registered Member
Posts
11
Karma
0

operator+ : compilation error

Thu Dec 03, 2009 11:48 am
Hello,
I have a compilation error concerning the operator+.
It seems that this operator for scalars is defined but it does not compile.
I use the eigen library distributed on ubuntu.


Code: Select all
VectorXd x(21);
x <<  -2.0, -1.7, -1.4, -1.1, -0.8 ,-0.5, -0.2 , 0.1 , 0.4 , 0.7 , 1.0 , 1.3 , 1.6 , 1.9 , 2.2, 2.5 , 2.8 , 3.1  ,3.4,  3.7 , 4.0;

VectorXd xx = x+10;


the compile error message :

/home/rtrepos/usr/src/vle_dev/eigen_utils/src/test_eigen_utils.cpp: In function ‘int main(int, const char**)’:
/home/rtrepos/usr/src/vle_dev/eigen_utils/src/test_eigen_utils.cpp:300: error: no match for ‘operator+’ in ‘x + 10’

Best regards.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: operator+ : compilation error

Thu Dec 03, 2009 11:54 am
have a look at the tutorial:
http://eigen.tuxfamily.org/dox/Tutorial ... cOperators

the correct syntax for this operation is:

xx = x .cwise()+ 10;

here you have to add the .cwise() prefix to make it clear you don't want to add 10 to all coefficients in contrast to:

x + 10 I

where I is the identity matrix.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: operator+ : compilation error

Thu Dec 03, 2009 11:55 am
You can't add a number to a vector like that. If you want to add that number to all coeffs of the vector, do:
Code: Select all
v.cwise() + 10.0

Note that "cwise()" is just a "prefix" for the operator+. That's why you write it only on the left hand side, and the result of the operator+ is again just a vector expression.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
rtrepos
Registered Member
Posts
11
Karma
0

Re: operator+ : compilation error

Thu Dec 03, 2009 12:18 pm
Sorry, actually I saw it on the tutorial but I forgot it.
Thank you, I'll take more time before posting now..


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]