Skip to content
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

Implement the MatrixView class #734

Merged
merged 17 commits into from
Sep 10, 2020

Conversation

GiulioRomualdi
Copy link
Member

@GiulioRomualdi GiulioRomualdi commented Sep 9, 2020

This PR has to be the updated version of #730. Differently from #730 the storage ordering is now a regular attribute of the class, rather than a template parameter. The class now behaves like an std::span, i.e. when the copy assignment operator is called the pointer, and not what it's contained, is copied.

I've also implemented make_matrix_view to simplify the creation of a MatrixView. The usual toEigen() functions have been implemented to convert the MatrixView<> to an EigenMap, in this case, the StorageOrder is handled using the Eigen::Stride (thanks @S-Dafarra for suggesting this).

The PR is correlated to UnitTests.

This is the first step to achieve #716

@traversaro @prashanthr05 @S-Dafarra

This is a preliminary working implementation of kindyn with MatrixView.

src/core/include/iDynTree/Core/EigenHelpers.h Outdated Show resolved Hide resolved
src/core/include/iDynTree/Core/MatrixView.h Outdated Show resolved Hide resolved
src/core/include/iDynTree/Core/MatrixView.h Outdated Show resolved Hide resolved
src/core/tests/MatrixViewUnitTest.cpp Show resolved Hide resolved
Copy link
Member

@traversaro traversaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor comment, other then that it is great. The stride trick is far from being intuitive, so if you have some link to explain it would be great to add it in a comment in the code, thanks!
Other then that, can you update the CHANGELOG?

src/core/include/iDynTree/Core/EigenHelpers.h Outdated Show resolved Hide resolved
@S-Dafarra
Copy link
Contributor

Let me drop here an idea. It would be nice to add (not necessarily in this PR) a block call. I think that this would be possible by playing with the stride (which should become a class parameter as well). We can discuss this F2F, or I can also try to implement it if you want.

@GiulioRomualdi
Copy link
Member Author

Let me drop here an idea. It would be nice to add (not necessarily in this PR) a block call. I think that this would be possible by playing with the stride (which should become a class parameter as well). We can discuss this F2F, or I can also try to implement it if you want.

For the time being we can use toEigen().block(), but yes we can discuss 😄

Co-authored-by: Silvio Traversaro <pegua1@gmail.com>
@S-Dafarra
Copy link
Contributor

For the time being we can use toEigen().block(), but yes we can discuss

Yes, but that is not returning a MatrixView. Also, notice that the pointer returned by data() of block is const.


// This is a trick required to see a ColMajor matrix as a RowMajor matrix.
const int innerStride = (mat.storageOrder() == StorageOrder::ColMajor) ? mat.rows() : 1;
const int outerStride = (mat.storageOrder() == StorageOrder::ColMajor) ? 1 : mat.cols();
Copy link
Contributor

@prashanthr05 prashanthr05 Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read here that it is not always safe to use ternary operators with Eigen expressions.

Copy link
Contributor

@prashanthr05 prashanthr05 Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad, here mat is a MatrixView type!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it is not safe when an Eigen type is on the left side. In this case should be fine as only int are involved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, understood.

Copy link
Member Author

@GiulioRomualdi GiulioRomualdi Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the operator is called on int so it shouldn't be a problem, please correct me if I'm mistaken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it is not safe when an Eigen type is on the left side. In this case should be fine as only int are involved.

Ops I missed the message

@GiulioRomualdi
Copy link
Member Author

GiulioRomualdi commented Sep 10, 2020

@traversaro

Super minor comment, other then that it is great. The stride trick is far from being intuitive, so if you have some link to explain it would be great to add it in a comment in the code, thanks!

Done here: 7bcf16f

Other then that, can you update the CHANGELOG?

Here: f07abf2

@traversaro
Copy link
Member

Thanks! Can I merge with squash?

@GiulioRomualdi
Copy link
Member Author

Thanks! Can I merge with squash?

Yes sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants