1use mdarray::{DSlice, DTensor, Layout, Shape, Slice};
3
4use crate::matmul::{Triangle, Type};
5
6use num_complex::ComplexFloat;
7
8pub trait MatVec<T> {
10 fn matvec<'a, La, Lx>(
11 &self,
12 a: &'a DSlice<T, 2, La>,
13 x: &'a DSlice<T, 1, Lx>,
14 ) -> impl MatVecBuilder<'a, T, La, Lx>
15 where
16 La: Layout,
17 Lx: Layout;
18}
19
20pub trait MatVecBuilder<'a, T, La, Lx>
22where
23 La: Layout,
24 Lx: Layout,
25 T: 'a,
26 La: 'a,
27 Lx: 'a,
28{
29 fn parallelize(self) -> Self;
30
31 fn scale(self, alpha: T) -> Self;
33
34 fn eval(self) -> DTensor<T, 1>;
36
37 fn overwrite<Ly: Layout>(self, y: &mut DSlice<T, 1, Ly>);
39
40 fn add_to<Ly: Layout>(self, y: &mut DSlice<T, 1, Ly>);
42
43 fn add_to_scaled<Ly: Layout>(self, y: &mut DSlice<T, 1, Ly>, beta: T);
45
46 fn add_outer<Ly: Layout>(self, y: &DSlice<T, 1, Ly>, beta: T) -> DTensor<T, 2>;
48
49 fn add_outer_special(self, beta: T, ty: Type, tr: Triangle) -> DTensor<T, 2>;
51
52 }
58
59pub trait VecOps<T: ComplexFloat> {
61 fn add_to_scaled<Lx: Layout, Ly: Layout>(
63 &self,
64 alpha: T,
65 x: &DSlice<T, 1, Lx>,
66 y: &mut DSlice<T, 1, Ly>,
67 );
68
69 fn dot<Lx: Layout, Ly: Layout>(&self, x: &DSlice<T, 1, Lx>, y: &DSlice<T, 1, Ly>) -> T;
71
72 fn dotc<Lx: Layout, Ly: Layout>(&self, x: &DSlice<T, 1, Lx>, y: &DSlice<T, 1, Ly>) -> T;
74
75 fn norm2<Lx: Layout>(&self, x: &DSlice<T, 1, Lx>) -> T::Real;
77
78 fn norm1<Lx: Layout>(&self, x: &DSlice<T, 1, Lx>) -> T::Real
80 where
81 T: ComplexFloat;
82
83 fn copy<Lx: Layout, Ly: Layout>(&self, x: &DSlice<T, 1, Lx>, y: &mut DSlice<T, 1, Ly>);
85
86 fn scal<Lx: Layout>(&self, alpha: T, x: &mut DSlice<T, 1, Lx>);
88
89 fn swap<Lx: Layout, Ly: Layout>(&self, x: &mut DSlice<T, 1, Lx>, y: &mut DSlice<T, 1, Ly>);
91
92 fn rot<Lx: Layout, Ly: Layout>(
94 &self,
95 x: &mut DSlice<T, 1, Lx>,
96 y: &mut DSlice<T, 1, Ly>,
97 c: T::Real,
98 s: T,
99 ) where
100 T: ComplexFloat;
101}
102
103pub trait Argmax<T: ComplexFloat + std::cmp::PartialOrd> {
105 fn argmax_overwrite<Lx: Layout, S: Shape>(
106 &self,
107 x: &Slice<T, S, Lx>,
108 output: &mut Vec<usize>,
109 ) -> bool;
110
111 fn argmax_abs_overwrite<Lx: Layout, S: Shape>(
112 &self,
113 x: &Slice<T, S, Lx>,
114 output: &mut Vec<usize>,
115 ) -> bool;
116
117 fn argmax<Lx: Layout, S: Shape>(&self, x: &Slice<T, S, Lx>) -> Option<Vec<usize>>;
119
120 fn argmax_abs<Lx: Layout, S: Shape>(&self, x: &Slice<T, S, Lx>) -> Option<Vec<usize>>;
122}