Registered Member
|
I very frequently need to get a pointer to a specific row of a matrix, to pass to a low-level function. For speed reasons, I do not want to copy the row data. I have defined my matrices to be row-major so that copying should not be necessary. I expected to be able to call .row().data() without incurring any copying, but I can see from profiling that indeed a copy is made. Do I need to do my own pointer/size arithmetic? Of not, what is the nice way to do it?
Here are the relevant code fragments. typedef Matrix< complex<float>, Dynamic, Dynamic, RowMajor > RowMajorComplexMat; RowMajorComplexMat bigMat; for( int band =0; band < mnBands; ++ band ) { const RowMajorComplexMat & thisRow = bigMat.row(band); // takes time, but shouldn't doSomethingWith( thisRow.data() ); } |
Moderator
|
bigMat.row(band).data() does not perform any copy. However, the returned type of .row(.) is not a Matrix<> object. It is a Block<....> expression whose precise type is given by RowMajorComplexMat::RowXpr.
|
Registered Member
|
Thank you, that is interesting to learn. So, if I write the following, should the problem go away? for( int band =0; band < nBands; ++ band ) { const RowMajorComplexMat::RowXpr & thisRow = bigMat.row(band); doSomethingWith( thisRow.data() ); } |
Moderator
|
Do not use a reference:
RowMajorComplexMat::ConstRowXpr thisRow = bigMat.row(band); |
Registered Member
|
Do you ever feel like someone should write a book about Eigen?
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell