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§
Required Methods§
Sourcefn wrap_value(t: Tensor) -> Result<Self::Value>
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());Sourcefn erase_write<'a>(w: Self::Write<'a>) -> TensorWrite<'a>
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".