Re: [eigen] How to convert a Matrix into (big) column vector |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 01/22/2012 03:30:25 PM, Christoph Hertzberg wrote:
> On 22.01.2012 12:16, Helmut Jarausch wrote:
> > how can I cheaply convert a Matrix to a big column vector
> containing
> > all the columns of the Matrix stacked one on top of the other
> > (assuming the Matrix is in column order, of course)
>
> Assuming the matrix is in column order and has no strides, you can
> take
> the .data() pointer and generate a Map using it.
>
> MatrixXd mat;
> VectorXd::Map(mat.data(), mat.rows()*mat.cols());
>
> I guess, you can even use an aligned map for that.
> Alternatively, if you just want to access sole elements, you can
> simply
> use mat(i); to access the i^th element (similar as in Matlab).
>
> Actually, instead of the last, I would prefer if there was a method
> .asVector() which generates a Map as above (and automatically decides
> if
> the data is aligned).
> Question would be, if .asVector() can also be implemented for
> Block-types and strided maps somehow.
>
Many thanks!
It was this '.asVector' that I was looking for but couldn't find.
But the ::Map solution suffices for the moment.
Helmut.