-
Notifications
You must be signed in to change notification settings - Fork 71
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 externally owned vector and matrices #430
Comments
Related discussions:
|
Related discussion at C++ standard committee :
|
Regarding the vector, it seems to me that In this case
would still be an open issue. A possibility could be to use a private flag to discern whether the vector can be resized or not (using asserts similarly to what Eigen does for the maps). On the other hand, we would not need to change any interface. |
VectorDynSize supports the
I check the proposal, and the On the other hand, |
Regarding |
The abseil one is Apache 2-licensed, so it is not directly incorporable in the iDynTree codebase (see https://www.dwheeler.com/essays/floss-license-slide.html). Furthermore, I have the impression that extracting the span implementation from the complete class would be quite complicated. The gsl-lite one is MIT-licensed, so we can incorporate it directly in the iDynTree. I think we can make iDynTree C++14 only at this point (we discussed about this at a YARP level, so it should not be a problem). The |
👍
Were you thinking about a rough copy/paste or wrapping it as |
Copy/paste from gsl + cleanup of gsl stuff + renaming as |
Microsoft's GSL also has a MIT-license implementation of span : https://github.com/Microsoft/GSL/blob/master/include/gsl/span . |
cc @diegoferigo I suspect this could be useful for wb-toolbox . |
I was looking at this table and I did not realize what M stood for 😅 It seems to be much simpler! |
Yes, because it is already C++14. I think we can drop the methods returning using the |
Regarding |
I think we can also drop a few |
|
I think we can just switch to |
But the actual |
Considering that in iDynTree we have only vector and matrices as containers, I wonder whether it is better to avoid considering a generic |
I totally agree, especially because the ndspan proposal seems to be quite complicated and its inclusion in the standard is uncertain. |
I would call this new class something like |
I don't know, I don't think we can get too wrong passing a pointer and two integers around. : ) |
|
I was referring to all the machinery that makes Regarding the name I like the suffix |
👍 |
👍
Sincerely I prefer the compile-time option, also because I don't know if it makes sense for this information to change at run-time. Looking at the Maybe we can add for our current definition of MatrixStorageOrdering a similar implementation of std::is_same in order to check which ordering is actually used, maybe using something like: constexpr bool isRowMajor() const noexcept { return iDynTree::is_same<iDynTree::RowMajor, order_type>::value; } where |
An example for iDynTree::Span in action for the use-case of getting and setting states, bool getState(iDynTree::Span<double>& x) const
{
x(0) = 0.0;
return true;
}
bool setState(iDynTree::Span<double>& x)
{
// ... check if x and internal state have same size, else throw error
// avoiding all that here
double state = x(0);
return true;
} can be called using, iDynTree::VectorDynSize state;
state.resize(1);
state(0) = 10.0;
std::cout << state.toString() << std::endl; // prints 10.0
iDynTree::Span<double> buf(state.data(), state.size());
getState(buf);
std::cout << state.toString() << std::endl; // prints 0.0
state(0) = 10.0;
iDynTree::Span<double> setBuf(state.data(), state.size());
setState(setBuf); |
Exactly! I would however add setState(state.asSpan()) |
Actually the setState(iDynTree::make_span(state)) |
You are right, I totally forgot about it! |
A self-declared "production-ready" implementation of mdspan is available at https://github.com/kokkos/mdspan . |
I think we can close this issue right? |
Fixed by: Thanks @S-Dafarra @GiulioRomualdi ! |
To support reading and writing from and to Vector and Matrices already allocated in a form different from
iDynTree::VectorDynSize
,iDynTree::MatrixDynSize
,iDynTree::VectorFixSize
,iDynTree::MatrixFixSize
(such asEigen::MatrixXd
,std::vector<double>
,std::array<double>
, raw c-buffers, numpy matrices, etc etc, it may be useful to define classes to represent Vector and Matrices externally owned.While the matrix implementation is probably more complicated, the Vector implementation could be probably as simple as:
The most used methods of the classes such as KinDynComputations and InverseKinematics can be modified to accept this VectorExt class, to simplify interoperability and reducing the need of unnecessary copy, while avoiding dealing directly with raw pointers and preserving the possibility of checking sizes.
A thing that needs to be check is how to properly differentiate external buffers that can be modified to external buffers that can be only read.
The text was updated successfully, but these errors were encountered: