Skip to main content

ConcreteEinsumPlan

Struct ConcreteEinsumPlan 

Source
pub struct ConcreteEinsumPlan { /* private fields */ }
Expand description

Prepared concrete einsum plan for repeated executions with fixed input dtype and shape metadata.

Preparing a plan parses and optimizes the contraction tree once. Execution validates the later inputs against the prepared dtype and shape contract, then runs the stored tree without re-planning.

§Examples

use tenferro_cpu::CpuBackend;
use tenferro_einsum::ConcreteEinsumPlan;
use tenferro_tensor::Tensor;

let lhs = Tensor::from_vec_col_major(vec![2, 3], vec![1.0_f64; 6]).unwrap();
let rhs = Tensor::from_vec_col_major(vec![3, 4], vec![1.0_f64; 12]).unwrap();
let plan = ConcreteEinsumPlan::prepare([&lhs, &rhs], "ij,jk->ik")?;

let mut backend = CpuBackend::new();
let out = plan.execute([&lhs, &rhs], &mut backend)?;
assert_eq!(out.shape(), &[2, 4]);

Implementations§

Source§

impl ConcreteEinsumPlan

Source

pub fn prepare<'a, I>(inputs: I, subscripts: &str) -> Result<Self>
where I: AsRef<[&'a Tensor]>,

Prepare a plan from dtype-erased concrete tensor inputs and string notation.

Source

pub fn prepare_subscripts<'a, I>( inputs: I, subscripts: &EinsumSubscripts, ) -> Result<Self>
where I: AsRef<[&'a Tensor]>,

Prepare a plan from dtype-erased concrete tensor inputs and parsed integer-label subscripts.

Source

pub fn prepare_typed<'a, T, I>(inputs: I, subscripts: &str) -> Result<Self>
where T: TensorScalar, I: AsRef<[&'a TypedTensor<T>]>,

Prepare a plan from typed concrete tensor inputs and string notation.

Source

pub fn prepare_typed_subscripts<'a, T, I>( inputs: I, subscripts: &EinsumSubscripts, ) -> Result<Self>
where T: TensorScalar, I: AsRef<[&'a TypedTensor<T>]>,

Prepare a plan from typed concrete tensor inputs and parsed integer-label subscripts.

Source

pub fn prepare_read<'a, I>(inputs: I, subscripts: &str) -> Result<Self>
where I: AsRef<[TensorRead<'a>]>,

Prepare a plan from read-only tensor inputs and string notation.

Source

pub fn prepare_read_subscripts<'a, I>( inputs: I, subscripts: &EinsumSubscripts, ) -> Result<Self>
where I: AsRef<[TensorRead<'a>]>,

Prepare a plan from read-only tensor inputs and parsed integer-label subscripts.

Source

pub fn execute<'a, I, B>(&self, inputs: I, backend: &mut B) -> Result<Tensor>
where I: AsRef<[&'a Tensor]>, B: TensorBackend,

Execute this plan on dtype-erased concrete tensor inputs.

Source

pub fn execute_typed<'a, T, I, B>( &self, inputs: I, backend: &mut B, ) -> Result<TypedTensor<T>>
where T: TensorScalar, I: AsRef<[&'a TypedTensor<T>]>, B: TensorBackend,

Execute this plan on typed concrete tensor inputs.

Source

pub fn execute_read<'a, I, B>( &self, inputs: I, backend: &mut B, ) -> Result<Tensor>
where I: AsRef<[TensorRead<'a>]>, B: TensorBackend,

Execute this plan on read-only tensor inputs.

Source

pub fn execute_into<'a, I, B>( &self, inputs: I, backend: &mut B, out: TensorWrite<'_>, ) -> Result<()>
where I: AsRef<[&'a Tensor]>, B: TensorBackend,

Execute this plan on dtype-erased concrete tensor inputs into caller-provided output.

Source

pub fn execute_typed_into<'a, T, I, B>( &self, inputs: I, backend: &mut B, out: &mut TypedTensor<T>, ) -> Result<()>
where T: TensorScalar, I: AsRef<[&'a TypedTensor<T>]>, B: TensorBackend,

Execute this plan on typed concrete tensor inputs into caller-provided output.

Source

pub fn execute_read_into<'a, I, B>( &self, inputs: I, backend: &mut B, out: TensorWrite<'_>, ) -> Result<()>
where I: AsRef<[TensorRead<'a>]>, B: TensorBackend,

Execute this plan on read-only tensor inputs into caller-provided output.

Source

pub fn execute_read_into_accum<'a, I, B>( &self, inputs: I, backend: &mut B, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<()>
where I: AsRef<[TensorRead<'a>]>, B: TensorBackend,

Execute this plan on read-only inputs with scaled output accumulation.

accumulation follows the dot-general contract: out = alpha * einsum(inputs) + beta * out.

§Examples
use tenferro_cpu::CpuBackend;
use tenferro_einsum::ConcreteEinsumPlan;
use tenferro_tensor::{
    DotGeneralAccumulation, DType, Tensor, TensorRead, TensorWrite,
};

let lhs = Tensor::from_vec_col_major(vec![1], vec![2.0_f64])?;
let rhs = Tensor::from_vec_col_major(vec![1], vec![3.0_f64])?;
let mut out = Tensor::from_vec_col_major(vec![], vec![1.0_f64])?;
let plan = ConcreteEinsumPlan::prepare([&lhs, &rhs], "i,i->")?;
let mut backend = CpuBackend::new();
plan.execute_read_into_accum(
    [TensorRead::from_tensor(&lhs), TensorRead::from_tensor(&rhs)],
    &mut backend,
    DotGeneralAccumulation::add_to(DType::F64)?,
    TensorWrite::from_tensor(&mut out),
)?;
assert_eq!(out.as_slice::<f64>()?, &[7.0]);

Trait Implementations§

Source§

impl Debug for ConcreteEinsumPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,