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::algebra::{ abstr::{Field, Scalar}, linear::Matrix, }; use std::ops::Div; //Divides all matrix elements with a scalar impl<T> Div<T> for Matrix<T> where T: Field + Scalar { type Output = Matrix<T>; /// Divides all matrix element with a scalar /// /// # Example /// /// ``` /// use mathru::algebra::linear::Matrix; /// /// let res_ref: Matrix<f64> = Matrix::new(2, 2, vec![1.0, 0.0, 3.0, -7.0]); /// let f: f64 = 7.0; /// let a: Matrix<f64> = Matrix::new(2, 2, vec![7.0, 0.0, 21.0, -49.0]); /// ``` fn div(self, m: T) -> Matrix<T> { return self * (T::one() / m); } } impl<'a, 'b, T> Div<&'b T> for &'a Matrix<T> where T: Field + Scalar { type Output = Matrix<T>; /// Divide all matrix with a scalar /// /// # Example /// /// ``` /// use mathru::algebra::linear::Matrix; /// /// let res_ref: Matrix<f64> = Matrix::new(2, 2, vec![1.0, 0.0, 3.0, -7.0]); /// let a: Matrix<f64> = Matrix::new(2, 2, vec![4.0, 0.0, 12.0, -28.0]); /// ``` fn div(self, m: &'b T) -> Matrix<T> { return self.clone() * (T::one() / *m); } }