Merge pull request #143 from aryla/master
Fix multiplication of rectangular DMats.
This commit is contained in:
commit
53b8737aca
|
@ -285,11 +285,11 @@ impl<'a, N: Copy + Mul<N, Output = N> + Add<N, Output = N> + Zero> Mul<DMat<N>>
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mul(self, right: DMat<N>) -> DMat<N> {
|
fn mul(self, right: DMat<N>) -> DMat<N> {
|
||||||
right * self
|
self * (&right)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, N: Copy + Mul<N, Output = N> + Add<N, Output = N> + Zero> Mul<&'a DMat<N>> for &'a DMat<N> {
|
impl<'a, 'b, N: Copy + Mul<N, Output = N> + Add<N, Output = N> + Zero> Mul<&'b DMat<N>> for &'a DMat<N> {
|
||||||
type Output = DMat<N>;
|
type Output = DMat<N>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
34
tests/mat.rs
34
tests/mat.rs
|
@ -354,6 +354,40 @@ fn test_dmat_multiplication() {
|
||||||
assert!((mat1 * mat2) == res);
|
assert!((mat1 * mat2) == res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests multiplication of rectangular (non-square) matrices.
|
||||||
|
#[test]
|
||||||
|
fn test_dmat_multiplication_rect() {
|
||||||
|
let mat1 = DMat::from_row_vec(
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
&[
|
||||||
|
1.0, 2.0,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
let mat2 = DMat::from_row_vec(
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
&[
|
||||||
|
3.0, 4.0, 5.0,
|
||||||
|
6.0, 7.0, 8.0,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
let res = DMat::from_row_vec(
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
&[
|
||||||
|
15.0, 18.0, 21.0,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!((mat1.clone() * mat2.clone()) == res);
|
||||||
|
assert!((&mat1 * mat2.clone()) == res);
|
||||||
|
assert!((mat1.clone() * &mat2) == res);
|
||||||
|
assert!((&mat1 * &mat2) == res);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dmat_subtraction() {
|
fn test_dmat_subtraction() {
|
||||||
let mat1 = DMat::from_row_vec(
|
let mat1 = DMat::from_row_vec(
|
||||||
|
|
Loading…
Reference in New Issue