|
@@ -200,7 +200,8 @@ impl<
|
|
|
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
mod tests {
|
|
mod tests {
|
|
- use crate::{SquareMatrix};
|
|
|
|
|
|
+ use crate::{ColumnVector, RowVector, SquareMatrix};
|
|
|
|
+ use crate::types::matrix::multiply;
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
fn view_of_generic_matrix() {
|
|
fn view_of_generic_matrix() {
|
|
@@ -208,4 +209,28 @@ mod tests {
|
|
let view = mat.view::<2, 2>(1, 1);
|
|
let view = mat.view::<2, 2>(1, 1);
|
|
assert_eq!(view, SquareMatrix::diagonal(&[2, 3]));
|
|
assert_eq!(view, SquareMatrix::diagonal(&[2, 3]));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn multiply_views_inside_generic_matrix() {
|
|
|
|
+ let mut mat = SquareMatrix::from([
|
|
|
|
+ [0, 4, -2, -1],
|
|
|
|
+ [1, 0, 0, 0],
|
|
|
|
+ [3, 0, 0, 0],
|
|
|
|
+ [-5, 0, 0, 0],
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ let a = ColumnVector::from(mat.view::<3, 1>(1, 0));
|
|
|
|
+ let b = RowVector::from(mat.view::<1, 3>(0, 1));
|
|
|
|
+ multiply(&mut mat.view_mut::<3, 3>(1, 1), &a, &b);
|
|
|
|
+
|
|
|
|
+ assert_eq!(
|
|
|
|
+ mat,
|
|
|
|
+ SquareMatrix::from([
|
|
|
|
+ [0, 4, -2, -1],
|
|
|
|
+ [1, 4, -2, -1],
|
|
|
|
+ [3, 12, -6, -3],
|
|
|
|
+ [-5, -20, 10, 5],
|
|
|
|
+ ])
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|