rust_linear_algebra/matrix/ops/
div.rs

1use super::super::Matrix;
2use std::ops::Div;
3
4impl<K, T> Div<T> for Matrix<K>
5where
6    K: Div<T, Output = K> + Copy + Default,
7    T: Copy,
8{
9    type Output = Matrix<K>;
10
11    fn div(self, rhs: T) -> Self::Output {
12        let mut elements = vec![vec![K::default(); self.cols()]; self.rows()];
13
14        for i in 0..self.rows() {
15            for j in 0..self.cols() {
16                elements[i][j] = self.elements[i][j] / rhs;
17            }
18        }
19
20        Matrix { elements }
21    }
22}
23
24impl<K> Matrix<K>
25where
26    K: Div<Output = K> + Copy,
27{
28    pub fn inv_scl(&mut self, a: K) {
29        self.iter_mut()
30            .for_each(|row| row.iter_mut().for_each(|v| *v = *v / a));
31    }
32}