Seb
Registered Member

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 APIdoc 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? 
bjacob
Moderator

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

Thanks! The cast works fine. It seems I did not understand the identity of CwiseBinaryOp
It is there: http://eigen.tuxfamily.org/dox/classEig ... b69fe2e55a 
bjacob
Moderator

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

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? 
bjacob
Moderator

At the moment, we don't seem to have anything for that. You can always do
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

Thanks for answering. I can help myself with dirty hacks until this feature arrives. Thanks! 
ggael
Moderator

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. 
bjacob
Moderator

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! 
Registered users: Amadiro, andreas_k, Baidu [Spider], Bing [Bot], davidemme, einar, Exabot [Bot], Google [Bot], google01103, Horus, jmf, joaob, Mamarok, Przemas, ScionicSpectre, Silvio Grosso, simonv, slangkamp, stefanu, StuieT, tavet, TheraHedwig, tienhung, tosky, veqz, Yahoo [Bot]