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
impl ConcreteEinsumPlan
Sourcepub fn prepare<'a, I>(inputs: I, subscripts: &str) -> Result<Self>
pub fn prepare<'a, I>(inputs: I, subscripts: &str) -> Result<Self>
Prepare a plan from dtype-erased concrete tensor inputs and string notation.
§Errors
Returns Error::InvalidSubscripts for malformed notation,
Error::Validation for rank, shape, or dtype contract violations, or
Error::Planning when no valid contraction tree can be built.
Sourcepub fn prepare_subscripts<'a, I>(
inputs: I,
subscripts: &EinsumSubscripts,
) -> Result<Self>
pub fn prepare_subscripts<'a, I>( inputs: I, subscripts: &EinsumSubscripts, ) -> Result<Self>
Prepare a plan from dtype-erased concrete tensor inputs and parsed integer-label subscripts.
§Errors
Returns Error::Validation for rank, shape, or dtype contract
violations, or Error::Planning when no valid contraction tree can be
built.
Sourcepub fn prepare_typed<'a, T, I>(inputs: I, subscripts: &str) -> Result<Self>
pub fn prepare_typed<'a, T, I>(inputs: I, subscripts: &str) -> Result<Self>
Prepare a plan from typed concrete tensor inputs and string notation.
§Errors
Returns Error::InvalidSubscripts for malformed notation,
Error::Validation for rank or shape contract violations, or
Error::Planning when no valid contraction tree can be built.
Sourcepub fn prepare_typed_subscripts<'a, T, I>(
inputs: I,
subscripts: &EinsumSubscripts,
) -> Result<Self>
pub fn prepare_typed_subscripts<'a, T, I>( inputs: I, subscripts: &EinsumSubscripts, ) -> Result<Self>
Prepare a plan from typed concrete tensor inputs and parsed integer-label subscripts.
§Errors
Returns Error::Validation for rank or shape contract violations, or
Error::Planning when no valid contraction tree can be built.
Sourcepub fn prepare_read<'a, I>(inputs: I, subscripts: &str) -> Result<Self>where
I: AsRef<[TensorRead<'a>]>,
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.
§Errors
Returns Error::InvalidSubscripts for malformed notation,
Error::Validation for rank, shape, or dtype contract violations, or
Error::Planning when no valid contraction tree can be built.
Sourcepub fn prepare_read_subscripts<'a, I>(
inputs: I,
subscripts: &EinsumSubscripts,
) -> Result<Self>where
I: AsRef<[TensorRead<'a>]>,
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.
§Errors
Returns Error::Validation for rank, shape, or dtype contract
violations, or Error::Planning when no valid contraction tree can be
built.
Sourcepub fn execute<'a, I, B>(&self, inputs: I, backend: &mut B) -> Result<Tensor>
pub fn execute<'a, I, B>(&self, inputs: I, backend: &mut B) -> Result<Tensor>
Execute this plan on dtype-erased concrete tensor inputs.
§Errors
Returns Error::Validation when inputs differ from the prepared
rank, shape, or dtype contract, or Error::Tensor for a typed backend
failure.
Sourcepub fn execute_typed<'a, T, I, B>(
&self,
inputs: I,
backend: &mut B,
) -> Result<TypedTensor<T>>
pub fn execute_typed<'a, T, I, B>( &self, inputs: I, backend: &mut B, ) -> Result<TypedTensor<T>>
Execute this plan on typed concrete tensor inputs.
§Errors
Returns Error::Validation when inputs differ from the prepared rank
or shape contract, or Error::Tensor for a typed backend failure.
Sourcepub fn execute_read<'a, I, B>(
&self,
inputs: I,
backend: &mut B,
) -> Result<Tensor>
pub fn execute_read<'a, I, B>( &self, inputs: I, backend: &mut B, ) -> Result<Tensor>
Execute this plan on read-only tensor inputs.
§Errors
Returns Error::Validation when inputs differ from the prepared
rank, shape, or dtype contract, or Error::Tensor for a typed backend
failure.
Sourcepub fn execute_into<'a, I, B>(
&self,
inputs: I,
backend: &mut B,
out: TensorWrite<'_>,
) -> Result<()>
pub fn execute_into<'a, I, B>( &self, inputs: I, backend: &mut B, out: TensorWrite<'_>, ) -> Result<()>
Execute this plan on dtype-erased concrete tensor inputs into caller-provided output.
§Errors
Returns Error::Validation for input or output rank, shape, or dtype
mismatches, or Error::Tensor for a typed backend failure.
Sourcepub fn execute_typed_into<'a, 'out, T, I, B, O>(
&self,
inputs: I,
backend: &mut B,
out: O,
) -> Result<()>where
T: TensorScalar,
I: AsRef<[&'a TypedTensor<T>]>,
B: TensorBackend,
O: Into<TypedTensorWrite<'out, T>>,
pub fn execute_typed_into<'a, 'out, T, I, B, O>(
&self,
inputs: I,
backend: &mut B,
out: O,
) -> Result<()>where
T: TensorScalar,
I: AsRef<[&'a TypedTensor<T>]>,
B: TensorBackend,
O: Into<TypedTensorWrite<'out, T>>,
Execute this plan on typed concrete tensor inputs into caller-provided output.
§Errors
Returns Error::Validation for input or output rank or shape
mismatches, or Error::Tensor for a typed backend failure.
Sourcepub fn execute_read_into<'a, I, B>(
&self,
inputs: I,
backend: &mut B,
out: TensorWrite<'_>,
) -> Result<()>
pub fn execute_read_into<'a, I, B>( &self, inputs: I, backend: &mut B, out: TensorWrite<'_>, ) -> Result<()>
Execute this plan on read-only tensor inputs into caller-provided output.
§Errors
Returns Error::Validation for input or output rank, shape, or dtype
mismatches, or Error::Tensor for a typed backend failure.
Sourcepub fn execute_read_into_accum<'a, I, B>(
&self,
inputs: I,
backend: &mut B,
accumulation: DotGeneralAccumulation,
out: TensorWrite<'_>,
) -> Result<()>
pub fn execute_read_into_accum<'a, I, B>( &self, inputs: I, backend: &mut B, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<()>
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]);§Errors
Returns Error::Validation for input or output rank, shape, or dtype
mismatches, Error::Numerical for an invalid accumulation, or
Error::Tensor for a typed backend failure.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConcreteEinsumPlan
impl RefUnwindSafe for ConcreteEinsumPlan
impl Send for ConcreteEinsumPlan
impl Sync for ConcreteEinsumPlan
impl Unpin for ConcreteEinsumPlan
impl UnsafeUnpin for ConcreteEinsumPlan
impl UnwindSafe for ConcreteEinsumPlan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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