ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

Introduce an ArrayLike trait

Open akern40 opened this issue 10 months ago • 0 comments

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

  1. Work for types that implement the associated num_traits traits, i.e., abs for T: Signed.
  2. Have both array-creating and array-mutating variants
  3. Broadcast amongst all arguments
  4. 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:

  1. An implementation of the math stuff above that uses ArrayLike, to close #14632
  2. A PR with the Ndarray trait, following the design of #339

Note: This PR uses #1440 so should be merged after that.

akern40 avatar Dec 26 '24 04:12 akern40