Skip to main content

Repr

Trait Repr 

Source
pub trait Repr: Sealed {
    type Value;
    type Write<'a>;

    // Required methods
    fn wrap_value(t: Tensor) -> Result<Self::Value>;
    fn erase_write<'a>(w: Self::Write<'a>) -> TensorWrite<'a>;
}
Expand description

A representation of tensor values: dtype-erased or statically typed.

§Examples

use tenferro_tensor::{Erased, Repr, Tensor, Typed};

let a = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
let b = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
let erased = <Erased as Repr>::wrap_value(a)?;
let typed = <Typed<f64> as Repr>::wrap_value(b)?;
assert_eq!(erased.shape(), typed.shape());

Required Associated Types§

Source

type Value

The value type: Tensor or TypedTensor<T>.

Source

type Write<'a>

The writable target type: TensorWrite<'a> or TypedTensorWrite<'a, T>.

Required Methods§

Source

fn wrap_value(t: Tensor) -> Result<Self::Value>

Wrap an erased result in this representation. Typed representations perform a checked downcast.

§Errors

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

§Examples
use tenferro_tensor::{Repr, Tensor, Typed};

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

fn erase_write<'a>(w: Self::Write<'a>) -> TensorWrite<'a>

Erase a writable target to TensorWrite. Metadata only.

§Examples
use tenferro_tensor::{Erased, Repr, Tensor, TensorWrite};

let mut t = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
let write = TensorWrite::from_tensor(&mut t);
let erased = <Erased as Repr>::erase_write(write);
assert_eq!(erased.shape(), &[2]);

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§