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

Support Clone elements in stack and select #269

Closed
bluss opened this issue Jan 30, 2017 · 5 comments · Fixed by #932
Closed

Support Clone elements in stack and select #269

bluss opened this issue Jan 30, 2017 · 5 comments · Fixed by #932

Comments

@bluss
Copy link
Member

bluss commented Jan 30, 2017

Related issue to #249

@jturner314
Copy link
Member

This also applies to the .select() method (which is implemented in terms of stack).

@jturner314
Copy link
Member

To avoid uninitialized data issues, probably the simplest implementation would be to choose the iteration order and memory layout such that a Vec could be extended with the data from each array in sequence, and then re-interpret the Vec as an Array at the end.

For example, let's say you want to stack arrays a and b along axis 2. I think this will work:

  1. Permute the axes of a and b to move axis 2 to be the first axis, but preserve the ordering of the other axes.
  2. Create a new Vec.
  3. Extend the Vec from a.iter().cloned(), and then extend it with b.iter().cloned().
  4. Convert the Vec into an Array. (The first axis of this array will correspond to axis 2 of a and b, and the other axes will be in order.)
  5. Permute the axes of the Array to move the first axis to be axis 2.

This approach isn't necessarily the fastest because the iteration order may not be ideal, but it's relatively straightforward and doesn't need any unsafe code.

@jturner314 jturner314 changed the title Support Clone elements in stack Support Clone elements in stack and select Apr 19, 2019
@gussmith23
Copy link

Wondering if there's any movement on this -- I think this is blocking me. I'm using ndarray to hold tensors of non-"simple" values (i.e. things that don't implement Copy, like other tensors!). I know that use-case probably raises hairs on some peoples' necks, but ndarray has been handling it pretty well up til now! It would be a bummer if this turned out to be a permanent block.

@gussmith23
Copy link

Also FWIW, I could take a crack at implementing something!

@bluss
Copy link
Member Author

bluss commented Apr 18, 2020

Let's get the #735 merged first (or base the work on that).

Non-copy elements aren't all that simple, but jturner has a plan here, and it sounds like it's a good one.

Non-copy elements have this trouble elsewhere: #797 (comment)

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