clarabel/algebra/dense/
traits.rs

1#![allow(non_snake_case)]
2use crate::algebra::*;
3
4pub(crate) trait FactorEigen<T> {
5    // computes eigenvalues only (full set)
6    fn eigvals<S>(
7        &mut self,
8        A: &mut DenseStorageMatrix<S, T>,
9    ) -> Result<(), DenseFactorizationError>
10    where
11        S: AsMut<[T]> + AsRef<[T]>;
12    // computes eigenvalues and vectors (full set)
13    #[allow(dead_code)] //PJG: implemented for some future projection method
14    fn eigen<S>(&mut self, A: &mut DenseStorageMatrix<S, T>) -> Result<(), DenseFactorizationError>
15    where
16        S: AsMut<[T]> + AsRef<[T]>;
17}
18
19pub(crate) trait FactorCholesky<T> {
20    // computes the Cholesky decomposition.  Only the upper
21    // part of the input A will be referenced. The Cholesky factor
22    // is stored in self.L
23    fn factor<S>(
24        &mut self,
25        A: &mut DenseStorageMatrix<S, T>,
26    ) -> Result<(), DenseFactorizationError>
27    where
28        S: AsMut<[T]> + AsRef<[T]>;
29
30    // Solve AX = B, where B is matrix with (possibly) multiple columns.
31    // Uses previously computed factor from the `factor` function.
32    // B is modified in place and stores X after call.
33    fn solve<S>(&mut self, B: &mut DenseStorageMatrix<S, T>)
34    where
35        S: AsMut<[T]> + AsRef<[T]>;
36
37    // computes log(det(X)) for the matrix X = LL^T
38    fn logdet(&self) -> T;
39}
40
41pub(crate) trait FactorSVD<T> {
42    // compute "economy size" SVD.  Values in A are overwritten
43    // as internal working space.
44    fn factor<S>(
45        &mut self,
46        A: &mut DenseStorageMatrix<S, T>,
47    ) -> Result<(), DenseFactorizationError>
48    where
49        S: AsMut<[T]> + AsRef<[T]>;
50
51    // Solve AX = B, where B is matrix with (possibly) multiple columns.
52    // Uses previously computed SVD factors.   Computes a solution using
53    // the pseudoinverse of A when A is rank deficient / non-square.
54    // B is modified in place and stores X after call.
55    fn solve<S>(&mut self, B: &mut DenseStorageMatrix<S, T>)
56    where
57        S: AsMut<[T]> + AsRef<[T]>;
58}
59
60/// Compute outer product of matrix with itself
61/// and store into the given triangle of the matrix
62pub(crate) trait MultiplySYRK<T> {
63    fn syrk<MATA>(&mut self, A: &MATA, α: T, β: T, uplo: MatrixTriangle)
64    where
65        MATA: DenseMatrix<T>;
66}
67
68pub(crate) trait MultiplySYR2K<T> {
69    fn syr2k<S1, S2>(
70        &mut self,
71        A: &DenseStorageMatrix<S1, T>,
72        B: &DenseStorageMatrix<S2, T>,
73        α: T,
74        β: T,
75    ) where
76        S1: AsRef<[T]>,
77        S2: AsRef<[T]>;
78}
79
80//PJG: problem here since DenseMatrix<T> is implemented by symmetric types,
81//but this should really only be implemented if MATA and MATB are either
82//DenseStorageMatrix or Adjoint<DenseStorageMatrix>.   Possibly solveable
83//by adding a new trait for DenseMatrix that is not implemented by symmetric,
84//something like DenseMaybeAdjointMatrix<T>?
85pub(crate) trait MultiplyGEMM<T> {
86    fn mul<MATA, MATB>(&mut self, A: &MATA, B: &MATB, α: T, β: T) -> &Self
87    where
88        MATB: DenseMatrix<T>,
89        MATA: DenseMatrix<T>;
90}
91
92// Solve AX = B.  A will be corrupted post solution, and B will be
93// overwritten with the solution X.
94#[allow(dead_code)] //PJG: not currently used anywhere
95pub(crate) trait SolveLU<T> {
96    fn lusolve(
97        &mut self,
98        A: &mut Matrix<T>,
99        B: &mut Matrix<T>,
100    ) -> Result<(), DenseFactorizationError>;
101}
102
103#[allow(dead_code)] //PJG: not currently used anywhere
104pub(crate) trait MultiplyGEMV<T> {
105    fn gemv(&self, x: &[T], y: &mut [T], α: T, β: T);
106}
107
108#[allow(dead_code)] //PJG: not currently used anywhere
109pub(crate) trait MultiplySYMV {
110    type T;
111    fn symv(&self, x: &[Self::T], y: &mut [Self::T], α: Self::T, β: Self::T);
112}