Registered Member
|
Hi,
I'm getting my head around Eigen::Refs and hoped that someone might be able to help me with a small sticking point. I am attempting to call an external library function which writes directly to a preallocated c-array, and pass the contents of my Eigen::Ref to this:
Now, as Eigen::Ref can possibly contain Eigen::Block, the usual approach of calling my_mat.data() is not possible. Is there any other way of getting access to the address of the first element in the block? I'm aware that there is a reason why this is not supported 'out of the box', as clearly the block may have different strides/isn't guaranteed to be contiguous, but would be good to be able to call libraryFunc without making a copy and I know that in my case the data will be contiguous. Thanks for any help you might be able to give to clear up this confusion! |
Moderator
|
You can still use &mat(0,0) but the data(), outerStride() and innerStride() method should be available. If not, then that's a bug we have to fix.
|
Registered Member
|
Aha! That's a very useful trick! Thanks for pointing me in the right direction
|
Registered Member
|
Oh, I just realised that you stated that the data() method should also still be available.
Having just checked, indeed it is! It seems that I had some other issue which was causing my code to fail compilation before. That's very useful to know! And of course, it makes perfect sense that innerStride() and outerStride() can be used to check that I'm accessing the data appropriately as well – I'm understanding things much better now. Thanks again for your help! |
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]