Matrix Implement Alga Traits

Hello,

I am trying to implement a class that can operate on any generic vector/matrix, so almost everything was written with traits in alga. However, when I tried to use Matrix2 in nalgebra, the compiler produced an error about trait not implemented.

    error[E0277]: the trait bound `na::Matrix<f64, na::U2, na::U2, na::ArrayStorage<f64, na::U2, na::U2>>: alga::linear::matrix::SquareMatrix` is not satisfied
 --> src/main.rs:7:49
  |
7 |     let basis = OrderedOrthonormalBasis::from(Matrix2::<f64>::identity());
  |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `alga::linear::matrix::SquareMatrix` is not implemented for `na::Matrix<f64, na::U2, na::U2, na::ArrayStorage<f64, na::U2, na::U2>>`
  |

Is there a reason Matrix traits are not implemented by nalgebra?

Hi!

I don’t see any reasons why we did not implement alga::linear::Matrix for statically-sized matrices from nalgebra. So I guess this was an overlook.

However, keep in mind that alga is no longer actively developed (nalgebra now uses the simba crate instead) and all implementation of alga traits are now exposed only if the alga cargo feature of nalgebra is activated. So we currently have no plan to add any more implementations of alga traits in nalgebra (but we will still accept them to be merged if they were contributed through a pull request).

So I think there are three options:

  • You may try to implement these traits you want yourself. I will be happy to mentor if you need guidance for that.
  • Or you can define your own matrix traits that you can implement.
  • Or you can make your structure generic wrt. the matrix dimensions instead of the matrix type itself.

Hello,

Thank you for letting me know that alga is no longer being actively developed. I did implement my own Vector struct based on the alga traits, which is why I liked it a lot and decided to use it as the generic library. Really appreciate your offering to help out! :smiley:

I will take a look at simba as well as trying to implement my program with generic dimensions. My main objective is to implement something that is generic enough, so that I can even swap out the data type in Matrix to some other field (like a function instead of numbers).

Thank you very much!