Skip to main content

CoreRepr

Trait CoreRepr 

Source
pub trait CoreRepr: Repr {
    type Real;
    type Bool;

    // Required methods
    fn wrap_value_of(op: &'static str, t: Tensor) -> Result<Self::Value>;
    fn wrap_real(op: &'static str, t: Tensor) -> Result<Self::Real>;
    fn wrap_bool(op: &'static str, t: Tensor) -> Result<Self::Bool>;
}
Expand description

The core result types for an input representation.

Erased returns Tensor everywhere. Typed<T> returns TypedTensor<T::Real> for real-valued results (abs) and TypedTensor<bool> for predicates (compare).

§Examples

use tenferro_runtime::CoreRepr;
use tenferro_tensor::{Erased, Tensor, Typed};

let t = Tensor::from_vec_col_major(vec![1], vec![true])?;
let erased = <Erased as CoreRepr>::wrap_bool("compare", t.duplicate()?)?;
let typed = <Typed<f64> as CoreRepr>::wrap_bool("compare", t.duplicate()?)?;
assert_eq!(erased.shape(), typed.shape());
// A typed result of another dtype is a validation error naming the op.
assert!(<Typed<f64> as CoreRepr>::wrap_value_of("add", t).is_err());

Required Associated Types§

Source

type Real

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

Source

type Bool

The predicate result type (Tensor or TypedTensor<bool>).

Required Methods§

Source

fn wrap_value_of(op: &'static str, t: Tensor) -> Result<Self::Value>

Wrap the erased result of op in this representation’s value type; typed representations check the dtype.

§Errors

Returns Error::Validation with ValidationError::DTypeMismatch (op op) when a typed representation receives a tensor of another dtype.

§Examples
use tenferro_runtime::CoreRepr;
use tenferro_tensor::{Tensor, Typed};

let t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert!(<Typed<f64> as CoreRepr>::wrap_value_of("add", t.duplicate()?).is_ok());
assert!(<Typed<f32> as CoreRepr>::wrap_value_of("add", t).is_err());
Source

fn wrap_real(op: &'static str, t: Tensor) -> Result<Self::Real>

Wrap the erased real-valued result of op; typed representations check the dtype.

§Errors

Returns Error::Validation with ValidationError::DTypeMismatch when a typed representation receives a tensor of another dtype.

§Examples
use tenferro_runtime::CoreRepr;
use tenferro_tensor::{Tensor, Typed};

let t = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert!(<Typed<f64> as CoreRepr>::wrap_real("abs", t.duplicate()?).is_ok());
assert!(<Typed<f32> as CoreRepr>::wrap_real("abs", t).is_err());
Source

fn wrap_bool(op: &'static str, t: Tensor) -> Result<Self::Bool>

Wrap the erased predicate result of op; typed representations check the dtype.

§Errors

Returns Error::Validation with ValidationError::DTypeMismatch when a typed representation receives a tensor of another dtype.

§Examples
use tenferro_runtime::CoreRepr;
use tenferro_tensor::{Tensor, Typed};

let flags = Tensor::from_vec_col_major(vec![2], vec![true, false])?;
assert!(<Typed<f64> as CoreRepr>::wrap_bool("compare", flags).is_ok());
let real = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert!(<Typed<f64> as CoreRepr>::wrap_bool("compare", 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 CoreRepr for Erased

Source§

type Real = Tensor

Source§

type Bool = Tensor

Source§

fn wrap_value_of(_op: &'static str, t: Tensor) -> Result<Tensor>

Source§

fn wrap_real(_op: &'static str, t: Tensor) -> Result<Tensor>

Source§

fn wrap_bool(_op: &'static str, t: Tensor) -> Result<Tensor>

Source§

impl<T: TensorScalar> CoreRepr for Typed<T>

Source§

type Real = TypedTensor<<T as TensorScalar>::Real>

Source§

type Bool = TypedTensor<bool>

Source§

fn wrap_value_of(op: &'static str, t: Tensor) -> Result<TypedTensor<T>>

Source§

fn wrap_real(op: &'static str, t: Tensor) -> Result<Self::Real>

Source§

fn wrap_bool(op: &'static str, t: Tensor) -> Result<Self::Bool>

Implementors§