Skip to main content

EagerTensorLinalgExt

Trait EagerTensorLinalgExt 

Source
pub trait EagerTensorLinalgExt {
Show 23 methods // Required methods fn svd(&self) -> Result<(EagerTensor, EagerTensor, EagerTensor)>; fn svd_with_options( &self, options: SvdOptions, ) -> Result<(EagerTensor, EagerTensor, EagerTensor)>; fn svd_full(&self) -> Result<(EagerTensor, EagerTensor, EagerTensor)>; fn qr(&self) -> Result<(EagerTensor, EagerTensor)>; fn qr_with_options( &self, options: QrOptions, ) -> Result<(EagerTensor, EagerTensor)>; fn lu(&self) -> Result<(EagerTensor, EagerTensor, EagerTensor, EagerTensor)>; fn full_piv_lu( &self, ) -> Result<(EagerTensor, EagerTensor, EagerTensor, EagerTensor, EagerTensor)>; fn full_piv_lu_solve(&self, b: &EagerTensor) -> Result<EagerTensor>; fn solve(&self, b: &EagerTensor) -> Result<EagerTensor>; fn lstsq(&self, b: &EagerTensor) -> Result<EagerTensor>; fn cholesky(&self) -> Result<EagerTensor>; fn eigh(&self) -> Result<(EagerTensor, EagerTensor)>; fn eigh_with_options( &self, options: EighOptions, ) -> Result<(EagerTensor, EagerTensor)>; fn eig(&self) -> Result<(EagerTensor, EagerTensor)>; fn triangular_solve( &self, b: &EagerTensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<EagerTensor>; fn slogdet(&self) -> Result<(EagerTensor, EagerTensor)>; fn det(&self) -> Result<EagerTensor>; fn inv(&self) -> Result<EagerTensor>; fn eigvalsh(&self) -> Result<EagerTensor>; fn eigvals(&self) -> Result<EagerTensor>; fn pinv(&self) -> Result<EagerTensor>; fn pinv_with_rtol(&self, rtol: f64) -> Result<EagerTensor>; fn norm( &self, ord: Option<f64>, dim: Option<&[usize]>, keepdim: bool, ) -> Result<EagerTensor>;
}
Expand description

Linear algebra extension methods for EagerTensor.

Required Methods§

Source

