Skip to main content

LinalgRepr

Trait LinalgRepr 

Source
pub trait LinalgRepr: Repr {
    type Real;
    type Complex;
    type Index;

    // Required methods
    fn wrap_real(t: Tensor) -> Result<Self::Real>;
    fn wrap_complex(t: Tensor) -> Result<Self::Complex>;
    fn wrap_index(t: Tensor) -> Result<Self::Index>;
}
Expand description

A Repr that can also name the real, complex and index results of a linalg operation.

Erased returns Tensor everywhere. Typed<T> returns TypedTensor<T::Real> for real-valued results (singular values, eigenvalues of a Hermitian matrix, …), TypedTensor<T::Complex> for the general eigendecomposition and TypedTensor<i64> for index results.

§Examples

use tenferro_linalg::LinalgRepr;
use tenferro_tensor::{Erased, Tensor, Typed};

let s = Tensor::from_vec_col_major(vec![1], vec![2.0_f64])?;
let erased = <Erased as LinalgRepr>::wrap_real(s.duplicate()?)?;
let typed = <Typed<f64> as LinalgRepr>::wrap_real(s.duplicate()?)?;
assert_eq!(erased.shape(), typed.shape());
// A mismatching dtype is an internal error, not a panic.
assert!(<Typed<f32> as LinalgRepr>::wrap_real(s).is_err());

Required Associated Types§

Source

type Real

The real-valued result type (Tensor or TypedTensor<T::Real>).

Source

type Complex

The complex-valued result type (Tensor or TypedTensor<T::Complex>).

Source

type Index

The index result type (Tensor or TypedTensor<i64>).

Required Methods§

Source

fn wrap_real(t: Tensor) -> Result<Self::Real>

Wrap an erased real-valued result. Typed representations perform a checked downcast.

§Errors

Returns Error::Internal when a typed representation receives a tensor of another dtype.

§Examples
use tenferro_linalg::LinalgRepr;
use tenferro_tensor::{Tensor, Typed};

let s = Tensor::from_vec_col_major(vec![1], vec![2.0_f64])?;
assert!(<Typed<f64> as LinalgRepr>::wrap_real(s.duplicate()?).is_ok());
assert!(<Typed<f32> as LinalgRepr>::wrap_real(s).is_err());
Source

fn wrap_complex(t: Tensor) -> Result<Self::Complex>

Wrap an erased complex-valued result. Typed representations perform a checked downcast.

§Errors

Returns Error::Internal when a typed representation receives a tensor of another dtype.

§Examples
use num_complex::Complex64;
use tenferro_linalg::LinalgRepr;
use tenferro_tensor::{Tensor, Typed};

let c = Tensor::from_vec_col_major(vec![1], vec![Complex64::new(1.0, 2.0)])?;
assert!(<Typed<f64> as LinalgRepr>::wrap_complex(c.duplicate()?).is_ok());
assert!(<Typed<f32> as LinalgRepr>::wrap_complex(c).is_err());
Source

fn wrap_index(t: Tensor) -> Result<Self::Index>

Wrap an erased index result. Typed representations perform a checked downcast.

§Errors

Returns Error::Internal when a typed representation receives a tensor of another dtype.

§Examples
use tenferro_linalg::LinalgRepr;
use tenferro_tensor::{Tensor, Typed};

let idx = Tensor::from_vec_col_major(vec![2], vec![0_i64, 1])?;
assert!(<Typed<f64> as LinalgRepr>::wrap_index(idx).is_ok());
let real = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert!(<Typed<f64> as LinalgRepr>::wrap_index(real).is_err());

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl LinalgRepr for Erased

Source§

impl<T: LinalgScalar> LinalgRepr for Typed<T>

Implementors§