Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-03-12 20:51:42 +03:00
parent 33ea6498cf
commit 2eca1003cf
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D

View file

@ -36,7 +36,7 @@ pub fn sum<T: Add<Output = T> + Copy>(a: &Matrix<T>, b: &Matrix<T>) -> Option<Ma
Some(c) Some(c)
} }
pub fn mul<T: Mul<Output = T> + Copy + AddAssign + MulAssign + std::fmt::Display + From<u8>>( pub fn mul<T: Mul<Output = T> + Copy + AddAssign + From<u8>>(
a: &Matrix<T>, a: &Matrix<T>,
b: &Matrix<T>, b: &Matrix<T>,
) -> Option<Matrix<T>> { ) -> Option<Matrix<T>> {
@ -66,10 +66,7 @@ pub fn mul<T: Mul<Output = T> + Copy + AddAssign + MulAssign + std::fmt::Display
} }
#[allow(dead_code)] #[allow(dead_code)]
fn gen_matrix<T: Mul<Output = T> + Copy + AddAssign + MulAssign + std::fmt::Display + From<i32>>( fn gen_matrix<T: From<i32>>(i: usize, j: usize) -> Option<Matrix<T>> {
i: usize,
j: usize,
) -> Option<Matrix<T>> {
if !(i > 0 && j > 0) { if !(i > 0 && j > 0) {
return None; return None;
} }
@ -123,7 +120,7 @@ mod test {
let ab = mul(&a, &b); let ab = mul(&a, &b);
let ba = mul(&b, &a); let ba = mul(&b, &a);
if ab != None && ba != None { if ab != None && ba != None {
assert!(ab.unwrap() == ba.unwrap()) assert_eq!(ab.unwrap(), ba.unwrap())
} else { } else {
assert!(false) assert!(false)
} }