Skip to main content

TypedTensorReadEinsumIntoExt

Trait TypedTensorReadEinsumIntoExt 

Source
pub trait TypedTensorReadEinsumIntoExt<T: TensorScalar> {
    // Required methods
    fn einsum_read_into<'out, B, O>(
        &self,
        subscripts: &str,
        backend: &mut B,
        out: O,
    ) -> Result<()>
       where B: TensorBackend,
             O: Into<TypedTensorWrite<'out, T>>;
    fn einsum_read_into_subscripts<'out, B, O>(
        &self,
        subscripts: &EinsumSubscripts,
        backend: &mut B,
        out: O,
    ) -> Result<()>
       where B: TensorBackend,
             O: Into<TypedTensorWrite<'out, T>>;
}
Expand description

Backend-explicit preallocated-output einsum methods for typed borrowed views.

§Examples

use tenferro_cpu::CpuBackend;
use tenferro_einsum::TypedTensorReadEinsumIntoExt;
use tenferro_tensor::TypedTensor;

let lhs = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0])?;
let rhs = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![3.0, 4.0])?;
let mut output = TypedTensor::<f64>::from_vec_col_major(vec![], vec![0.0])?;
let mut backend = CpuBackend::new();
[lhs.as_view(), rhs.as_view()].einsum_read_into("i,i->", &mut backend, &mut output)?;
assert_eq!(output.as_slice()?, &[11.0]);

Required Methods§

Source

fn einsum_read_into<'out, B, O>( &self, subscripts: &str, backend: &mut B, out: O, ) -> Result<()>
where B: TensorBackend, O: Into<TypedTensorWrite<'out, T>>,

Execute an einsum from string notation over typed borrowed views into a caller-provided typed output.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_einsum::TypedTensorReadEinsumIntoExt;
use tenferro_tensor::TypedTensor;

let input = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 3.0])?;
let mut output = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0; 2])?;
let mut backend = CpuBackend::new();
[input.as_view()].einsum_read_into("i->i", &mut backend, &mut output)?;
assert_eq!(output.as_slice()?, &[2.0, 3.0]);
§Errors

Returns Error::InvalidSubscripts for malformed notation, Error::Validation with a shape, rank, or dtype payload when inputs or output do not match, or Error::Tensor for a typed backend failure.

Source

fn einsum_read_into_subscripts<'out, B, O>( &self, subscripts: &EinsumSubscripts, backend: &mut B, out: O, ) -> Result<()>
where B: TensorBackend, O: Into<TypedTensorWrite<'out, T>>,

Execute an einsum from parsed integer-label subscripts over typed borrowed views into a caller-provided typed output.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_einsum::{EinsumSubscripts, TypedTensorReadEinsumIntoExt};
use tenferro_tensor::TypedTensor;

let input = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![2.0, 3.0])?;
let mut output = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0; 2])?;
let subscripts = EinsumSubscripts::new(&[&[0]], &[0]);
let mut backend = CpuBackend::new();
[input.as_view()].einsum_read_into_subscripts(&subscripts, &mut backend, &mut output)?;
assert_eq!(output.as_slice()?, &[2.0, 3.0]);
§Errors

Returns Error::Validation with a shape, rank, or dtype payload when inputs or output do not match, or Error::Tensor for a typed backend failure.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T: TensorScalar> TypedTensorReadEinsumIntoExt<T> for [TypedTensorView<'a, T>]

Source§

fn einsum_read_into<'out, B, O>( &self, subscripts: &str, backend: &mut B, out: O, ) -> Result<()>
where B: TensorBackend, O: Into<TypedTensorWrite<'out, T>>,

Source§

fn einsum_read_into_subscripts<'out, B, O>( &self, subscripts: &EinsumSubscripts, backend: &mut B, out: O, ) -> Result<()>
where B: TensorBackend, O: Into<TypedTensorWrite<'out, T>>,

Source§

impl<'a, T: TensorScalar, const N: usize> TypedTensorReadEinsumIntoExt<T> for [TypedTensorView<'a, T>; N]

Source§

fn einsum_read_into<'out, B, O>( &self, subscripts: &str, backend: &mut B, out: O, ) -> Result<()>
where B: TensorBackend, O: Into<TypedTensorWrite<'out, T>>,

Source§

fn einsum_read_into_subscripts<'out, B, O>( &self, subscripts: &EinsumSubscripts, backend: &mut B, out: O, ) -> Result<()>
where B: TensorBackend, O: Into<TypedTensorWrite<'out, T>>,

Implementors§