pub trait LinalgBackend: TensorBackend {
Show 20 methods
// Required methods
fn cholesky(&mut self, input: &Tensor) -> Result<Tensor>;
fn triangular_solve(
&mut self,
a: &Tensor,
b: &Tensor,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
) -> Result<Tensor>;
fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn full_piv_lu_solve(
&mut self,
a: &Tensor,
b: &Tensor,
transpose_a: bool,
) -> Result<Tensor>;
fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>>;
fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor>;
// Provided methods
fn svd_with_options(
&mut self,
input: &Tensor,
options: SvdOptions,
) -> Result<Vec<Tensor>> { ... }
fn svd_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>> { ... }
fn qr_with_options(
&mut self,
input: &Tensor,
options: QrOptions,
) -> Result<Vec<Tensor>> { ... }
fn qr_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>> { ... }
fn eigh_with_options(
&mut self,
input: &Tensor,
options: EighOptions,
) -> Result<Vec<Tensor>> { ... }
fn eigh_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>> { ... }
fn cholesky_read(&mut self, _input: TensorView<'_>) -> Result<Tensor> { ... }
fn lu_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>> { ... }
fn full_piv_lu_read(
&mut self,
_input: TensorView<'_>,
) -> Result<Vec<Tensor>> { ... }
fn eig_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>> { ... }
}Expand description
Backend surface required by the linalg extension runtime.
§Examples
use tenferro_linalg::backend::LinalgBackend;
use tenferro_cpu::CpuBackend;
fn accepts_linalg_backend<B: LinalgBackend>(_backend: &mut B) {}
let mut backend = CpuBackend::new();
accepts_linalg_backend(&mut backend);Required Methods§
Sourcefn triangular_solve(
&mut self,
a: &Tensor,
b: &Tensor,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
) -> Result<Tensor>
fn triangular_solve( &mut self, a: &Tensor, b: &Tensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<Tensor>
Solve a triangular linear system with explicit side, triangle, transpose, and unit-diagonal flags.
Sourcefn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public LU outputs (P, L, U, parity).
Sourcefn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute complete-pivot LU outputs (P, L, U, Q, parity).
The reconstruction convention is A = P^T * L * U * Q, equivalently
P * A * Q^T = L * U. parity is a scalar real tensor containing
+1 or -1: F32 for F32/C32 inputs and F64 for F64/C64
inputs.
Sourcefn full_piv_lu_solve(
&mut self,
a: &Tensor,
b: &Tensor,
transpose_a: bool,
) -> Result<Tensor>
fn full_piv_lu_solve( &mut self, a: &Tensor, b: &Tensor, transpose_a: bool, ) -> Result<Tensor>
Solve a linear system through the complete-pivot LU path.
With transpose_a = false, this solves A * x = b. With
transpose_a = true, this solves A^T * x = b.
Sourcefn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public SVD outputs (U, S, Vt).
Sourcefn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public QR outputs (Q, R).
QR is thin: for an m x n input, Q has shape m x min(m, n) and
R has shape min(m, n) x n.
Sourcefn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>
Compute public Hermitian eigendecomposition outputs (values, vectors).
The returned vector order is [values, vectors], where values has
shape [n] and vectors has shape [n, n].
Provided Methods§
Sourcefn svd_with_options(
&mut self,
input: &Tensor,
options: SvdOptions,
) -> Result<Vec<Tensor>>
fn svd_with_options( &mut self, input: &Tensor, options: SvdOptions, ) -> Result<Vec<Tensor>>
Compute public SVD outputs (U, S, Vt) with explicit options.
derivative_eps is validated for API consistency, but concrete backend
execution does not perform AD. gauge controls optional singular-vector
post-processing.
§Examples
use tenferro_cpu::CpuBackend;
use tenferro_linalg::{LinalgBackend, SvdGauge, SvdOptions};
use tenferro_tensor::Tensor;
let input = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 2.0])?;
let mut backend = CpuBackend::new();
let outputs = backend.svd_with_options(
&input,
SvdOptions::default().gauge(SvdGauge::CanonicalPivot),
)?;
assert_eq!(outputs[1].shape(), &[2]);Sourcefn svd_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
fn svd_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
Compute a singular value decomposition from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 0.0, 0.0, 2.0],
)?;
let mut backend = CpuBackend::new();
let outputs = backend.svd_read(TensorView::F64(input.as_view()))?;
assert_eq!(outputs[1].shape(), &[2]);Sourcefn qr_with_options(
&mut self,
input: &Tensor,
options: QrOptions,
) -> Result<Vec<Tensor>>
fn qr_with_options( &mut self, input: &Tensor, options: QrOptions, ) -> Result<Vec<Tensor>>
Compute public QR outputs (Q, R) with explicit options.
gauge controls optional sign or phase post-processing.
§Examples
use tenferro_cpu::CpuBackend;
use tenferro_linalg::{LinalgBackend, QrGauge, QrOptions};
use tenferro_tensor::Tensor;
let input = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 2.0])?;
let mut backend = CpuBackend::new();
let outputs = backend.qr_with_options(
&input,
QrOptions::default().gauge(QrGauge::PositiveDiagonal),
)?;
assert_eq!(outputs[0].shape(), &[2, 2]);Sourcefn qr_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
fn qr_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
Compute public QR outputs (Q, R) from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 0.0, 0.0, 2.0],
)?;
let mut backend = CpuBackend::new();
let outputs = backend.qr_read(TensorView::F64(input.as_view()))?;
assert_eq!(outputs[0].shape(), &[2, 2]);
assert_eq!(outputs[1].shape(), &[2, 2]);Sourcefn eigh_with_options(
&mut self,
input: &Tensor,
options: EighOptions,
) -> Result<Vec<Tensor>>
fn eigh_with_options( &mut self, input: &Tensor, options: EighOptions, ) -> Result<Vec<Tensor>>
Compute public Hermitian eigendecomposition outputs with explicit options.
derivative_eps is validated for API consistency, but concrete backend
execution does not perform AD. gauge controls optional eigenvector
post-processing.
§Examples
use tenferro_cpu::CpuBackend;
use tenferro_linalg::{EighGauge, EighOptions, LinalgBackend};
use tenferro_tensor::Tensor;
let input = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 2.0])?;
let mut backend = CpuBackend::new();
let outputs = backend.eigh_with_options(
&input,
EighOptions::default()
.gauge(EighGauge::CanonicalPivot)
.derivative_eps(1.0e-10),
)?;
assert_eq!(outputs[0].shape(), &[2]);Sourcefn eigh_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
fn eigh_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
Compute public Hermitian eigendecomposition outputs from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 0.0, 0.0, 2.0],
)?;
let mut backend = CpuBackend::new();
let outputs = backend.eigh_read(TensorView::F64(input.as_view()))?;
assert_eq!(outputs[0].shape(), &[2]);
assert_eq!(outputs[1].shape(), &[2, 2]);Sourcefn cholesky_read(&mut self, _input: TensorView<'_>) -> Result<Tensor>
fn cholesky_read(&mut self, _input: TensorView<'_>) -> Result<Tensor>
Compute Cholesky factorization from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![4.0, 2.0, 2.0, 3.0],
)?;
let mut backend = CpuBackend::new();
let output = backend.cholesky_read(TensorView::F64(input.as_view()))?;
assert_eq!(output.shape(), &[2, 2]);Sourcefn lu_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
fn lu_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
Compute public LU outputs from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 3.0, 2.0, 4.0],
)?;
let mut backend = CpuBackend::new();
let outputs = backend.lu_read(TensorView::F64(input.as_view()))?;
assert_eq!(outputs.len(), 4);Sourcefn full_piv_lu_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
fn full_piv_lu_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
Compute public full-pivoting LU outputs from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![1.0, 3.0, 2.0, 4.0],
)?;
let mut backend = CpuBackend::new();
let outputs = backend.full_piv_lu_read(TensorView::F64(input.as_view()))?;
assert_eq!(outputs.len(), 5);Sourcefn eig_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
fn eig_read(&mut self, _input: TensorView<'_>) -> Result<Vec<Tensor>>
Compute general eigendecomposition outputs from a borrowed tensor view.
Backends may canonicalize the view inside the same placement family, but must not silently transfer between CPU and GPU memory.
§Examples
use tenferro_linalg::LinalgBackend;
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{TensorView, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![2.0, 0.0, 0.0, 3.0],
)?;
let mut backend = CpuBackend::new();
let outputs = backend.eig_read(TensorView::F64(input.as_view()))?;
assert_eq!(outputs.len(), 2);