Registered Member
|
Here is a simplified version of what im trying to do :
Matrix<double,100000,3> mxA; Block<double,100000,1> * pmxCol1 = NULL; Block<double,100000,1> * pmxCol2 = NULL; Block<double,100000,1> * pmxCol3 = NULL; // Matrix<double,100000,1> * pmxCol1 = NULL; // Matrix<double,100000,1> * pmxCol2 = NULL; // Matrix<double,100000,1> * pmxCol3 = NULL; pmxCol1 = mxr.block<100000,1>(0,0); pmxCol2 = mxr.block<100000,1>(0,1); pmxCol3 = mxr.block<100000,1>(0,2); ... DoSomeLongOperation(pCol1,pCol2,pCol3); ... I can't find a way to have reference (pointer) to a sub block or a sub matrix. My program need to be fast... I dont want to copy the original data. Hopes you get my point. thx |
Registered Member
|
If your matrix has column-major storage (which is the default with Eigen) then doing:
returns a reference to the start of the i-th column, and therefore,
returns a pointer to the start of the i-th column.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
ah, this is only reliable with the devel branch, sorry, as eigen 2.0 may return the coeff by value in which case you'd be taking the address of a temporary.
The more reliable approach with eigen 2.0 is:
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
|
Registered Member
|
ok, then do the 1st approach I said, and, if you use Eigen 2.0, cast the resulting pointer as a non-constant pointer. That will force the compiler to choose the non-constant operator(), or at least in the other case you'll have a compilation error.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
The problem is if i want to do something like a SVD i would have to copy the data back in another Matrix container or use another SVD function
|
Registered Member
|
oh, i'm stupid.
This is what i should have told you to do all along:
however, careful, it doesn't check that the indices are in range.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thx for the support, thats what I though, I'll have to copy the data because I need the matrix container not only the data pointer
|
Registered Member
|
I still don't really understand what you mean, but do you know that thanks to expression templates, block() does not actually return a copy the block, instead it just returns an expression?
so you can do matrix.block(.....) = othermatrix.block(....) and there's no redundant copy here. hope that helps...
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Moderator
|
... and you can also name the reference to use it multiple times, e.g:
Block<MatrixType, Dynamic, 1> col1 = mat.col(1); col1 *= 2; |
Registered Member
|
Just got back from work...
Yeah I thought it would return a copy thx |
Registered Member
|
Is there a way to have 2 seperate Matrix object that have the same buffer adress?
|
Moderator
|
yes, you can use the Map object for that purpose, e.g.:
Map<MatrixType> m1(buffer_address, rows, cols); then you can use m1 like any Eigen matrix object. |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]