Fix &DMatrix - DMatrix.

Fix #203.
This commit is contained in:
Sébastien Crozet 2016-09-06 19:41:47 +02:00
parent f7f343b569
commit 89c745fa17
2 changed files with 20 additions and 4 deletions

View File

@ -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
}
}

View File

@ -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]