array_matrix/vector/
outer.rs

1use std::ops::Mul;
2
3use crate::{matrix_init, Matrix, Vector};
4
5pub trait Outer<Rhs: Vector>: Vector
6where Self::Output: Matrix
7{
8    type Output;
9    
10    /// Returns the outer product of two vector-arrays
11    /// 
12    /// u ⊗ v
13    /// 
14    /// # Arguments
15    /// 
16    /// * `rhs` - A vector
17    /// 
18    /// # Examples
19    /// 
20    /// ```rust
21    /// let u = [1.0, 2.0, 3.0];
22    /// let v = [1.0, 2.0, 3.0];
23    /// let uv = [
24    ///     [1.0, 2.0, 3.0],
25    ///     [2.0, 4.0, 6.0],
26    ///     [3.0, 6.0, 9.0]
27    /// ];
28    /// 
29    /// assert_eq!(u.outer(v), uv);
30    /// ```
31    fn outer(self, rhs: Rhs) -> Self::Output;
32}
33
34impl<F, const L: usize, const H: usize> Outer<[F; L]> for [F; H]
35where
36    Self: Vector,
37    [F; L]: Vector,
38    [[<F as Mul<F>>::Output; L]; H]: Matrix,
39    F: Mul<F> + Clone
40{
41    type Output = [[<F as Mul<F>>::Output; L]; H];
42    fn outer(self, rhs: [F; L]) -> Self::Output
43    {
44        matrix_init(|r, c| self[r].clone()*rhs[c].clone())
45    }
46}