pub trait TypedTensorLinalgExt<T: LinalgScalar> {
Show 22 methods
// Required methods
fn svd(&self, session: &mut dyn BackendSession) -> Result<TypedSvd<T>>;
fn svdvals(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<<T as TensorScalar>::Real>>;
fn svd_with_options(
&self,
options: SvdOptions,
session: &mut dyn BackendSession,
) -> Result<TypedSvd<T>>;
fn qr(
&self,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<T>, TypedTensor<T>)>;
fn qr_with_options(
&self,
options: QrOptions,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<T>, TypedTensor<T>)>;
fn lu(&self, session: &mut dyn BackendSession) -> Result<TypedLu<T>>;
fn full_piv_lu(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedFullPivLu<T>>;
fn full_piv_lu_solve(
&self,
b: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>;
fn solve(
&self,
b: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>;
fn cholesky(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>;
fn eigh(
&self,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>;
fn eigh_with_options(
&self,
options: EighOptions,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>;
fn eig(&self, session: &mut dyn BackendSession) -> Result<TypedEig<T>>;
fn triangular_solve(
&self,
b: &TypedTensor<T>,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>;
fn slogdet(
&self,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<T>, TypedTensor<<T as TensorScalar>::Real>)>;
fn det(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>;
fn inv(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>;
fn eigvalsh(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<<T as TensorScalar>::Real>>;
fn eigvals(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T::Complex>>;
fn pinv(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>;
fn pinv_with_rtol(
&self,
rtol: f64,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>;
fn norm(
&self,
ord: Option<f64>,
dim: Option<&[usize]>,
keepdim: bool,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<<T as TensorScalar>::Real>>;
}Expand description
Linear algebra methods with statically typed inputs and outputs.
Singular values, Hermitian eigenvalues, determinant log-magnitudes, and
norms use T::Real; general eigenvalues and eigenvectors use T::Complex.
§Examples
use tenferro_cpu::CpuBackend;
use tenferro_linalg::TypedTensorLinalgExt;
use tenferro_tensor::{BackendSessionHost, TypedTensor};
let input = TypedTensor::<f64>::from_vec_col_major(
vec![2, 2],
vec![2.0, 0.0, 0.0, 4.0],
)?;
let mut host = CpuBackend::new();
let (_u, singular_values, _vt) = host.with_backend_session(|session| input.svd(session))?;
assert_eq!(singular_values.as_slice()?, &[4.0, 2.0]);Required Methods§
Sourcefn svd(&self, session: &mut dyn BackendSession) -> Result<TypedSvd<T>>
fn svd(&self, session: &mut dyn BackendSession) -> Result<TypedSvd<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let (_u, s, _vt) = host.with_backend_session(|session| a.svd(session))?;
assert_eq!(s.as_slice()?, &[4.0, 2.0]);Sourcefn svdvals(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<<T as TensorScalar>::Real>>
fn svdvals( &self, session: &mut dyn BackendSession, ) -> Result<TypedTensor<<T as TensorScalar>::Real>>
Compute singular values without allocating singular-vector outputs.
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected
backend has no values-only capability.
§Examples
let values = host.with_backend_session(|session| a.svdvals(session))?;
assert_eq!(values.as_slice()?, &[4.0, 2.0]);Sourcefn svd_with_options(
&self,
options: SvdOptions,
session: &mut dyn BackendSession,
) -> Result<TypedSvd<T>>
fn svd_with_options( &self, options: SvdOptions, session: &mut dyn BackendSession, ) -> Result<TypedSvd<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation errors for metadata/options, plus backend or typed-output errors.
§Examples
let (_u, s, _vt) = host.with_backend_session(|session| { a.svd_with_options(SvdOptions::default(), session) })?;
assert_eq!(s.as_slice()?, &[4.0, 2.0]);Sourcefn qr(
&self,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<T>, TypedTensor<T>)>
fn qr( &self, session: &mut dyn BackendSession, ) -> Result<(TypedTensor<T>, TypedTensor<T>)>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let (q, r) = host.with_backend_session(|session| a.qr(session))?;
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(r.shape(), &[2, 2]);Sourcefn qr_with_options(
&self,
options: QrOptions,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<T>, TypedTensor<T>)>
fn qr_with_options( &self, options: QrOptions, session: &mut dyn BackendSession, ) -> Result<(TypedTensor<T>, TypedTensor<T>)>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation errors for metadata/options, plus backend or typed-output errors.
§Examples
let (q, r) = host.with_backend_session(|session| { a.qr_with_options(QrOptions::default(), session) })?;
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(r.shape(), &[2, 2]);Sourcefn lu(&self, session: &mut dyn BackendSession) -> Result<TypedLu<T>>
fn lu(&self, session: &mut dyn BackendSession) -> Result<TypedLu<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let (_p, l, u, _parity) = host.with_backend_session(|session| a.lu(session))?;
assert_eq!(l.shape(), &[2, 2]);
assert_eq!(u.shape(), &[2, 2]);Sourcefn full_piv_lu(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedFullPivLu<T>>
fn full_piv_lu( &self, session: &mut dyn BackendSession, ) -> Result<TypedFullPivLu<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let (p, _l, _u, q, _parity) = host.with_backend_session(|session| a.full_piv_lu(session))?;
assert_eq!(p.shape(), &[2, 2]);
assert_eq!(q.shape(), &[2, 2]);Sourcefn full_piv_lu_solve(
&self,
b: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn full_piv_lu_solve( &self, b: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns incompatible-input validation, backend, singular, or typed-downcast errors.
§Examples
let x = host.with_backend_session(|session| a.full_piv_lu_solve(&b, session))?;
assert_eq!(x.shape(), &[2, 1]);Sourcefn solve(
&self,
b: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn solve( &self, b: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns incompatible-input validation, backend, singular, or typed-downcast errors.
§Examples
let x = host.with_backend_session(|session| a.solve(&b, session))?;
assert_eq!(x.as_slice()?, &[2.0, 2.0]);Sourcefn cholesky(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn cholesky(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns matrix validation, backend, positive-definiteness, or typed-downcast errors.
§Examples
let l = host.with_backend_session(|session| a.cholesky(session))?;
assert_eq!(l.shape(), &[2, 2]);Sourcefn eigh(
&self,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>
fn eigh( &self, session: &mut dyn BackendSession, ) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, convergence, output-contract, or typed-downcast errors.
§Examples
let (values, vectors) = host.with_backend_session(|session| a.eigh(session))?;
assert_eq!(values.as_slice()?, &[1.0, 3.0]);
assert_eq!(vectors.shape(), &[2, 2]);Sourcefn eigh_with_options(
&self,
options: EighOptions,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>
fn eigh_with_options( &self, options: EighOptions, session: &mut dyn BackendSession, ) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation errors for metadata/options, plus backend or typed-output errors.
§Examples
let (values, vectors) = host.with_backend_session(|session| { a.eigh_with_options(EighOptions::default(), session) })?;
assert_eq!(values.shape(), &[2]);
assert_eq!(vectors.shape(), &[2, 2]);Sourcefn eig(&self, session: &mut dyn BackendSession) -> Result<TypedEig<T>>
fn eig(&self, session: &mut dyn BackendSession) -> Result<TypedEig<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, convergence, output-contract, or typed-downcast errors.
§Examples
let (values, vectors) = host.with_backend_session(|session| a.eig(session))?;
assert_eq!(values.shape(), &[2]);
assert_eq!(vectors.shape(), &[2, 2]);Sourcefn triangular_solve(
&self,
b: &TypedTensor<T>,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn triangular_solve( &self, b: &TypedTensor<T>, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns incompatible-input/flag validation, backend, singular, or typed-output errors.
§Examples
let x = host.with_backend_session(|session| { a.triangular_solve(&b, true, false, false, false, session) })?;
assert_eq!(x.shape(), &[2, 1]);Sourcefn slogdet(
&self,
session: &mut dyn BackendSession,
) -> Result<(TypedTensor<T>, TypedTensor<<T as TensorScalar>::Real>)>
fn slogdet( &self, session: &mut dyn BackendSession, ) -> Result<(TypedTensor<T>, TypedTensor<<T as TensorScalar>::Real>)>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let (sign, logabsdet) = host.with_backend_session(|session| a.slogdet(session))?;
assert_eq!(sign.as_slice()?, &[1.0]);
assert_eq!(logabsdet.shape(), &[]);Sourcefn det(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn det(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let determinant = host.with_backend_session(|session| a.det(session))?;
assert!((determinant.as_slice()?[0] - 8.0).abs() < 1.0e-12);Sourcefn inv(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn inv(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, singular-solve, or typed-downcast errors.
§Examples
let inverse = host.with_backend_session(|session| a.inv(session))?;
assert_eq!(inverse.as_slice()?, &[0.5, 0.0, 0.0, 0.25]);Sourcefn eigvalsh(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<<T as TensorScalar>::Real>>
fn eigvalsh( &self, session: &mut dyn BackendSession, ) -> Result<TypedTensor<<T as TensorScalar>::Real>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, convergence, output-contract, or typed-downcast errors.
§Examples
let values = host.with_backend_session(|session| a.eigvalsh(session))?;
assert_eq!(values.as_slice()?, &[1.0, 3.0]);Sourcefn eigvals(
&self,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T::Complex>>
fn eigvals( &self, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T::Complex>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, convergence, output-contract, or typed-downcast errors.
§Examples
let values = host.with_backend_session(|session| a.eigvals(session))?;
assert_eq!(values.shape(), &[2]);Sourcefn pinv(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn pinv(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation, backend, numerical, output-contract, or typed-downcast errors.
§Examples
let pseudoinverse = host.with_backend_session(|session| a.pinv(session))?;
assert_eq!(pseudoinverse.shape(), &[2, 2]);Sourcefn pinv_with_rtol(
&self,
rtol: f64,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn pinv_with_rtol( &self, rtol: f64, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns a validation error for invalid rtol, plus backend or typed-output errors.
§Examples
let pseudoinverse = host.with_backend_session(|session| { a.pinv_with_rtol(1.0e-12, session) })?;
assert_eq!(pseudoinverse.shape(), &[2, 2]);Sourcefn norm(
&self,
ord: Option<f64>,
dim: Option<&[usize]>,
keepdim: bool,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<<T as TensorScalar>::Real>>
fn norm( &self, ord: Option<f64>, dim: Option<&[usize]>, keepdim: bool, session: &mut dyn BackendSession, ) -> Result<TypedTensor<<T as TensorScalar>::Real>>
§Errors
Returns tenferro_tensor::Error::Unsupported when the selected backend does not support the operation.
Returns validation errors for axes/order combinations, backend, or typed-output errors.
§Examples
let frobenius = host.with_backend_session(|session| a.norm(None, None, false, session))?;
assert_eq!(frobenius.shape(), &[]);Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".