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
use std::ops::{Mul, Add};
use num_traits::Zero;
use crate::Vector;
pub trait Dot<Rhs: Vector>: Vector
{
type Output;
fn dot(self, rhs: Rhs) -> Self::Output;
}
impl<F, const L: usize> Dot<[F; L]> for [F; L]
where
Self: Vector,
F: Mul<F, Output = F> + Add<F, Output = F> + Zero + Clone
{
type Output = F;
fn dot(self, rhs: [F; L]) -> Self::Output
{
(0..L).map(|i| self[i].clone()*rhs[i].clone()).reduce(|a, b| a + b).unwrap_or(F::zero())
}
}