fn svd(&self) -> Result<(EagerTensor, EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for an invalid rank, shape, or dtype, Error::Extension with an unsupported-operation or unsupported-dtype source when the selected backend cannot execute the decomposition, and Error::RuntimeState when the eager runtime or backend is unavailable.

§Examples
let (_u, s, _vt) = a.svd()?;
assert_eq!(s.shape(), &[2]);
Source

fn svd_with_options( &self, options: SvdOptions, ) -> Result<(EagerTensor, EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation when derivative_eps is non-finite or non-positive, Error::Extension for unsupported dtypes or numerical non-convergence, and Error::Internal if the extension violates its output-count contract.

§Examples
let (_u, s, _vt) = a.svd_with_options(SvdOptions::default())?;
assert_eq!(s.shape(), &[2]);
Source

fn svd_full(&self) -> Result<(EagerTensor, EagerTensor, EagerTensor)>

Full-matrices SVD returning square U (m x m) and Vh (n x n), whose trailing n - rank rows span the input’s right nullspace.

§Errors

Returns Error::Validation for an invalid rank, and Error::Extension with an unsupported-operation source when the active backend does not implement full-matrices SVD (the CPU faer provider supports it; the LAPACK provider and GPU backends return an unsupported error in this slice). Automatic differentiation through the full variant is unsupported and surfaces a typed error rather than a silent thin fallback.

§Examples
let (u, s, vh) = a.svd_full()?;
assert_eq!(u.shape(), &[1, 1]);
assert_eq!(s.shape(), &[1]);
assert_eq!(vh.shape(), &[2, 2]);
let singular_values = s.value()?.as_slice::<f64>()?;
assert!((singular_values[0] - 2.0_f64.sqrt()).abs() < 1e-12);
Source

fn qr(&self) -> Result<(EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for invalid matrix rank or shape, Error::Extension for unsupported dtypes or numerical failure, and Error::RuntimeState when the eager runtime or backend is unavailable.

§Examples
let (q, r) = a.qr()?;
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(r.shape(), &[2, 2]);
Source

fn qr_with_options( &self, options: QrOptions, ) -> Result<(EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for invalid matrix rank or shape, Error::Extension for unsupported dtypes or numerical failure, and Error::Internal if the extension violates its output-count contract.

§Examples
let (q, r) = a.qr_with_options(QrOptions::default())?;
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(r.shape(), &[2, 2]);
Source

fn lu(&self) -> Result<(EagerTensor, EagerTensor, EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for an invalid matrix rank or shape, Error::Extension for an unsupported dtype or singular numerical result, and Error::RuntimeState when execution cannot access its backend.

§Examples
let (_p, l, u, parity) = a.lu()?;
assert_eq!(l.shape(), &[2, 2]);
assert_eq!(u.shape(), &[2, 2]);
assert_eq!(parity.shape(), &[]);
Source

fn full_piv_lu( &self, ) -> Result<(EagerTensor, EagerTensor, EagerTensor, EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for an invalid matrix rank or shape, Error::Extension for unsupported dtypes or singular numerical results, and Error::Internal if the extension violates its output contract.

§Examples
let (p, _l, _u, q, parity) = a.full_piv_lu()?;
assert_eq!(p.shape(), &[2, 2]);
assert_eq!(q.shape(), &[2, 2]);
assert_eq!(parity.shape(), &[]);
Source

fn full_piv_lu_solve(&self, b: &EagerTensor) -> Result<EagerTensor>

§Errors

Returns Error::Validation when a and b have incompatible matrix or batch shapes, Error::Extension for an unsupported dtype or singular system, and Error::RuntimeState when the backend is unavailable.

§Examples
let x = a.full_piv_lu_solve(&b)?;
assert_eq!(x.shape(), &[2, 1]);
Source

fn solve(&self, b: &EagerTensor) -> Result<EagerTensor>

§Errors

Returns Error::Validation for incompatible matrix, batch, or dtype metadata, Error::Extension for an unsupported dtype or singular system, and Error::RuntimeState when the backend is unavailable.

§Examples
let x = a.solve(&b)?;
assert_eq!(x.value()?.as_slice::<f64>()?, &[2.0, 2.0]);
Source

fn lstsq(&self, b: &EagerTensor) -> Result<EagerTensor>

Least-squares solve argmin_x ||A x - b||_2 for a tall or square, full-column-rank A, via the thin QR factorization.

§Errors

Returns Error::Validation when A or b is not a matrix (rank >= 2), when A is wide (rows < cols; underdetermined), or when the dtype is not floating-point or complex; Error::Extension for backend QR or triangular-solve failures; and Error::RuntimeState when the backend is unavailable. Rank-deficient A is not detected and yields an ill-defined result.

§Examples
let x = a.lstsq(&b)?;
assert_eq!(x.shape(), &[2, 1]);
let values = x.value()?.as_slice::<f64>()?;
assert!((values[0] - 1.0_f64).abs() < 1e-12);
assert!((values[1] - 2.0_f64).abs() < 1e-12);
Source

fn cholesky(&self) -> Result<EagerTensor>

§Errors

Returns Error::Validation for a non-square or invalid-rank input, Error::Extension for unsupported dtypes or a non-positive-definite matrix, and Error::RuntimeState when the backend is unavailable.

§Examples
let l = a.cholesky()?;
assert_eq!(l.shape(), &[2, 2]);
Source

fn eigh(&self) -> Result<(EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for a non-square or invalid-rank input, Error::Extension for unsupported dtypes or numerical non-convergence, and Error::RuntimeState when the backend is unavailable.

§Examples
let (values, vectors) = a.eigh()?;
assert_eq!(values.value()?.as_slice::<f64>()?, &[1.0, 3.0]);
assert_eq!(vectors.shape(), &[2, 2]);
Source

fn eigh_with_options( &self, options: EighOptions, ) -> Result<(EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for an invalid rank, shape, or derivative_eps, Error::Extension for unsupported dtypes or non-convergence, and Error::Internal for an output-count violation.

§Examples
let (values, vectors) = a.eigh_with_options(EighOptions::default())?;
assert_eq!(values.shape(), &[2]);
assert_eq!(vectors.shape(), &[2, 2]);
Source

fn eig(&self) -> Result<(EagerTensor, EagerTensor)>

§Errors

Returns Error::Validation for a non-square or invalid-rank input, Error::Extension for unsupported dtypes or numerical non-convergence, and Error::RuntimeState when the backend is unavailable.

§Examples
let (values, vectors) = a.eig()?;
assert_eq!(values.shape(), &[2]);
assert_eq!(vectors.shape(), &[2, 2]);
Source

fn triangular_solve( &self, b: &EagerTensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<EagerTensor>

§Errors

Returns Error::Validation for incompatible matrix, batch, or dtype metadata, Error::Extension for unsupported dtypes or a singular system, and Error::RuntimeState when the backend is unavailable.

§Examples
let x = a.triangular_solve(&b, true, false, false, false)?;
assert_eq!(x.shape(), &[2, 1]);
Source

fn slogdet(&self) -> Result<(EagerTensor, EagerTensor)>

Return the determinant sign and logarithm of its absolute value.

§Errors

Returns Error::Validation for a non-square input, Error::Extension for an unsupported dtype or numerical failure, and Error::Internal if a primitive violates its output contract.

§Examples
let (sign, logabsdet) = a.slogdet()?;
assert_eq!(sign.value()?.as_slice::<f64>()?, &[1.0]);
assert_eq!(logabsdet.shape(), &[]);
Source

fn det(&self) -> Result<EagerTensor>

Return the determinant.

§Errors

Returns Error::Validation, Error::Extension, Error::RuntimeState, or Error::Internal under the conditions documented by Self::slogdet.

§Examples
let determinant = a.det()?;
assert!((determinant.value()?.as_slice::<f64>()?[0] - 8.0).abs() < 1.0e-12);
Source

fn inv(&self) -> Result<EagerTensor>

Return the matrix inverse.

§Errors

Returns Error::Validation for invalid matrix metadata, Error::Extension for an unsupported dtype or singular solve, and Error::RuntimeState when eager execution cannot access its backend.

§Examples
let inverse = a.inv()?;
assert_eq!(inverse.value()?.as_slice::<f64>()?, &[0.5, 0.0, 0.0, 0.25]);
Source

fn eigvalsh(&self) -> Result<EagerTensor>

Return Hermitian eigenvalues without eigenvectors.

§Errors

Returns the validation, unsupported-dtype, numerical-convergence, runtime-state, or output-contract errors reported by Self::eigh.

§Examples
let values = a.eigvalsh()?;
assert_eq!(values.value()?.as_slice::<f64>()?, &[1.0, 3.0]);
Source

fn eigvals(&self) -> Result<EagerTensor>

Return general eigenvalues without eigenvectors.

§Errors

Returns the validation, unsupported-dtype, numerical-convergence, runtime-state, or output-contract errors reported by Self::eig.

§Examples
let values = a.eigvals()?;
assert_eq!(values.shape(), &[2]);
Source

fn pinv(&self) -> Result<EagerTensor>

Return the Moore-Penrose pseudoinverse with the default tolerance.

§Errors

Returns Error::Validation for invalid matrix metadata, Error::Extension for unsupported SVD execution, and Error::Internal for an unexpected decomposition output contract.

§Examples
let pseudoinverse = a.pinv()?;
assert_eq!(pseudoinverse.shape(), &[2, 2]);
Source

fn pinv_with_rtol(&self, rtol: f64) -> Result<EagerTensor>

Return the Moore-Penrose pseudoinverse with an explicit relative tolerance.

§Errors

Returns Error::Validation when rtol is negative or non-finite, plus the Error::Extension and output-contract errors reported by Self::pinv.

§Examples
let pseudoinverse = a.pinv_with_rtol(1.0e-12)?;
assert_eq!(pseudoinverse.shape(), &[2, 2]);
Source

fn norm( &self, ord: Option<f64>, dim: Option<&[usize]>, keepdim: bool, ) -> Result<EagerTensor>

Return a vector, matrix, or tensor norm.

§Errors

Returns Error::Validation for an unsupported order/dimension combination or invalid axes, Error::Extension when a required matrix decomposition is unsupported, and eager runtime/backend failures.

§Examples
let frobenius = a.norm(None, None, false)?;
assert_eq!(frobenius.shape(), &[]);

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§