fre-hu / mdarray

Multidimensional array for Rust
Apache License 2.0
11 stars 0 forks source link

Support for dynamic number of dimensions #4

Open grothesque opened 1 month ago

grothesque commented 1 month ago

I reference a discussion from https://github.com/rust-ndarray/ndarray/issues/1272#issuecomment-2325747608:

@fre-hu wrote:

I think the simplest way is to add dynamic rank as a new shape type and keep the existing layout types. The shape types for static rank are tuples of dimensions (each static or dynamic), and the new type will instead consist of a Box/Vec. The resulting layout mapping will then use Box/Vec for both shape and strides.

There can be limitations and for some operations like creating array views and permuting dimensions the rank must be static. But yes you can always convert to static rank for calculations.

Please correct me if I'm wrong, but with today's mdarray it is simply not possible to have arrays beyond a certain rank.

Of course there is no way around this with today's Rust given that macros need to be instantiated for each supported number of dimensions. And also the value of supporting static shapes beyond, say, 10 dimensions, seems marginal.

But for completeness and interfacing with other general array libraries, I think that supporting a fully generic layout would be very valuable.

grothesque commented 4 weeks ago

I'm working on a new library for tensor network computations. See there for a design sketch. (Comments are most welcome!)

I think that mdarray could be ideal as the dense array backend for my library, but the one crucial missing feature is support for dynamic number of dimensions.

Would you be open to adding support for dynamic number of dimensions (following the idea you sketch out above) to mdarray?

fre-hu commented 4 weeks ago

Yes, I have a prototype that just needs to be cleaned up.

fre-hu commented 2 weeks ago

Please see the latest commit for dynamic rank support.