![]() Registered Member ![]()
|
I need to access the array that contains the data of a MatrixBase Eigen matrix without making a deep copy. Cross post from StackOverflow.
The Eigen library has the data() method which returns a pointer to an array, however it is only accessible from a Matrix type. The MatrixBase doesn't have a similar method, even though the MatrixBase class is supposed to act as a template and the actual type should be just a Matrix. If I try to access MatrixBase.data() I get a compile time error:
Error:
The underlying matrices that are of type Eigen:MatrixBase are always Eigen::Matrix<float, Dynamic, Dynamic>, so all of the objects whose data() I am trying to access definitely have it as a method. I am currently solving my problem using this method:
However this adds an additional copy, which is the single slowest point in my code. A solution using Ref<> was proposed, but I think this also adds an additional copy, even though the types should be matching. I can't use Eigen Magma for this situation and also I'd rather not change the types of the function, as it would require changing A LOT of code. Any ideas? EDIT: Thanks for the explanation. It doesn't solve my problem, but it explains why I can't get a pointer to a data array (and that such array doesn't exist, so I have to look for a different solution).
Last edited by XapaJIaMnu on Tue Aug 05, 2014 11:13 am, edited 1 time in total.
|
![]() Registered Member ![]()
|
The error suggests that you when you call uscgemv, the argument b is not a Matrix but an expression of the form scalar * Matrix. Such an expression does not have a .data() member because the scalar product is not yet evaluated.
|
![]() Registered Member ![]()
|
Does this mean that the expression is evaluated the first time you access it? Because I can do b(0,0) and get the result inside? |
![]() Registered Member ![]()
|
Correct. If you do b(0,0) then that entry of the matrix is computed (lazy evaluation). |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]