ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

Fixed axis length support similiar to `Eigen`

Open zirconium-n opened this issue 3 years ago • 2 comments
trafficstars

In Eigen, We can write Matrix<float, 4, 4> to represent a matrix with fixed 4x4 size. In Rust, I would imaging syntax similar to ArrayBase<Array2Repr<T, 4, 4>, FixedIx2<4, 4>>, which has no allocation, const bound check and enable better simd instructions.

I can see several difficulty implementing this:

  1. Dimension trait currently requires Add/Sub/Mul, which doesn't make sense in fixed length.
  2. ArrayRepr requires exact generic argument match to FixedIx2. This might requires refactor to Data or Dimension traits.
  3. Enable better simd instructions on specific axis length might require #[feature(const_evaluatable_checked)] and #[feature(specialization)], and both of them are incomplete feature.
  4. Mixing fixed axis length and dynamic axis length in one matrix seems hard.

zirconium-n avatar Dec 17 '21 07:12 zirconium-n

I think @bluss has indicated in the past that he doesn't want to do this, but it's been a while. Personally, I'm concerned about the additional complexity without sufficient benefit. I think it would make more sense to start with named tensor functionality, with marker types for the axis names. This is more important for n-D arrays, IMO, and then we could consider supporting const lengths associated with the marker types.

You may be interested in the nalgebra crate, which provides fixed axis length support for vectors and matrices (but not arrays with more than 2 dimensions).

jturner314 avatar Dec 18 '21 19:12 jturner314

I think @bluss has indicated in the past that he doesn't want to do this, but it's been a while. Personally, I'm concerned about the additional complexity without sufficient benefit. I think it would make more sense to start with named tensor functionality, with marker types for the axis names. This is more important for n-D arrays, IMO, and then we could consider supporting const lengths associated with the marker types.

You may be interested in the nalgebra crate, which provides fixed axis length support for vectors and matrices (but not arrays with more than 2 dimensions).

Thanks, I will look into nalgebra. On the other hand, I will investigate the complexity/benefit factor deeper.

zirconium-n avatar Dec 21 '21 03:12 zirconium-n