1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use array::Array;
use std::ops::{Add, Mul};
pub fn vdot<T>(first: &Array<T>, second: &Array<T>) -> T
where T: Copy + Add<Output=T> + Mul<Output=T> + From<u8>
{
if !super::is_vector(&first) || !super::is_vector(&second) {
panic!("Calling method vdot with non vector like arrays is not supported");
}
let first_data = first.data.borrow();
let second_data = second.data.borrow();
return first.shape().get_bounds()
.zip(second.shape().get_bounds())
.fold(T::from(0), |acc, (f, s)| acc + first_data[f] * second_data[s]);
}