Registered Member
|
Hi,
I have an array of doubles, and I want to create a MatrixXd from this. Is there any way of doing this without having to loop over the array and assign each value to the matrix? How does eigen store the matrix internally? A single array of doubles, or a 2d array? |
Registered Member
|
A matrix is stored internally as single array, one column after another (for Column-major)
So you can use col(j) to get read-write access to column j http://eigen.tuxfamily.org/dox-devel/QuickRefPage.html |
Registered Member
|
Ok, that gets me a ColXpr object? Then, that has a public pointer to the underlying array, so I can memcpy onto that?
Can I get a pointer to the very first element of the matrix, for example by doing &mat(0,0) and memcpy the entire array, all columns in one go, onto that? Is there going to be any speed advantage of doing this, or is using a column-major loop to copy the elements one by one from the array via the mat(r,c) operator going to be about the same speed anyway? |
Registered Member
|
have a look at "Mapping external arrays" on http://eigen.tuxfamily.org/dox-devel/QuickRefPage.html
|
Registered Member
|
Super! That was what I was looking for.
Jeigen wrapping overhead for 1000x1000 matrices is now down from 5.4% to 4.1%. https://github.com/hughperkins/jeigen/b ... jeigen.cpp Anything similar for sparse matrices? |
Registered Member
|
For sparse matrices, you have the class MappedSparseMatrix http://eigen.tuxfamily.org/dox-devel/cl ... atrix.html
Note that the Map classes use the same memory as the arrays you supply. So you should not free those arrays before you finish with the Map classes. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]