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

[SOLVED] Question on CwiseBinaryOp

Tags: None
(comma "," separated)
Seb
Registered Member
Posts
99
Karma
0

[SOLVED] Question on CwiseBinaryOp

Thu Apr 23, 2009 9:58 am
Hi

I am struggling with using cwise operations. I want to create a matrix from another one by applying an elementwise

matrixA = matrixB < scalarC;

MatrixXd B;
double c;
MatrixXd A = B.cwise() < c;
results in a compilation error YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY

I have seen in the API-doc of cwise that the operator is defined. To my understanding it is specialized for evaluating purposes. Does anyone know the missing hint in transforming the resulting CwiseBinaryOp object to a matrix?
User avatar
bjacob
Registered Member
Posts
658
Karma
3

[SOLVED] Question on CwiseBinaryOp

Thu Apr 23, 2009 10:46 am
the result is a matrix of bools, so it complains about different scalar types. you can cast() or select().

PS. strange, this operator isn't mentioned in the online docs, only the one taking a second xpr is mentioned here.
http://eigen.tuxfamily.org/dox/classEigen_1_1Cwise.html
Could that be your problem?

Last edited by bjacob on Thu Apr 23, 2009 10:50 am, edited 1 time in total.


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

[SOLVED] Question on CwiseBinaryOp

Thu Apr 23, 2009 3:50 pm
Thanks! The cast works fine. It seems I did not understand the identity of CwiseBinaryOp

bjacob wrote:PS. strange, this operator isn't mentioned in the online docs, only the one taking a second xpr is mentioned here.
http://eigen.tuxfamily.org/dox/classEigen_1_1Cwise.html
Could that be your problem?


It is there:

http://eigen.tuxfamily.org/dox/classEig ... b69fe2e55a
User avatar
bjacob
Registered Member
Posts
658
Karma
3


This one takes a matrix as second argument. Your notation seemed to imply you were passing a scalar (scalarC). Anyway, good if it's now working for you.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
Seb
Registered Member
Posts
99
Karma
0
I hope you can help me once more.

I am looking for an operation that gives me a rowwise sum, eg.

MatrixXd A(4,3);
MatrixXd b(4,1);

MatrixXd C = A+b.col(0);

Then C should contain C(i,k) = A(i,k)+b(i)

Is that somehow possible?
User avatar
bjacob
Registered Member
Posts
658
Karma
3
At the moment, we don't seem to have anything for that. You can always do

Code: Select all
C = A + (b*RowVectorXd::Ones(3)).lazy();


but this is quite inelegant.

What we need is to have "stacking" expressions and I remember that this has already been asked for. I'll have a look at it, when I can.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
Seb
Registered Member
Posts
99
Karma
0
bjacob wrote:What we need is to have "stacking" expressions and I remember that this has already been asked for. I'll have a look at it, when I can.


Thanks for answering. I can help myself with dirty hacks until this feature arrives. Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
it is already there ! it is called replicate. I think you can do something like:

c = a + b.replicate(1,a.cols());

or

c = a + b.rowwise().replicate(a.cols());

for more details have a look at the doc.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
oh, i'm so out of date :-S


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

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