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

Add rvalue overload for xcontainer::storage #2401

Open
AntoinePrv opened this issue Jun 16, 2021 · 2 comments · May be fixed by #2413
Open

Add rvalue overload for xcontainer::storage #2401

AntoinePrv opened this issue Jun 16, 2021 · 2 comments · May be fixed by #2413

Comments

@AntoinePrv
Copy link
Contributor

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.

@tdegeus
Copy link
Member

tdegeus commented Jun 17, 2021

Would be great!
Actually, it would also be great to have a little section in the docs as well. Maybe somewhere around here ?

@JohanMabille
Copy link
Member

@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!

@AntoinePrv AntoinePrv linked a pull request Jul 13, 2021 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants