Reply to topic

pointer to Nth Row needed

xaffeine
Registered Member
Posts
24
Karma
0

pointer to Nth Row needed

Tue May 06, 2014 7:58 pm
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() );
}
User avatar ggael
Moderator
Posts
2696
Karma
17
OS

Re: pointer to Nth Row needed

Tue May 06, 2014 8:38 pm
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.
xaffeine
Registered Member
Posts
24
Karma
0

Re: pointer to Nth Row needed

Tue May 06, 2014 10:54 pm
ggael wrote: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.


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() );
}
User avatar ggael
Moderator
Posts
2696
Karma
17
OS

Re: pointer to Nth Row needed  Topic is solved

Wed May 07, 2014 6:50 am
Do not use a reference:

RowMajorComplexMat::ConstRowXpr thisRow = bigMat.row(band);
xaffeine
Registered Member
Posts
24
Karma
0

Re: pointer to Nth Row needed

Wed May 07, 2014 6:15 pm
Do you ever feel like someone should write a book about Eigen?

 
Reply to topic

Bookmarks



Who is online

Registered users: andreas_k, Baidu [Spider], Bing [Bot], bobthebuilder, davidemme, Exabot [Bot], frasty, Google [Bot], google01103, gregormi, ivan, jstaniek, jzarecta, koriun, MSNbot Media, nbelavic, neferkamichael, pedrorodriguez, Steve Guilford, vpinon, Yahoo [Bot]