1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use crate::{matrix::Matrix, number::Number, types::Type}; pub trait SubMatrix<U>: Send + Sync { fn size(&self) -> (usize, usize); fn index(&self, i: usize, j: usize) -> U; } impl<U> SubMatrix<U> for U where U: Number, { fn size(&self) -> (usize, usize) { (1usize, 1usize) } fn index(&self, _: usize, _: usize) -> U { *self } } impl<T, U> SubMatrix<U> for Matrix<T, U> where T: Type, U: Number, { fn size(&self) -> (usize, usize) { (self.get_rows(), self.get_columns()) } fn index(&self, i: usize, j: usize) -> U { self[i][j] } } impl<T, U> SubMatrix<U> for &Matrix<T, U> where T: Type, U: Number, { fn size(&self) -> (usize, usize) { (self.get_rows(), self.get_columns()) } fn index(&self, i: usize, j: usize) -> U { self[i][j] } }