-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use matrix view with Eigen::Ref and Eigen::Map #797
Comments
In order to replicate the error, try to instantiate a iDynTree::MatrixView a(eigenRef);
|
Note that
However, for Ref that are continuous in memory, indeed this should be possible. Have you tried to define explicitly the MatrixView constructor that uses Eigen::Ref, just to try?
What would be the return value of |
What do you think about handling inner/outer strides into MatrixView? |
To me (given that I never worked extensively with strides) seems to be a bit complex w.r.t. to the advantages that it provides, but if someone wants to work on it I would be happy to have it in iDynTree. |
Sorry to jump in just now. Back in time, I thought a little bit about it and I think it may be possible to get a submatrix from a MatrixView, but as you said it is possible only if you can specify the inner and outer stride too. Assuming that we are not mixing RowMajor and ColMajor, you can get a sub-block of the matrix by simply offsetting the raw pointer to the position of the top left element of the block, change the row and cols to the dimension of the block and keep the same inner and outer stride. In fact, the distance in memory between rows and columns does not change, you are only changing the boundaries. |
Hi @S-Dafarra the main limitation of what we implemented is that this kind of code cannot compile void foo(Eigen::Ref<Eigen::MatrixXd> m)
{
kinDyn.getFreeFloatingMassMatrix(m);
return;
} while the following works void foo(Eigen::MatrixXd& m)
{
kinDyn.getFreeFloatingMassMatrix(m);
return;
} |
I understand. Does |
Today I had the opportunity to understand deeper the problem. First of all the problem that I underlined in #797 (comment) iDynTree::MatrixView a(eigenRef); it is simply a template deduction problem (as @S-Dafarra suggested in #797 (comment)). indeed For instance this snippet #include <iostream>
#include <Eigen/Dense>
#include <iDynTree/Core/MatrixView.h>
void foo(iDynTree::MatrixView<double> view) {
std::cout << "Size: " << view.rows() << " x " << view.cols() << std::endl;
std::cout << "view(0,0): " << view(0, 0) << std::endl;
view(0, 0) = 2;
std::cout << "view(0,0): " << view(0, 0) << std::endl;
}
int main() {
Eigen::MatrixXd m(10, 10);
Eigen::MatrixXd n(10, 10);
m.setZero();
n.setIdentity();
Eigen::Ref<Eigen::MatrixXd> ref(m);
std::cout << "Eigen::Ref" << std::endl;
foo(ref);
std::cout << std::endl;
std::cout << "Eigen::MatrixXd" << std::endl;
foo(n);
return 0;
} gives
On the other hand as @traversaro and @S-Dafarra explained the
This problem does not subsist if |
This was partically fixed by #800, right @GiulioRomualdi ? Could you specify what is missing to close the issue, or eventually open an issue just for that? |
Hi @traversaro, #800 implements the possibility to retrieve a sub-block of a matrix view. The nice thing is that we can use For instance, this now works without problems: void foo(Eigen::Ref<double> m)
{
m.setIdentity();
}
Eigen::MatixXd m(20,30);
iDynTree::MatrixView view(m);
foo(iDynTree::toEigen(view.block(0,0,10,10))); |
In my opinion, we can close the issue |
If I try to compile the these lines
the following error is thrown by the compiler
Something similar happens if I do
where the function
subA
isThis is the error
Actually supporting the eigen::map is not really important since matrixview can be seen as a map, so we can wrap directly a non-idyntree object using the matrixview. On the other hand, adding the support to
eigen::ref
it would be really nice since it may happen that the input of a function is anEigen::Ref
object.I think that the problem can be split into these subtasks:
SubMatrixView
. This can be used to extract a block from aMatrixView
(this is actually what I need)cc @traversaro and @S-Dafarra
The text was updated successfully, but these errors were encountered: