pub enum DimExpr {
Const(usize),
InputDim {
input_idx: usize,
axis: usize,
},
Add(Box<DimExpr>, Box<DimExpr>),
Sub(Box<DimExpr>, Box<DimExpr>),
Mul(Box<DimExpr>, Box<DimExpr>),
FloorDiv(Box<DimExpr>, Box<DimExpr>),
Min(Box<DimExpr>, Box<DimExpr>),
Max(Box<DimExpr>, Box<DimExpr>),
}Expand description
Arithmetic expression over tensor dimension sizes.
Evaluated at execution time from actual input tensor shapes.
InputDim { input_idx, axis } references the axis size of
the op’s input_idx-th input tensor.
§Examples
use tenferro_ops::dim_expr::DimExpr;
let expr = DimExpr::mul(
DimExpr::InputDim {
input_idx: 0,
axis: 0,
},
DimExpr::InputDim {
input_idx: 0,
axis: 1,
},
);
assert_eq!(expr.eval(&[&[3, 4]]), 12);Variants§
Const(usize)
A concrete dimension size.
InputDim
Axis size of the op’s input_idx-th input tensor.
Add(Box<DimExpr>, Box<DimExpr>)
Sum of two dimension expressions.
Sub(Box<DimExpr>, Box<DimExpr>)
Difference of two dimension expressions.
Mul(Box<DimExpr>, Box<DimExpr>)
Product of two dimension expressions.
FloorDiv(Box<DimExpr>, Box<DimExpr>)
Floor division of two dimension expressions.
Min(Box<DimExpr>, Box<DimExpr>)
Minimum of two dimension expressions.
Max(Box<DimExpr>, Box<DimExpr>)
Maximum of two dimension expressions.
Implementations§
Source§impl DimExpr
impl DimExpr
Sourcepub fn eval(&self, input_shapes: &[&[usize]]) -> usize
pub fn eval(&self, input_shapes: &[&[usize]]) -> usize
Evaluate the expression using actual input tensor shapes.
§Panics
Panics if an InputDim node references an input_idx that is
out of bounds for input_shapes, or an axis that is out of
bounds for the corresponding shape slice.
§Examples
use tenferro_ops::dim_expr::DimExpr;
let expr = DimExpr::add(
DimExpr::InputDim {
input_idx: 0,
axis: 0,
},
DimExpr::Const(2),
);
assert_eq!(expr.eval(&[&[5, 7]]), 7);Sourcepub fn max_input_idx(&self) -> Option<usize>
pub fn max_input_idx(&self) -> Option<usize>
Return the maximum referenced input_idx, or None if the expression
contains only constants.
§Examples
use tenferro_ops::dim_expr::DimExpr;
let expr = DimExpr::add(
DimExpr::InputDim {
input_idx: 0,
axis: 0,
},
DimExpr::InputDim {
input_idx: 2,
axis: 1,
},
);
assert_eq!(expr.max_input_idx(), Some(2));Sourcepub fn from_concrete(shape: &[usize]) -> Vec<Self>
pub fn from_concrete(shape: &[usize]) -> Vec<Self>
Sourcepub fn input_shape(input_idx: usize, rank: usize) -> Vec<Self>
pub fn input_shape(input_idx: usize, rank: usize) -> Vec<Self>
Sourcepub fn max_input_idx_all(exprs: &[Self]) -> Option<usize>
pub fn max_input_idx_all(exprs: &[Self]) -> Option<usize>
Trait Implementations§
impl Eq for DimExpr
impl StructuralPartialEq for DimExpr
Auto Trait Implementations§
impl Freeze for DimExpr
impl RefUnwindSafe for DimExpr
impl Send for DimExpr
impl Sync for DimExpr
impl Unpin for DimExpr
impl UnsafeUnpin for DimExpr
impl UnwindSafe for DimExpr
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
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