ndarray
ndarray copied to clipboard
Introduce an ArrayLike trait
This is one of two PRs I'm working on that start to "traitify" ndarray. This trait is like the Ndarray trait suggested by @bluss in #339, but is slightly broader: it's meant to encapsulate not just actual ndarray types, but anything that could act like a multidimensional array. This includes Vecs, slices, arrays, and (critically) scalars that implement ScalarOperand.
The motivation for me was trying to design a set of methods expanded numerical methods, addressing #1462 (and others). My goal was to have these methods
- Work for types that implement the associated
num_traitstraits, i.e.,absforT: Signed. - Have both array-creating and array-mutating variants
- Broadcast amongst all arguments
- Work for arrays and scalars interchangeably
I was able to accomplish 1-3 with existing infrastructure, but you can see in #1462 that I was struggling with (4). This trait would allow me to accomplish all of these tasks.
Feedback is greatly welcome. Keep an eye out for two more upcoming PRs:
- An implementation of the math stuff above that uses
ArrayLike, to close #14632 - A PR with the
Ndarraytrait, following the design of #339
Note: This PR uses #1440 so should be merged after that.