parent
f7f343b569
commit
89c745fa17
|
@ -516,7 +516,16 @@ macro_rules! dmat_impl(
|
|||
|
||||
#[inline]
|
||||
fn sub(self, right: $dmatrix<N>) -> $dmatrix<N> {
|
||||
right - self
|
||||
assert!(self.nrows == right.nrows && self.ncols == right.ncols,
|
||||
"Unable to subtract matrices with different dimensions.");
|
||||
|
||||
let mut res = right;
|
||||
|
||||
for (mij, res) in self.mij.iter().zip(res.mij.iter_mut()) {
|
||||
*res = *mij - *res;
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
tests/mat.rs
13
tests/mat.rs
|
@ -439,7 +439,9 @@ fn test_dmat_addition() {
|
|||
]
|
||||
);
|
||||
|
||||
assert!((mat1 + mat2) == res);
|
||||
assert!((mat1.clone() + mat2.clone()) == res);
|
||||
assert!((mat1.clone() + &mat2) == res);
|
||||
assert!((&mat1 + mat2) == res);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -471,7 +473,10 @@ fn test_dmat_multiplication() {
|
|||
]
|
||||
);
|
||||
|
||||
assert!((mat1 * mat2) == res);
|
||||
assert!((mat1.clone() * mat2.clone()) == res);
|
||||
assert!((&mat1 * mat2.clone()) == res);
|
||||
assert!((&mat1 * &mat2) == res);
|
||||
assert!((mat1 * &mat2) == res);
|
||||
}
|
||||
|
||||
// Tests multiplication of rectangular (non-square) matrices.
|
||||
|
@ -537,7 +542,9 @@ fn test_dmat_subtraction() {
|
|||
]
|
||||
);
|
||||
|
||||
assert!((mat1 - mat2) == res);
|
||||
assert!((mat1.clone() - mat2.clone()) == res);
|
||||
assert!((&mat1 - mat2.clone()) == res);
|
||||
assert!((mat1 - &mat2) == res);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue