matmul_with_conj

Function matmul_with_conj 

Source
pub fn matmul_with_conj<T: ComplexField, M: Shape, N: Shape, K: Shape>(
    dst: impl AsMatMut<T = T, Rows = M, Cols = N>,
    beta: Accum,
    lhs: impl AsMatRef<T = T, Rows = M, Cols = K>,
    conj_lhs: Conj,
    rhs: impl AsMatRef<T = T, Rows = K, Cols = N>,
    conj_rhs: Conj,
    alpha: T,
    par: Par,
)
Expand description

computes the matrix product [beta * acc] + alpha * lhs * rhs (implicitly conjugating the operands if needed) and stores the result in acc

performs the operation:

  • acc = alpha * lhs * rhs if beta is Accum::Replace (in this case, the preexisting values in acc are not read)
  • acc = acc + alpha * lhs * rhs if beta is Accum::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_with_conj;
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_with_conj(
	&mut acc,
	Accum::Replace,
	&lhs,
	Conj::No,
	&rhs,
	Conj::No,
	2.5,
	Par::Seq,
);

zip!(&acc, &target).for_each(|unzip!(acc, target)| assert!((acc - target).abs() < 1e-10));