Skip to main content

NativeEinsumPlan

Struct NativeEinsumPlan 

Source
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

Source

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"));
Source

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§

Source§

impl Debug for NativeEinsumPlan

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<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,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

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
§

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

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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