镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add rvalue overload for xcontainer::storage #2401

Description

@AntoinePrv

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.

Activity

  1. tdegeus commented on Jun 17, 2021

    @tdegeus
    Member

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

  2. JohanMabille commented on Jun 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions