pub trait LinalgBackend<T: Copy + 'static> {
type Real: Copy + 'static;
// Required methods
fn thin_svd(
&mut self,
a: &[T],
m: usize,
n: usize,
u: &mut [T],
s: &mut [Self::Real],
vt: &mut [T],
) -> Result<()>;
fn qr(
&mut self,
a: &[T],
m: usize,
n: usize,
q: &mut [T],
r: &mut [T],
) -> Result<()>;
fn lu(
&mut self,
a: &[T],
m: usize,
n: usize,
perm: &mut [usize],
l: &mut [T],
u_out: &mut [T],
) -> Result<()>;
fn cholesky(&mut self, a: &[T], n: usize, l: &mut [T]) -> Result<()>;
fn eigen_sym(
&mut self,
a: &[T],
n: usize,
values: &mut [Self::Real],
vectors: &mut [T],
) -> Result<()>;
fn mat_mul(
&mut self,
a: &[T],
m: usize,
k: usize,
b: &[T],
n: usize,
c: &mut [T],
) -> Result<()>;
fn solve(
&mut self,
a: &[T],
b: &[T],
n: usize,
nrhs: usize,
x: &mut [T],
) -> Result<()>;
fn solve_triangular(
&mut self,
a: &[T],
b: &[T],
n: usize,
nrhs: usize,
upper: bool,
x: &mut [T],
) -> Result<()>;
fn eig_general(
&mut self,
a: &[T],
n: usize,
values_ri: &mut [T],
vectors_ri: &mut [T],
) -> Result<()>;
}Expand description
Slice-level backend interface for matrix linear algebra operations.
All input/output slices use column-major layout. The trait is
parameterized by scalar type T (e.g., f64, f32).
Implementations take &mut self to allow internal workspace reuse.
This trait is used internally by CPU provider implementations.
The public API boundary is TensorLinalgBackend.
§Examples
use tenferro_linalg::backend::LinalgBackend;
fn do_svd<B: LinalgBackend<f64, Real = f64>>(backend: &mut B) {
let a = [1.0, 0.0, 0.0, 1.0]; // 2x2 identity
let mut u = [0.0; 4];
let mut s = [0.0; 2];
let mut vt = [0.0; 4];
backend.thin_svd(&a, 2, 2, &mut u, &mut s, &mut vt).unwrap();
}Required Associated Types§
Required Methods§
Sourcefn thin_svd(
&mut self,
a: &[T],
m: usize,
n: usize,
u: &mut [T],
s: &mut [Self::Real],
vt: &mut [T],
) -> Result<()>
fn thin_svd( &mut self, a: &[T], m: usize, n: usize, u: &mut [T], s: &mut [Self::Real], vt: &mut [T], ) -> Result<()>
Thin SVD: A = U diag(S) Vt.
Sourcefn qr(
&mut self,
a: &[T],
m: usize,
n: usize,
q: &mut [T],
r: &mut [T],
) -> Result<()>
fn qr( &mut self, a: &[T], m: usize, n: usize, q: &mut [T], r: &mut [T], ) -> Result<()>
Thin QR decomposition: A = Q R.
Sourcefn lu(
&mut self,
a: &[T],
m: usize,
n: usize,
perm: &mut [usize],
l: &mut [T],
u_out: &mut [T],
) -> Result<()>
fn lu( &mut self, a: &[T], m: usize, n: usize, perm: &mut [usize], l: &mut [T], u_out: &mut [T], ) -> Result<()>
LU decomposition with partial pivoting: P A = L U.
Sourcefn cholesky(&mut self, a: &[T], n: usize, l: &mut [T]) -> Result<()>
fn cholesky(&mut self, a: &[T], n: usize, l: &mut [T]) -> Result<()>
Cholesky decomposition: A = L L^H.
Sourcefn eigen_sym(
&mut self,
a: &[T],
n: usize,
values: &mut [Self::Real],
vectors: &mut [T],
) -> Result<()>
fn eigen_sym( &mut self, a: &[T], n: usize, values: &mut [Self::Real], vectors: &mut [T], ) -> Result<()>
Symmetric eigendecomposition: A = V diag(lambda) V^H.
Sourcefn mat_mul(
&mut self,
a: &[T],
m: usize,
k: usize,
b: &[T],
n: usize,
c: &mut [T],
) -> Result<()>
fn mat_mul( &mut self, a: &[T], m: usize, k: usize, b: &[T], n: usize, c: &mut [T], ) -> Result<()>
Matrix multiplication: C = A * B.
Sourcefn solve(
&mut self,
a: &[T],
b: &[T],
n: usize,
nrhs: usize,
x: &mut [T],
) -> Result<()>
fn solve( &mut self, a: &[T], b: &[T], n: usize, nrhs: usize, x: &mut [T], ) -> Result<()>
Solve linear system: A x = b.
Sourcefn solve_triangular(
&mut self,
a: &[T],
b: &[T],
n: usize,
nrhs: usize,
upper: bool,
x: &mut [T],
) -> Result<()>
fn solve_triangular( &mut self, a: &[T], b: &[T], n: usize, nrhs: usize, upper: bool, x: &mut [T], ) -> Result<()>
Solve triangular system: A x = b.
Sourcefn eig_general(
&mut self,
a: &[T],
n: usize,
values_ri: &mut [T],
vectors_ri: &mut [T],
) -> Result<()>
fn eig_general( &mut self, a: &[T], n: usize, values_ri: &mut [T], vectors_ri: &mut [T], ) -> Result<()>
General eigendecomposition: A V = V diag(lambda).
For real T: output uses interleaved re/im pairs (2*n values, 2*n*n vectors).
For complex T: output uses direct complex elements (n values, n*n vectors).