Open grothesque opened 1 month ago
I have switched to row-major order as it makes more sense, see the latest commit. I have also reduced the layout types to dense and strided, since these are the most important. Better to keep it simple and add back if it is really needed.
Regarding having both row and column-major order, yes the order could be merged into the layout type. The complexity is still there though, and there must be rules about iteration order, how to derive types for subarrays and how to do broadcasting etc. I will think some more about it.
Sounds great. Looking forward to your ideas about merging order into layout.
I fully agree that an array crate for Rust should strive to be minimalist. I think that the right approach is to think of it as providing common concepts and glue, while actual numerical algorithms are to be provided by other crates.
This is the approach that has been successful with Fortran, and that C++ is finally pursuing with their mdspan. I consider the monolithic approach of Numpy/SciPy, despite their success, as a technical liability rooted in the shortcomings of Python's packaging.
I reference a discussion from https://github.com/rust-ndarray/ndarray/issues/1272#issuecomment-2325747608:
@grothesque wrote:
@fre-hu replied:
From my point of view, row-major is arguably more relevant for a Rust array library than column major:
expr![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
having shape(3, 2)
and not(2, 3)
by default seems surprising.So, if there can be only one, I'd vote for row major :innocent:...
However, as far as memory layout goes, it should be possible to have both without an additional generic parameter, right? Just like C++ mdspan has
layout_right
,layout_left
, andlayout_stride
.The problem seems to be more about ensuring efficient order of dimensions when iterating. One possibility would be to have both ("iterate_left_to_right", and "iterate_right_to_left"), and then only one (or none) would be efficient for a given array.
To treat the general case efficiently, there could be a function to (statically or dynamically) reorder dimensions into either layout (if possible).
All of this would not require an additional generic parameter (I believe).