Registered Member
|
The following code produces
Does this mean the mapped vector/matrix are read-only? And any attempt assigning elements or whole vector/matrix results in new memory allocation? |
Registered Member
|
I just saw in a previous thread that
results in a deep copy. But if I change the type to
to a function taking VectorXf&, unless I change everything to "const". Why is that? |
Moderator
|
if you add a "const" then the compiler automatically convert your Map<VectorXf> into a temporary VectorXf. To write generic functions read this page:
http://eigen.tuxfamily.org/dox/TopicFun ... Types.html |
Registered Member
|
I see. So we need to be prepared for matrix, matrix expression, and possibly resizing matrix expression. I have a couple of more questions:
1. Do this mean any function we write taking matrix need to be templated? Even methods in a class? 2. What about returning a matrix by value? In particle, if I want to write to Map<VectorXd> with an assignment with rhs a function call, how would I go about that? Thanks for a great library and answering my questions. |
Moderator
|
1. if you want it to accept any kind of "matrix" objects then yes.
2. you can return a Matrix and pay for the cost of an extra copy. As an alternative we offer a ReturnByValue mechanism which transform something like: res = foo(...); to: foo_impl(..., res); the function foo will simply return a simple proxy object that encode the actual foo_impl function as well as the default evaluation type in case someone do, e.g.: res = A + foo(...); |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]