Trait totsu_core::LinAlgEx
source · pub trait LinAlgEx: LinAlg + Clone {
fn transform_ge(
transpose: bool,
n_row: usize,
n_col: usize,
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
);
fn transform_sp(
n: usize,
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
);
fn map_eig_worklen(n: usize) -> usize;
fn map_eig<M>(
mat: &mut Self::Sl,
scale_diag: Option<Self::F>,
eps_zero: Self::F,
work: &mut Self::Sl,
map: M
)
where
M: Fn(Self::F) -> Option<Self::F>;
}
Expand description
Linear algebra extended subtrait
Required Methods§
sourcefn transform_ge(
transpose: bool,
n_row: usize,
n_col: usize,
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
)
fn transform_ge(
transpose: bool,
n_row: usize,
n_col: usize,
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
)
Calculates \(\alpha G x + \beta y\).
- If
transpose
istrue
, Calculate \(\alpha G^T x + \beta y\) instead. alpha
is a scalar \(\alpha\).n_row
is a number of rows of \(G\).n_col
is a number of columns of \(G\).mat
is a matrix \(G\), stored in column-major. The length ofmat
shall ben_row * n_col
.x
is a vector \(x\). The length ofx
shall ben_col
(orn_row
iftranspose
istrue
).beta
is a scalar \(\beta\).y
is a vector \(y\) before entry, \(\alpha G x + \beta y\) (or \(\alpha G^T x + \beta y\) iftranspose
istrue
) on exit. The length ofy
shall ben_row
(orn_col
iftranspose
istrue
).
sourcefn transform_sp(
n: usize,
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
)
fn transform_sp(
n: usize,
alpha: Self::F,
mat: &Self::Sl,
x: &Self::Sl,
beta: Self::F,
y: &mut Self::Sl
)
Calculates \(\alpha S x + \beta y\), where \(S\) is a symmetric matrix, supplied in packed form.
n
is a number of rows and columns of \(S\).alpha
is a scalar \(\alpha\).mat
is a matrix \(S\), stored in packed form (the upper-triangular part in column-wise). The length ofmat
shall ben * (n + 1) / 2
.x
is a vector \(x\). The length ofx
shall ben
.beta
is a scalar \(\beta\).y
is a vector \(y\) before entry, \(\alpha S x + \beta y\) on exit. The length ofy
shall ben
.
sourcefn map_eig_worklen(n: usize) -> usize
fn map_eig_worklen(n: usize) -> usize
Query of a length of work slice that LinAlgEx::map_eig
requires.
Returns a length of work slice.
n
is a number of rows and columns of \(S\) (seeLinAlgEx::map_eig
).
sourcefn map_eig<M>(
mat: &mut Self::Sl,
scale_diag: Option<Self::F>,
eps_zero: Self::F,
work: &mut Self::Sl,
map: M
)where
M: Fn(Self::F) -> Option<Self::F>,
fn map_eig<M>(
mat: &mut Self::Sl,
scale_diag: Option<Self::F>,
eps_zero: Self::F,
work: &mut Self::Sl,
map: M
)where
M: Fn(Self::F) -> Option<Self::F>,
Applies a map to eigenvalues of a symmetric matrix \(S\) supplied in packed form.
- (optional) Scales diagonals of a given matrix \(S\).
- Eigenvalue decomposition: \(S \rightarrow V \mathbf{diag}(\lambda) V^T\)
- Applies a map to the eigenvalues: \(\lambda \rightarrow \lambda’\)
- Reconstruct the matrix: \(V \mathbf{diag’}(\lambda) V^T \rightarrow S’\)
- (optional) Inverted scaling to diagonals of \(S’\).
This routine is used for euclidean projection onto semidifinite matrix and taking a square root of the matrix.
mat
is the matrix \(S\) before entry, \(S’\) on exit. It shall be stored in packed form (the upper-triangular part in column-wise).scale_diag
is the optional scaling factor to the diagonals.None
has the same effect asSome(1.0)
but reduces computation.eps_zero
should be the same value ascrate::solver::SolverParam::eps_zero
.work
slice is used for temporal variables.map
takes an eigenvalue and returns a modified eigenvalue. ReturningNone
has the same effect as no-modification but reduces computation.