array_matrix/matrix/
div.rs

1use std::ops::{Div};
2
3use crate::{matrix_init, Matrix};
4
5pub trait MDiv<Rhs>: Matrix
6where
7    Self::Output: Matrix
8{
9    type Output;
10    
11    /// Returns matrix divided by a scalar
12    /// 
13    /// A/b
14    /// 
15    /// # Arguments
16    /// 
17    /// * `rhs` - A scalar
18    /// 
19    /// # Examples
20    /// 
21    /// ```rust
22    /// let a = [
23    ///     [1.0, 2.0],
24    ///     [3.0, 4.0]
25    /// ];
26    /// let b = 2.0;
27    /// let a_b = [
28    ///     [0.5, 1.0],
29    ///     [1.5, 2.0]
30    /// ];
31    /// assert_eq!(a.div(b), a_b)
32    /// ```
33    fn div(self, rhs: Rhs) -> Self::Output;
34}
35
36impl<F, const L: usize, const H: usize> MDiv<F> for [[F; L]; H]
37where
38    Self: Matrix,
39    [[<F as Div<F>>::Output; L]; H]: Matrix,
40    F: Clone + Div<F>
41{
42    type Output = [[<F as Div<F>>::Output; L]; H];
43    fn div(self, rhs: F) -> Self::Output
44    {
45        matrix_init(|r, c| self[r][c].clone()/rhs.clone())
46    }
47}