Skip to main content

Expr

Enum Expr 

Source
pub enum Expr<'a, T: Float> {
Show 16 variants Input(&'a Tensor<T>), Scalar(T), Add(Box<Expr<'a, T>>, Box<Expr<'a, T>>), Sub(Box<Expr<'a, T>>, Box<Expr<'a, T>>), Mul(Box<Expr<'a, T>>, Box<Expr<'a, T>>), Div(Box<Expr<'a, T>>, Box<Expr<'a, T>>), Neg(Box<Expr<'a, T>>), Sqrt(Box<Expr<'a, T>>), Exp(Box<Expr<'a, T>>), Ln(Box<Expr<'a, T>>), Abs(Box<Expr<'a, T>>), Sin(Box<Expr<'a, T>>), Cos(Box<Expr<'a, T>>), Pow(Box<Expr<'a, T>>, Box<Expr<'a, T>>), Fma(Box<Expr<'a, T>>, Box<Expr<'a, T>>, Box<Expr<'a, T>>), Clamp(Box<Expr<'a, T>>, T, T),
}
Expand description

An expression node in the computation graph.

Each variant represents either a leaf (tensor input or scalar constant) or a fused element-wise operation. The tree is evaluated in one pass via Expr::eval, avoiding intermediate tensor allocations.

Variants§

§

Input(&'a Tensor<T>)

A tensor input (leaf node).

§

Scalar(T)

A scalar constant, broadcast to match the output shape.

§

Add(Box<Expr<'a, T>>, Box<Expr<'a, T>>)

Element-wise addition.

§

Sub(Box<Expr<'a, T>>, Box<Expr<'a, T>>)

Element-wise subtraction.

§

Mul(Box<Expr<'a, T>>, Box<Expr<'a, T>>)

Element-wise multiplication.

§

Div(Box<Expr<'a, T>>, Box<Expr<'a, T>>)

Element-wise division.

§

Neg(Box<Expr<'a, T>>)

Unary negation.

§

Sqrt(Box<Expr<'a, T>>)

Element-wise square root.

§

Exp(Box<Expr<'a, T>>)

Element-wise exponential.

§

Ln(Box<Expr<'a, T>>)

Element-wise natural logarithm.

§

Abs(Box<Expr<'a, T>>)

Element-wise absolute value.

§

Sin(Box<Expr<'a, T>>)

Element-wise sine.

§

Cos(Box<Expr<'a, T>>)

Element-wise cosine.

§

Pow(Box<Expr<'a, T>>, Box<Expr<'a, T>>)

Element-wise power.

§

Fma(Box<Expr<'a, T>>, Box<Expr<'a, T>>, Box<Expr<'a, T>>)

Fused multiply-add: a * b + c.

§

Clamp(Box<Expr<'a, T>>, T, T)

Clamp values to [min, max].

Implementations§

Source§

impl<'a, T: Float> Expr<'a, T>

Source

pub fn input(tensor: &'a Tensor<T>) -> Self

Create an input expression referencing a tensor.

§Examples
use scivex_core::Tensor;
use scivex_core::jit::Expr;

let t = Tensor::from_vec(vec![1.0_f64, 2.0, 3.0], vec![3]).unwrap();
let result = Expr::input(&t).eval().unwrap();
assert_eq!(result.as_slice(), &[1.0, 2.0, 3.0]);
Source

pub fn scalar(val: T) -> Self

Create a scalar constant expression.

Source

pub fn add(self, other: Self) -> Self

Element-wise addition: self + other.

Source

pub fn sub(self, other: Self) -> Self

Element-wise subtraction: self - other.

Source

pub fn mul(self, other: Self) -> Self

Element-wise multiplication: self * other.

Source

pub fn div(self, other: Self) -> Self

Element-wise division: self / other.

Source

pub fn neg(self) -> Self

Unary negation: -self.

Source

pub fn sqrt(self) -> Self

Element-wise square root.

Source

pub fn exp(self) -> Self

Element-wise exponential.

Source

pub fn ln(self) -> Self

Element-wise natural logarithm.

Source

pub fn abs(self) -> Self

Element-wise absolute value.

Source

pub fn sin(self) -> Self

Element-wise sine.

Source

pub fn cos(self) -> Self

Element-wise cosine.

Source

pub fn pow(self, other: Self) -> Self

Element-wise power: self ^ other.

Source

pub fn fma(self, b: Self, c: Self) -> Self

Fused multiply-add: self * b + c.

Source

pub fn clamp(self, min: T, max: T) -> Self

Clamp values to [min, max].

Source

pub fn eval(&self) -> Result<Tensor<T>>

Evaluate the expression tree, producing a result tensor.

All Expr::Input tensors referenced anywhere in the tree must have the same shape. Scalar nodes are broadcast to match. Returns an error if input shapes disagree or if no shape can be determined (i.e., the entire expression is purely scalar with no tensor inputs).

Auto Trait Implementations§

§

impl<'a, T> Freeze for Expr<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for Expr<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Expr<'a, T>

§

impl<'a, T> Sync for Expr<'a, T>

§

impl<'a, T> Unpin for Expr<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for Expr<'a, T>
where T: UnsafeUnpin,

§

impl<'a, T> UnwindSafe for Expr<'a, T>

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