matrix multiplication
This commit is contained in:
parent
1a6ece1312
commit
34450d6a13
@ -32,6 +32,29 @@ macro_rules! impl_matrix {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
// MatX<VecY>.MatY<VecZ> = MatX<VecZ>
|
||||||
|
pub fn dot<const Z:usize,U,V>(self,rhs:Matrix<Y,Z,U>)->Matrix<X,Z,V>
|
||||||
|
where
|
||||||
|
T:core::ops::Mul<U,Output=V>+Copy,
|
||||||
|
V:core::iter::Sum,
|
||||||
|
{
|
||||||
|
let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter());
|
||||||
|
Matrix{
|
||||||
|
array:self.array.map(|axis|
|
||||||
|
core::array::from_fn(|_|
|
||||||
|
// axis dot product with transposed rhs array
|
||||||
|
axis.into_iter().zip(
|
||||||
|
array_of_iterators.each_mut().map(|iter|
|
||||||
|
iter.next().unwrap()
|
||||||
|
)
|
||||||
|
).map(|(a,b)|
|
||||||
|
a*b
|
||||||
|
).sum()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>
|
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user