xtensor
xtensor copied to clipboard
Add rvalue overload for `xcontainer::storage`
Motivation
It can make sense for users to move the data/storage out of an xcontainer
(for instance statically reshape an xt::xtensor<T, N>
to an xt::xtensor<T, 1>
).
Right now, we can do
xtensor<T, 1> new_tensor{std::move(old_tensor.storage()), {old_tensor.size()}, {1}};
But, as suggested by @JohanMabille, we cannot do
xtensor<T, 1> new_tensor(std::move(old_tensor).storage(), ...);
Or
xtensor<T, 2> some_func(....);
xtensor<T, 1> new_tensor(some_func().storage(), ...);
Proposed Implementation
Add one of the following overload to xcontainer
:
- a/ storage_type&& storage() noexcept&&;
- b/ storage_type storage() noexcept&&;
I can send a PR for this.
Would be great! Actually, it would also be great to have a little section in the docs as well. Maybe somewhere around here ?
@AntoinePrv I thought I had replied and I just realized I didn't, sorry for that.
I think the signature should be the first one since the method will return a data member (which is not a rvalue, thus there a chance to have a copy if you use the second signature).
A PR woule be very welcome!