-
Notifications
You must be signed in to change notification settings - Fork 357
Description
The recent addition of ArrayRef to ndarray explicitly unifies the in-memory representation of arrays in ndarray to be something like a tuple of (shape, strides, data ptr). This allows implementing Deref from all array types to the reference type. This in turn allows functions to accept array parameters as nothing more than a pointer to such a tuple, no matter whether the actual type is an owned array, a view, or something else. This avoids a lot of needlessly generic code and greatly simplifies APIs, just like the built-in slices of Rust do.
The next step of this harmonization would be realizing that to a large extent the different multi-dimensional array libraries for Rust work with a very similar model of what is an array. Perhaps a standard memory representation (i.e. order and data type for shape and strides) of array reference could be established that is shared across multiple crates?
- The mdarray crate has a Slice type that is similar to ndarray’s ArrayRef supports arbitrary shapes and strides.
- Faer has MatRef which is always two-dimensional, but supports arbitrary shapes and strides.
- As far as I know nalgebra’s matrices are always densely packed in the first dimension, which prevents them being reinterpreted as ArrayRefs at this point, but an reinterpretation as mdarray slices might be possible.
- There are more, but you get the point.
Anyway, without looking too much into the technical details at this moment, I would like to bring up the question whether there is interest in some degree of harmonization. I believe that this has the potential to greatly benefit the Rust numerical array “ecosystem”. If the array references became compatible, libraries could add features that enable Deref implementations from the array ref of an external library to the native one.
@sarah-quinones, @fre-hu, @akern40, what do you think?