pub struct NativeEinsumPlan { /* private fields */ }Expand description
A parsed einsum specification reusable across operand shapes and borrowed buffers.
The specification is parsed once; shape-specific owning execution plans are prepared and cached by the backend. This is the minimal parsed-plan bridge for https://github.com/tensor4all/tensor4all-rs/issues/1065. Unlike an operand-bound concrete plan, this specification accepts new shapes.
§Examples
use tensor4all_tensorbackend::NativeEinsumPlan;
use tenferro_tensor::{Tensor, TensorRead};
let plan = NativeEinsumPlan::new("i->")?;
for (data, expected) in [(vec![1.0_f64, 2.0], 3.0), (vec![1.0, 2.0, 3.0], 6.0)] {
let operand = Tensor::from_vec_col_major([data.len()], data)?;
let sum = plan.execute_reads(&[TensorRead::from_tensor(&operand)])?;
assert_eq!(sum.as_slice::<f64>()?, &[expected]);
}Implementations§
Source§impl NativeEinsumPlan
impl NativeEinsumPlan
Sourcepub fn new(subscripts: &str) -> Result<Self>
pub fn new(subscripts: &str) -> Result<Self>
Parse a fixed einsum expression without binding operand shapes or storage.
The parse is shared per thread: a repeated call with the same expression string returns a plan over the already parsed specification instead of re-parsing it, so the string form can be called inside a loop.
§Errors
Returns an error for invalid subscripts, such as a missing explicit output term.
§Examples
use tensor4all_tensorbackend::NativeEinsumPlan;
let error = NativeEinsumPlan::new("ij,jk").unwrap_err();
assert!(error.to_string().contains("invalid einsum subscripts"));Sourcepub fn execute_reads(&self, inputs: &[TensorRead<'_>]) -> Result<NativeTensor>
pub fn execute_reads(&self, inputs: &[TensorRead<'_>]) -> Result<NativeTensor>
Execute the parsed expression on borrowed inputs without copying them.
§Errors
Returns an error for empty inputs, operand-count or rank mismatches, incompatible label extents, or a backend execution failure. Mixed dtypes retain the promotion performed by the native einsum graph.
§Examples
use tensor4all_tensorbackend::NativeEinsumPlan;
use tenferro_tensor::{Tensor, TensorRead};
let plan = NativeEinsumPlan::new("i,i->")?;
let lhs = Tensor::from_vec_col_major([2], vec![1.0_f64, 2.0])?;
let rhs = Tensor::from_vec_col_major([2], vec![3.0_f64, 4.0])?;
let dot = plan.execute_reads(&[TensorRead::from_tensor(&lhs), TensorRead::from_tensor(&rhs)])?;
assert_eq!(dot.as_slice::<f64>()?, &[11.0]);Trait Implementations§
Auto Trait Implementations§
impl Freeze for NativeEinsumPlan
impl RefUnwindSafe for NativeEinsumPlan
impl Send for NativeEinsumPlan
impl Sync for NativeEinsumPlan
impl Unpin for NativeEinsumPlan
impl UnsafeUnpin for NativeEinsumPlan
impl UnwindSafe for NativeEinsumPlan
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T, U> Imply<T> for U
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