Trait totsu_core::solver::LinAlg
source · pub trait LinAlg {
type F: Float;
type Sl: SliceLike<F = Self::F> + ?Sized;
fn norm(x: &Self::Sl) -> Self::F;
fn copy(x: &Self::Sl, y: &mut Self::Sl);
fn scale(alpha: Self::F, x: &mut Self::Sl);
fn add(alpha: Self::F, x: &Self::Sl, y: &mut Self::Sl);
fn adds(s: Self::F, y: &mut Self::Sl);
fn abssum(x: &Self::Sl, incx: usize) -> Self::F;
fn transform_di(
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
);
}
Expand description
Linear algebra trait.
Required Associated Types§
Required Methods§
sourcefn norm(x: &Self::Sl) -> Self::F
fn norm(x: &Self::Sl) -> Self::F
Calculates 2-norm (or euclidean norm) \(\|x\|_2=\sqrt{\sum_i x_i^2}\).
Returns the calculated norm.
x
is a vector \(x\).
sourcefn copy(x: &Self::Sl, y: &mut Self::Sl)
fn copy(x: &Self::Sl, y: &mut Self::Sl)
Copies from a vector to another vector.
x
is a slice to copy.y
is a slice being copied to.x
andy
shall have the same length.
sourcefn scale(alpha: Self::F, x: &mut Self::Sl)
fn scale(alpha: Self::F, x: &mut Self::Sl)
Calculates \(\alpha x\).
alpha
is a scalar \(\alpha\).x
is a vector \(x\) before entry, \(\alpha x\) on exit.
sourcefn add(alpha: Self::F, x: &Self::Sl, y: &mut Self::Sl)
fn add(alpha: Self::F, x: &Self::Sl, y: &mut Self::Sl)
Calculates \(\alpha x + y\).
alpha
is a scalar \(\alpha\).x
is a vector \(x\).y
is a vector \(y\) before entry, \(\alpha x + y\) on exit.x
andy
shall have the same length.
sourcefn adds(s: Self::F, y: &mut Self::Sl)
fn adds(s: Self::F, y: &mut Self::Sl)
Calculates \(s\mathbb{1} + y\).
s
is a scalar \(s\).y
is a vector \(y\) before entry, \(s\mathbb{1} + y\) on exit.
sourcefn abssum(x: &Self::Sl, incx: usize) -> Self::F
fn abssum(x: &Self::Sl, incx: usize) -> Self::F
Calculates 1-norm (or sum of absolute values) \(\|x\|_1=\sum_i |x_i|\).
Returns the calculated norm.
x
is a vector \(x\).incx
is spacing between elements ofx
sourcefn transform_di(
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
)
fn transform_di(
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
)
Calculates \(\alpha D x + \beta y\), where \(D={\bf diag}(d)\) is a diagonal matrix.
alpha
is a scalar \(\alpha\).mat
is a diagonal vector \(d\) of \(D\).x
is a vector \(x\).beta
is a scalar \(\beta\).y
is a vector \(y\) before entry, \(\alpha D x + \beta y\) on exit.mat
,x
andy
shall have the same length.