nalgebra
nalgebra copied to clipboard
Specialized matrix types
Is there a way to implement custom matrix types, such that algorithms could use its structure efficiently? Say, having a diagonal matrix storing only its diagonal and specializing matrix-vector multiplication for it?
Probably related: #822
No, currently nothing like this is possible - and it's not likely to be possible any time soon either. A great number of methods in nalgebra
rely on the storage being a dense matrix.
A DiagonalMatrix
type is something I've been wanting for a while, however. Although perhaps it would be a better fit in nalgebra-sparse
than nalgebra
itself. This is however debatable as for example dense SVD or Eigendecompositions produce diagonal matrices. Currently these diagonal matrices are represented as vectors in nalgebra
, but this is less than ideal because you cannot work with the matrix as if it were a matrix.
I was expecting to have something like a matrix trait that could be implemented for different matrix types. But this rapidly evolves into a hierarchy of types (like in Julia), I'm afraid, and that can be hard given specialization in Rust being currently unstable (rust-lang/rust#31844).