array_matrix/vector/
dot.rs1use std::ops::{Mul, Add};
2
3use num_traits::Zero;
4
5use crate::Vector;
6
7pub trait Dot<Rhs: Vector>: Vector
8{
9 type Output;
10
11 fn dot(self, rhs: Rhs) -> Self::Output;
29}
30
31impl<F, const L: usize> Dot<[F; L]> for [F; L]
32where
33 Self: Vector,
34 F: Mul<F, Output = F> + Add<F, Output = F> + Zero + Clone
35{
36 type Output = F;
37 fn dot(self, rhs: [F; L]) -> Self::Output
38 {
39 (0..L).map(|i| self[i].clone()*rhs[i].clone()).reduce(|a, b| a + b).unwrap_or(F::zero())
40 }
41}