rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.43k stars 295 forks source link

Add generic initializers for statically-dimensioned array types #1385

Open thatcomputerguy0101 opened 1 month ago

thatcomputerguy0101 commented 1 month ago

This takes advantage of const generics to provide general initializers for the statically-dimensioned array types. (2-6 dimensions, with the current implementations). This reduces the reliance on macros for array initialization, and enables other crates to operate more succinctly when working with an unknown-dimension static array type. I'm unsure how well this fits with the existence of the dynamic array index implementation, and the name of the new type alias IxD is open for discussion. No additional test cases have been implemented for this functionality yet.

bluss commented 1 month ago

Hm, new clippy lints should be fixed in a different PR, I think

thatcomputerguy0101 commented 1 month ago

I originally decided on the name IxD to match the style of Ix0, Ix1, etc..., but with a generic D instead of a fixed value. It is also short, which helps in its usability as a convenience type (since it is an alias for Dim<[Ix, D]>). However, its name is close to IxDyn, and I have concerns about possible confusion between those two.

thatcomputerguy0101 commented 3 days ago

With my most recent updates, I believe all static-related simplification that can be done within the current Rust feature set is implemented. This can be revisited in the future once https://github.com/rust-lang/rust/issues/76560 lands.