Skip to main content

TypedTensorLinalgExt

Trait TypedTensorLinalgExt 

Source
pub trait TypedTensorLinalgExt<T: LinalgScalar> {
Show 24 methods // Required methods fn svd(&self, session: &mut dyn Engine) -> Result<TypedSvd<T>>; fn svdvals( &self, session: &mut dyn Engine, ) -> Result<TypedTensor<<T as TensorScalar>::Real>>; fn svd_with_options( &self, options: SvdOptions, session: &mut dyn Engine, ) -> Result<TypedSvd<T>>; fn svd_full(&self, session: &mut dyn Engine) -> Result<TypedSvd<T>>; fn qr( &self, session: &mut dyn Engine, ) -> Result<(TypedTensor<T>, TypedTensor<T>)>; fn qr_with_options( &self, options: QrOptions, session: &mut dyn Engine, ) -> Result<(TypedTensor<T>, TypedTensor<T>)>; fn rank_revealing_qr( &self, options: RankRevealingQrOptions, session: &mut dyn Engine, ) -> Result<TypedRankRevealingQrResult<T>>; fn lu(&self, session: &mut dyn Engine) -> Result<TypedLu<T>>; fn full_piv_lu(&self, session: &mut dyn Engine) -> Result<TypedFullPivLu<T>>; fn full_piv_lu_solve( &self, b: &TypedTensor<T>, session: &mut dyn Engine, ) -> Result<TypedTensor<T>>; fn solve( &self, b: &TypedTensor<T>, session: &mut dyn Engine, ) -> Result<TypedTensor<T>>; fn cholesky(&self, session: &mut dyn Engine) -> Result<TypedTensor<T>>; fn eigh( &self, session: &mut dyn Engine, ) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>; fn eigh_with_options( &self, options: EighOptions, session: &mut dyn Engine, ) -> Result<(TypedTensor<<T as TensorScalar>::Real>, TypedTensor<T>)>; fn eig(&self, session: &mut dyn Engine) -> Result<TypedEig<T>>; fn triangular_solve( &self, b: &TypedTensor<T>, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, session: &mut dyn Engine, ) -> Result<TypedTensor<T>>; fn slogdet( &self, session: &mut dyn Engine, ) -> Result<(TypedTensor<T>, TypedTensor<<T as TensorScalar>::Real>)>; fn det(&self, session: &mut dyn Engine) -> Result<TypedTensor<T>>; fn inv(&self, session: &mut dyn Engine) -> Result<TypedTensor<T>>; fn eigvalsh( &self, session: &mut dyn Engine, ) -> Result<TypedTensor<<T as TensorScalar>::Real>>; fn eigvals( &self, session: &mut dyn Engine, ) -> Result<TypedTensor<T::Complex>>; fn pinv(&self, session: &mut dyn Engine) -> Result<TypedTensor<T>>; fn pinv_with_rtol( &self, rtol: f64, session: &mut dyn Engine, ) -> Result<TypedTensor<T>>; fn norm( &self, ord: Option<f64>, dim: Option<&[usize]>, keepdim: bool, session: &mut dyn Engine, ) -> 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::CpuEngine;
use tenferro_linalg::TypedTensorLinalgExt;
use tenferro_tensor::TypedTensor;

let input = TypedTensor::<f64>::from_vec_col_major(
    vec![2, 2],
    vec![2.0, 0.0, 0.0, 4.0],
)?;
let mut host = tenferro_cpu::CpuEngine::serial();
let (_u, singular_values, _vt) = input.svd(&mut host)?;
assert_eq!(singular_values.as_slice()?, &[4.0, 2.0]);

Required Methods§

Source

fn svd(&self, session: &mut dyn Engine) -> 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) = a.svd(&mut host)?;
assert_eq!(s.as_slice()?, &[4.0, 2.0]);
Source

fn svdvals( &self, session: &mut dyn Engine, ) -> 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 = a.svdvals(&mut host)?;
assert_eq!(values.as_slice()?, &[4.0, 2.0]);
Source

fn svd_with_options( &self, options: SvdOptions, session: &mut dyn Engine, ) -> 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) = { a.svd_with_options(SvdOptions::default(), &mut host) }?;
assert_eq!(s.as_slice()?, &[4.0, 2.0]);
Source

fn svd_full(&self, session: &mut dyn Engine) -> Result<TypedSvd<T>>

Compute the full-matrices SVD (U, S, Vt) with U shaped m x m and Vt shaped n x n. The singular values keep the real counterpart dtype of T, exactly as TypedTensorLinalgExt::svd does.

§Errors

Returns tenferro_tensor::Error::Unsupported when the selected backend or CPU provider has no full-matrices kernel. Returns validation errors for an unsupported rank or dtype, plus backend, numerical, output-contract, or typed-downcast errors.

§Examples
let (u, s, vt) = a.svd_full(&mut host)?;
assert_eq!(u.shape(), &[1, 1]);
assert_eq!(vt.shape(), &[2, 2]);
assert!((s.as_slice()?[0] - 2.0_f64.sqrt()).abs() < 1e-12);
Source

