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>
impl<'a, T: Float> Expr<'a, T>
Sourcepub fn input(tensor: &'a Tensor<T>) -> Self
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]);Sourcepub fn eval(&self) -> Result<Tensor<T>>
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).