faer/operator/operator_impl/
diagref.rs

1use super::*;
2
3impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> LinOp<T> for DiagRef<'_, ViewT> {
4	#[inline]
5	fn apply_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq {
6		let _ = rhs_ncols;
7		let _ = par;
8		StackReq::EMPTY
9	}
10
11	#[inline]
12	fn nrows(&self) -> usize {
13		self.column_vector().nrows()
14	}
15
16	#[inline]
17	fn ncols(&self) -> usize {
18		self.column_vector().nrows()
19	}
20
21	#[math]
22	fn apply(&self, out: MatMut<'_, T>, rhs: MatRef<'_, T>, par: Par, stack: &mut MemStack) {
23		let k = rhs.ncols();
24		_ = par;
25		_ = stack;
26		let mut out = out;
27		for j in 0..k {
28			z!(out.rb_mut().col_mut(j), rhs.col(j), self.column_vector()).for_each(|uz!(out, rhs, d)| *out = *rhs * Conj::apply(d));
29		}
30	}
31
32	fn conj_apply(&self, out: MatMut<'_, T>, rhs: MatRef<'_, T>, par: Par, stack: &mut MemStack) {
33		self.column_vector().conjugate().as_diagonal().apply(out, rhs, par, stack)
34	}
35}
36
37impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> BiLinOp<T> for DiagRef<'_, ViewT> {
38	#[inline]
39	fn transpose_apply_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq {
40		self.apply_scratch(rhs_ncols, par)
41	}
42
43	fn transpose_apply(&self, out: MatMut<'_, T>, rhs: MatRef<'_, T>, par: Par, stack: &mut MemStack) {
44		self.apply(out, rhs, par, stack);
45	}
46
47	fn adjoint_apply(&self, out: MatMut<'_, T>, rhs: MatRef<'_, T>, par: Par, stack: &mut MemStack) {
48		self.conj_apply(out, rhs, par, stack);
49	}
50}
51
52impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> Precond<T> for DiagRef<'_, ViewT> {
53	fn apply_in_place_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq {
54		let _ = rhs_ncols;
55		let _ = par;
56		StackReq::EMPTY
57	}
58
59	#[math]
60	fn apply_in_place(&self, rhs: MatMut<'_, T>, par: Par, stack: &mut MemStack) {
61		_ = par;
62		_ = stack;
63		let mut rhs = rhs;
64		let k = rhs.ncols();
65		for j in 0..k {
66			z!(rhs.rb_mut().col_mut(j), self.column_vector()).for_each(|uz!(out, d)| *out = *out * Conj::apply(d));
67		}
68	}
69
70	fn conj_apply_in_place(&self, rhs: MatMut<'_, T>, par: Par, stack: &mut MemStack) {
71		self.column_vector().conjugate().as_diagonal().apply_in_place(rhs, par, stack)
72	}
73}
74impl<T: ComplexField, ViewT: Conjugate<Canonical = T>> BiPrecond<T> for DiagRef<'_, ViewT> {
75	fn transpose_apply_in_place_scratch(&self, rhs_ncols: usize, par: Par) -> StackReq {
76		self.apply_in_place_scratch(rhs_ncols, par)
77	}
78
79	fn transpose_apply_in_place(&self, rhs: MatMut<'_, T>, par: Par, stack: &mut MemStack) {
80		self.apply_in_place(rhs, par, stack)
81	}
82
83	fn adjoint_apply_in_place(&self, rhs: MatMut<'_, T>, par: Par, stack: &mut MemStack) {
84		self.conj_apply_in_place(rhs, par, stack)
85	}
86}