Skip to main content

typed_eager_einsum

Function typed_eager_einsum 

Source
pub fn typed_eager_einsum<T: TensorScalar>(
    ctx: &mut impl TensorBackend,
    inputs: &[&TypedTensor<T>],
    subscripts: &str,
) -> Result<TypedTensor<T>>
Expand description

Execute eager einsum over typed tensors and return a typed result.

ยงExamples

use tenferro_einsum::typed_eager_einsum;
use tenferro_tensor::{cpu::CpuBackend, TypedTensor};

let mut ctx = CpuBackend::new();
let a = TypedTensor::<f64>::from_vec(vec![2, 3], vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
let b = TypedTensor::<f64>::from_vec(vec![3, 2], vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);

let c = typed_eager_einsum(&mut ctx, &[&a, &b], "ij,jk->ik").unwrap();

assert_eq!(c.shape, vec![2, 2]);
assert_eq!(c.as_slice(), &[22.0, 28.0, 49.0, 64.0]);