Skip to content

Improve documentation or add methods for conversion from nested Vec/ArrayBase #609

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

Closed
jturner314 opened this issue Mar 25, 2019 · 0 comments
Labels

Comments

@jturner314
Copy link
Member

A somewhat frequently-requested feature (e.g. #197, #590, #607) is to provide methods to create Array instances from nested Vec and/or ArrayBase instances (e.g. Array2<A> from Vec<Vec<A>> or Array3<A> from Vec<Array2<A>>).

Note that it's generally advisable to avoid nested Vec/ArrayBase types like this because they require extra heap allocations, can scatter data all over memory, cause unnecessary indirection, fail to enforce consistent shape within the nested Vecs/ArrayBases, and are generally more difficult to work with.

I think we should:

  • Improve the documentation to explain why these nested data structures are best avoided and the best way to handle the use cases (primarily constructing an Array by appending rows).
  • For users who need to use nested data structures anyway, either add the methods to perform the conversions or suggest how they could perform the conversion manually. (data.iter().flatten().cloned().collect::<Vec<_>>() followed by from_shape_vec seems pretty clean if the user is confident that the nested Vecs/ArrayBases are all the same length/shape).
jturner314 added a commit to jturner314/ndarray that referenced this issue Mar 25, 2019
Fixes rust-ndarray#609 (assuming we don't want to actually add conversion
methods).
jturner314 added a commit that referenced this issue Mar 25, 2019
Fixes #609 (assuming we don't want to actually add conversion
methods).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant