Registered Member
|
Hi
I'm writing some software that uses MatrixX3d and RowVector3d to represent Nx3 data where sometimes I want to constraint the data to only be 1xN. My problem is that functions like this:
allow the first argument to be either a RowVector3d or a MatrixX3d, but the second argument won't compile with a RowVector3d argument passed in. I'm doing a lot of this:
which is really annoying. My functions always just perform per row operations or Nx3 \times 3xM matrices so will all work in the case of N==1 What's the easiest way to allow my function to compile with both types without copying. I've started templating the code. but i have to put a whole load of includes in my headers because the whole implementation has to be avaliable and I don't wnat to do that. I could use MatrixX3d as my only type, but sometimes the data really has to be just one row and Id like that enforced at compile time. Can I cast my rowvectors to Matrices of size 1,3 without triggering a copy? Ideas are welcome. |
Moderator
|
To get high performance in the single-row case you could have to overload that would call a generic templated version (only needed in the cpp file). Or, if you can lost some performance you should be able to use a Ref<MatrixX3d> for the RBG parameter.
|
Registered Member
|
Oh yeah, templated functions in the cpp - I didn't think of that.
|
Registered Member
|
The Ref<MatrixX3d> method deosn't work BTW - thats one I tried already. It won't compile when you pass RowVector3d into the functions.
|
Moderator
|
oh, I see. When storage does not match, Ref<> cannot work without any copy. However, you are in a degenerate case that could work. We'll fix it.
|
Moderator
|
Fixed:
https://bitbucket.org/eigen/eigen/commits/81b83819b1b8/ Changeset: 81b83819b1b8 User: ggael Date: 2014-03-13 18:04:19 Summary: Relax Ref such that Ref<MatrixXf> accepts a RowVectorXf which can be seen as a degenerate MatrixXf(1,N) https://bitbucket.org/eigen/eigen/commits/1f063cc98b8c/ Changeset: 1f063cc98b8c Branch: 3.2 User: ggael Date: 2014-03-13 18:04:19 Summary: Relax Ref such that Ref<MatrixXf> accepts a RowVectorXf which can be seen as a degenerate MatrixXf(1,N) (grafted from 81b83819b1b8c4a92d52115d9f22bbb76c34e4a3) |
Registered Member
|
Fantastic - Thanks.
One last question - I'm using your suggestion of templated functions in the cpp file like this:
But this doesn't compile due to the Eigen::MatrixBase<X3Type> temporary. I'm not sure how to declare a variable with the same type as the templated MatrixBase. Can you help me with the syntax? THe only docs I can find are here, but I can't work out the exact syntax i need. http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html
|
Moderator
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]