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 std::ops::{Div};
use crate::{matrix_init, Matrix};
pub trait MDiv<Rhs>: Matrix
where
Self::Output: Matrix
{
type Output;
/// Returns matrix divided by a scalar
///
/// A/b
///
/// # Arguments
///
/// * `rhs` - A scalar
///
/// # Examples
///
/// ```rust
/// let a = [
/// [1.0, 2.0],
/// [3.0, 4.0]
/// ];
/// let b = 2.0;
/// let a_b = [
/// [0.5, 1.0],
/// [1.5, 2.0]
/// ];
/// assert_eq!(a.div(b), a_b)
/// ```
fn div(self, rhs: Rhs) -> Self::Output;
}
impl<F, const L: usize, const H: usize> MDiv<F> for [[F; L]; H]
where
Self: Matrix,
[[<F as Div<F>>::Output; L]; H]: Matrix,
F: Clone + Div<F>
{
type Output = [[<F as Div<F>>::Output; L]; H];
fn div(self, rhs: F) -> Self::Output
{
matrix_init(|r, c| self[r][c].clone()/rhs.clone())
}
}