Closed
Description
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 Vec
s/ArrayBase
s, 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 byfrom_shape_vec
seems pretty clean if the user is confident that the nestedVec
s/ArrayBase
s are all the same length/shape).