pub fn matmul<T: ComplexField, LhsT: Conjugate<Canonical = T>, RhsT: Conjugate<Canonical = T>, M: Shape, N: Shape, K: Shape>(
dst: impl AsMatMut<T = T, Rows = M, Cols = N>,
beta: Accum,
lhs: impl AsMatRef<T = LhsT, Rows = M, Cols = K>,
rhs: impl AsMatRef<T = RhsT, Rows = K, Cols = N>,
alpha: T,
par: Par,
)Expand description
computes the matrix product [beta * acc] + alpha * lhs * rhs and stores the result in acc
performs the operation:
acc = alpha * lhs * rhsifbetaisAccum::Replace(in this case, the preexisting values inaccare not read)acc = acc + alpha * lhs * rhsifbetaisAccum::Add
§panics
panics if the matrix dimensions are not compatible for matrix multiplication. i.e.
acc.nrows() == lhs.nrows()acc.ncols() == rhs.ncols()lhs.ncols() == rhs.nrows()
§Example
use faer::linalg::matmul::matmul;
use faer::{Accum, Conj, Mat, Par, mat, unzip, zip};
let lhs = mat![[0.0, 2.0], [1.0, 3.0]];
let rhs = mat![[4.0, 6.0], [5.0, 7.0]];
let mut acc = Mat::<f64>::zeros(2, 2);
let target = mat![
[
2.5 * (lhs[(0, 0)] * rhs[(0, 0)] + lhs[(0, 1)] * rhs[(1, 0)]),
2.5 * (lhs[(0, 0)] * rhs[(0, 1)] + lhs[(0, 1)] * rhs[(1, 1)]),
],
[
2.5 * (lhs[(1, 0)] * rhs[(0, 0)] + lhs[(1, 1)] * rhs[(1, 0)]),
2.5 * (lhs[(1, 0)] * rhs[(0, 1)] + lhs[(1, 1)] * rhs[(1, 1)]),
],
];
matmul(&mut acc, Accum::Replace, &lhs, &rhs, 2.5, Par::Seq);
zip!(&acc, &target).for_each(|unzip!(acc, target)| assert!((acc - target).abs() < 1e-10));