You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, matrix multiplication only works when the matrices have the same type T. However, matrices of matrices are common in control engineering and should be supported.
Current behavior:
use nalgebra::matrix;let m1 = matrix![1,2;3,4];let m2 = matrix![m1, m1; m1, m1];// Multiplication works for matrices of the same type `T`.let _ = m2 * m2;// T: Matrix<i32, U2, U2>// m2: Matrix<Matrix<i32, U2, U2>, U2, U2> = Matrix<T, U2, U2>// So Output: Matrix<Matrix<i32, U2, U2>, U2, U2> = Matrix<T, U2, U2>
Requested behavior:
// Multiplication fails because the types `T` are different.// However, the inner matrices (2x2 and 2x1) can be multiplied, so this should be allowed.let v = vector![5,6];let m3 = matrix![v, v; v, v];let _ = m2 * m3;// T1: Matrix<i32, U2, U2>// T2: Matrix<i32, U2, U1>// m1 * v: Matrix<i32, U2, U1> // So Output should be: Matrix<Matrix<i32, U2, U1>, U2, U2>
The compile-time error is as follows:
error[E0277]: cannot multiply `Matrix<Matrix<{integer}, Const<2>, Const<2>, ArrayStorage<{integer}, 2, 2>>, Const<2>, Const<2>, ArrayStorage<Matrix<{integer}, Const<2>, Const<2>, ArrayStorage<{integer}, 2, 2>>, 2, 2>>` by `Matrix<{integer}, Const<2>, Const<1>, ArrayStorage<{integer}, 2, 1>>`
--> src/main.rs:26:16
|
26 | let _ = m2 * v;
| ^ no implementation for `Matrix<Matrix<{integer}, Const<2>, Const<2>, ArrayStorage<{integer}, 2, 2>>, Const<2>, Const<2>, ArrayStorage<Matrix<{integer}, Const<2>, Const<2>, ArrayStorage<{integer}, 2, 2>>, 2, 2>> * Matrix<{integer}, Const<2>, Const<1>, ArrayStorage<{integer}, 2, 1>>`
|
= help: the trait `Mul<Matrix<{integer}, Const<2>, Const<1>, ArrayStorage<{integer}, 2, 1>>>` is not implemented for `Matrix<Matrix<{integer}, Const<2>, Const<2>, ArrayStorage<{integer}, 2, 2>>, Const<2>, Const<2>, ArrayStorage<Matrix<..., ..., ..., ...>, 2, 2>>`
= help: the following other types implement trait `Mul<Rhs>`:
<Matrix<T, Const<R1>, Const<C1>, SA> as Mul<OPoint<T, Const<D2>>>>
<Matrix<T, R, C, S> as Mul<T>>
<Matrix<T, R1, C1, SA> as Mul<Rotation<T, D2>>>
<Matrix<T, R1, C1, SA> as Mul<Matrix<T, R2, C2, SB>>>
<Matrix<T, Const<R1>, Const<C1>, SA> as Mul<&'b OPoint<T, Const<D2>>>>
<Matrix<T, R1, C1, SA> as Mul<&'b Rotation<T, D2>>>
<Matrix<T, R1, C1, SA> as Mul<&'b Matrix<T, R2, C2, SB>>>
<&'a Matrix<T, R1, C1, SA> as Mul<&'b Matrix<T, R2, C2, SB>>>
and 6 others
For more information about this error, try `rustc --explain E0277`.
The text was updated successfully, but these errors were encountered:
I think this is better handled by just stacking the matrices into a larger matrix and performing ordinary matrix operations. This will be made easier with the stack! macro that is ready to be merged in #1375.
I can't really see us wanting to take on the complexity of directly supporting this relatively niche use case, so I'm going to close this issue.
Currently, matrix multiplication only works when the matrices have the same type
T
. However, matrices of matrices are common in control engineering and should be supported.Current behavior:
Requested behavior:
The compile-time error is as follows:
The text was updated successfully, but these errors were encountered: