Registered Member
|
Dear All,
I'm new to eigen, and I'm completely amazed by its performance and design. However I'm stuck with few things. 1) I can't figure out how to perform an element-wise division. vec.cwise()/scalar does not work and I have to write a loop for this. Is there any technical reason why "/" operator does not work with cwise()? If not, then this would be a good idea to include it in the next version. 2) I have a function which takes a vector like this: void some_func(VectorXd& vec); and I want to pass a column of the matrix to it, but some_func(matr.col(i)) does not work because of type mismatch. Is there any intelligent way of doing this, or I have to make a copy of the column in vector object first? Many thanks in advance for the answers!
Last edited by yesint on Wed Apr 15, 2009 6:40 pm, edited 1 time in total.
|
Registered Member
|
You want to divide all coeffs of a vector by the same scalar? Then that's a plain division, no need for cwise, do: vec / scalar; Otherwise, to perform a cwise quotient by another vector, you would do vec.cwise()/othervector, and that would require you to #include.
The reason why it works but doesn't want you to write "cwise()" is that it is a basic linear-algebraic operation. Cwise is for operations that don't make much sense from the point of view of linear algebra but are useful for dealing with arrays.
Yes,
Notice I made the reference constant because C++ doesn't want non-constant references to temporaries. You can always const-cast if you must. Or if you don't want to make your function templated, you can always keep your old function and call it like this:
However this kills the possibility of lazy evaluation and doesn't give write access.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thank you very much for reply! Now it's clear. |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell