Skip to main content

Expr

Trait Expr 

Source
pub trait Expr<T: Clone> {
    // Required methods
    fn eval_at(&self, index: usize) -> T;
    fn size(&self) -> usize;
    fn shape(&self) -> &[usize];

    // Provided methods
    fn eval(&self) -> Array<T> { ... }
    fn can_fuse_with<E: Expr<T>>(&self, other: &E) -> bool { ... }
}
Expand description

Trait for lazy expressions that can be evaluated

All expression types (binary ops, unary ops, arrays) implement this trait to enable deferred computation and optimization.

Required Methods§

Source

fn eval_at(&self, index: usize) -> T

Evaluate the expression at a specific index

This is the core method that enables lazy evaluation. Each expression knows how to compute its value at any given index without materializing the entire result.

Source

fn size(&self) -> usize

Get the size of the expression result

Source

fn shape(&self) -> &[usize]

Get the shape of the expression result

Provided Methods§

Source

fn eval(&self) -> Array<T>

Materialize the expression into an Array

This triggers evaluation of the entire expression tree, applying all optimizations and fusions.

Source

fn can_fuse_with<E: Expr<T>>(&self, other: &E) -> bool

Check if this expression can be fused with another

Returns true if the expressions have compatible shapes for fusion.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a, T: Clone> Expr<T> for ArrayExpr<'a, T>

Source§

impl<A, B, C> Expr<f64> for FusedMultiplyAdd<A, B, C>
where A: Expr<f64>, B: Expr<f64>, C: Expr<f64>,

Source§

impl<L, R> Expr<f64> for SimdBinaryExpr<L, R>
where L: Expr<f64>, R: Expr<f64>,

Source§

impl<T, A, B, C, D, F1, F2, F3> Expr<T> for FusedQuadOp<T, A, B, C, D, F1, F2, F3>
where T: Clone, A: Expr<T>, B: Expr<T>, C: Expr<T>, D: Expr<T>, F1: Fn(T, T) -> T, F2: Fn(T, T) -> T, F3: Fn(T, T) -> T,

Source§

impl<T, A, B, C, F1, F2> Expr<T> for FusedElementWiseChain<T, A, B, C, F1, F2>
where T: Clone, A: Expr<T>, B: Expr<T>, C: Expr<T>, F1: Fn(T, T) -> T, F2: Fn(T, T) -> T,

Source§

impl<T, C, Tr, Fa> Expr<T> for WhereExpr<T, C, Tr, Fa>
where T: Clone, C: Expr<bool>, Tr: Expr<T>, Fa: Expr<T>,

Source§

impl<T, E, F1, F2> Expr<T> for FusedUnaryChain<T, E, F1, F2>
where T: Clone, E: Expr<T>, F1: Fn(T) -> T, F2: Fn(T) -> T,

Source§

impl<T, E, F> Expr<T> for ScalarExpr<T, E, F>
where T: Clone, E: Expr<T>, F: Fn(T, T) -> T,

Source§

impl<T, E, F> Expr<T> for UnaryExpr<T, E, F>
where T: Clone, E: Expr<T>, F: Fn(T) -> T,

Source§

impl<T, E> Expr<T> for ClipExpr<T, E>
where T: Clone + PartialOrd, E: Expr<T>,

Source§

impl<T, E> Expr<T> for FusedScalarBroadcast<T, E>
where T: Clone, E: Expr<T>,

Source§

impl<T, L, R, F1, F2> Expr<T> for FusedBinaryScalarExpr<T, L, R, F1, F2>
where T: Clone, L: Expr<T>, R: Expr<T>, F1: Fn(T, T) -> T, F2: Fn(T, T) -> T,

Source§

impl<T, L, R, F> Expr<T> for BinaryExpr<T, L, R, F>
where T: Clone, L: Expr<T>, R: Expr<T>, F: Fn(T, T) -> T,

Source§

impl<T: Clone> Expr<T> for BroadcastScalarExpr<T>