fn qr( &self, session: &mut dyn Engine, ) -> 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) = a.qr(&mut host)?;
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(r.shape(), &[2, 2]);
Source

fn qr_with_options( &self, options: QrOptions, session: &mut dyn Engine, ) -> 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) = { a.qr_with_options(QrOptions::default(), &mut host) }?;
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(r.shape(), &[2, 2]);
Source

fn rank_revealing_qr( &self, options: RankRevealingQrOptions, session: &mut dyn Engine, ) -> Result<TypedRankRevealingQrResult<T>>

Compute typed rank-revealing QR with i64 permutation and rank tensors.

§Errors

Returns validation, numerical, backend, unsupported, or typed-output contract errors.

§Examples
let result = {
    a.rank_revealing_qr(RankRevealingQrOptions::default(), &mut host)
}?;
assert_eq!(result.rank.as_slice()?, &[2_i64]);
Source

fn lu(&self, session: &mut dyn Engine) -> 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) = a.lu(&mut host)?;
assert_eq!(l.shape(), &[2, 2]);
assert_eq!(u.shape(), &[2, 2]);
Source

fn full_piv_lu(&self, session: &mut dyn Engine) -> 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) = a.full_piv_lu(&mut host)?;
assert_eq!(p.shape(), &[2, 2]);
assert_eq!(q.shape(), &[2, 2]);
Source

fn full_piv_lu_solve( &self, b: &TypedTensor<T>, session: &mut dyn Engine, ) -> 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 = a.full_piv_lu_solve(&b, &mut host)?;
assert_eq!(x.shape(), &[2, 1]);
Source

fn solve( &self, b: &TypedTensor<T>, session: &mut dyn Engine, ) -> Result<TypedTensor<T>>

The CUDA provider does not inspect the cuSOLVER getrf status flag on the forward solve path, so it performs no per-call non-singularity check and issues no host round trip. An exactly singular input is left to the caller’s verification, as in torch.linalg.solve. CPU providers may still report their own exactly singular factor as Error::Singular.

§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 = a.solve(&b, &mut host)?;
assert_eq!(x.as_slice()?, &[2.0, 2.0]);
Source

fn cholesky(&self, session: &mut dyn Engine) -> 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 = a.cholesky(&mut host)?;
assert_eq!(l.shape(), &[2, 2]);
Source

fn eigh( &self, session: &mut dyn Engine, ) -> 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) = a.eigh(&mut host)?;
assert_eq!(values.as_slice()?, &[1.0, 3.0]);
assert_eq!(vectors.shape(), &[2, 2]);
Source

fn eigh_with_options( &self, options: EighOptions, session: &mut dyn Engine, ) -> 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) = { a.eigh_with_options(EighOptions::default(), &mut host) }?;
assert_eq!(values.shape(), &[2]);
assert_eq!(vectors.shape(), &[2, 2]);
Source

fn eig(&self, session: &mut dyn Engine) -> 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) = a.eig(&mut host)?;
assert_eq!(values.shape(), &[2]);
assert_eq!(vectors.shape(), &[2, 2]);

Eigenvectors come back with unit 2-norm columns, whichever provider computed them; a column the provider left non-finite is reported as a numerical failure instead of being returned as NaN (#2148).

Source

fn triangular_solve( &self, b: &TypedTensor<T>, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, session: &mut dyn Engine, ) -> 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 = { a.triangular_solve(&b, true, false, false, false, &mut host) }?;
assert_eq!(x.shape(), &[2, 1]);
Source

fn slogdet( &self, session: &mut dyn Engine, ) -> 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) = a.slogdet(&mut host)?;
assert_eq!(sign.as_slice()?, &[1.0]);
assert_eq!(logabsdet.shape(), &[] as &[usize]);
Source

fn det(&self, session: &mut dyn Engine) -> 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 = a.det(&mut host)?;
assert!((determinant.as_slice()?[0] - 8.0).abs() < 1.0e-12);
Source

fn inv(&self, session: &mut dyn Engine) -> 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 = a.inv(&mut host)?;
assert_eq!(inverse.as_slice()?, &[0.5, 0.0, 0.0, 0.25]);
Source

fn eigvalsh( &self, session: &mut dyn Engine, ) -> 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 = a.eigvalsh(&mut host)?;
assert_eq!(values.as_slice()?, &[1.0, 3.0]);
Source

fn eigvals(&self, session: &mut dyn Engine) -> 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 = a.eigvals(&mut host)?;
assert_eq!(values.shape(), &[2]);
Source

fn pinv(&self, session: &mut dyn Engine) -> 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 = a.pinv(&mut host)?;
assert_eq!(pseudoinverse.shape(), &[2, 2]);
Source

fn pinv_with_rtol( &self, rtol: f64, session: &mut dyn Engine, ) -> 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 = { a.pinv_with_rtol(1.0e-12, &mut host) }?;
assert_eq!(pseudoinverse.shape(), &[2, 2]);
Source

fn norm( &self, ord: Option<f64>, dim: Option<&[usize]>, keepdim: bool, session: &mut dyn Engine, ) -> 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 = a.norm(None, None, false, &mut host)?;
assert_eq!(frobenius.shape(), &[] as &[usize]);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§