use mdarray::{DSlice, DTensor, Layout, Shape, Slice};
use crate::matmul::{Triangle, Type};
use num_complex::ComplexFloat;
pub trait MatVec<T> {
fn matvec<'a, La, Lx>(
&self,
a: &'a DSlice<T, 2, La>,
x: &'a DSlice<T, 1, Lx>,
) -> impl MatVecBuilder<'a, T, La, Lx>
where
La: Layout,
Lx: Layout;
}
pub trait MatVecBuilder<'a, T, La, Lx>
where
La: Layout,
Lx: Layout,
T: 'a,
La: 'a,
Lx: 'a,
{
fn parallelize(self) -> Self;
fn scale(self, alpha: T) -> Self;
fn eval(self) -> DTensor<T, 1>;
fn overwrite<Ly: Layout>(self, y: &mut DSlice<T, 1, Ly>);
fn add_to<Ly: Layout>(self, y: &mut DSlice<T, 1, Ly>);
fn add_to_scaled<Ly: Layout>(self, y: &mut DSlice<T, 1, Ly>, beta: T);
fn add_outer<Ly: Layout>(self, y: &DSlice<T, 1, Ly>, beta: T) -> DTensor<T, 2>;
fn add_outer_special(self, beta: T, ty: Type, tr: Triangle) -> DTensor<T, 2>;
}
pub trait VecOps<T: ComplexFloat> {
fn add_to_scaled<Lx: Layout, Ly: Layout>(
&self,
alpha: T,
x: &DSlice<T, 1, Lx>,
y: &mut DSlice<T, 1, Ly>,
);
fn dot<Lx: Layout, Ly: Layout>(&self, x: &DSlice<T, 1, Lx>, y: &DSlice<T, 1, Ly>) -> T;
fn dotc<Lx: Layout, Ly: Layout>(&self, x: &DSlice<T, 1, Lx>, y: &DSlice<T, 1, Ly>) -> T;
fn norm2<Lx: Layout>(&self, x: &DSlice<T, 1, Lx>) -> T::Real;
fn norm1<Lx: Layout>(&self, x: &DSlice<T, 1, Lx>) -> T::Real
where
T: ComplexFloat;
fn copy<Lx: Layout, Ly: Layout>(&self, x: &DSlice<T, 1, Lx>, y: &mut DSlice<T, 1, Ly>);
fn scal<Lx: Layout>(&self, alpha: T, x: &mut DSlice<T, 1, Lx>);
fn swap<Lx: Layout, Ly: Layout>(&self, x: &mut DSlice<T, 1, Lx>, y: &mut DSlice<T, 1, Ly>);
fn rot<Lx: Layout, Ly: Layout>(
&self,
x: &mut DSlice<T, 1, Lx>,
y: &mut DSlice<T, 1, Ly>,
c: T::Real,
s: T,
) where
T: ComplexFloat;
}
pub trait Argmax<T: ComplexFloat + std::cmp::PartialOrd> {
fn argmax_overwrite<Lx: Layout, S: Shape>(
&self,
x: &Slice<T, S, Lx>,
output: &mut Vec<usize>,
) -> bool;
fn argmax_abs_overwrite<Lx: Layout, S: Shape>(
&self,
x: &Slice<T, S, Lx>,
output: &mut Vec<usize>,
) -> bool;
fn argmax<Lx: Layout, S: Shape>(&self, x: &Slice<T, S, Lx>) -> Option<Vec<usize>>;
fn argmax_abs<Lx: Layout, S: Shape>(&self, x: &Slice<T, S, Lx>) -> Option<Vec<usize>>;
}