pub enum TDim {
Val(i64),
Sym(Symbol),
Add(Vec<TDim>),
Mul(Vec<TDim>),
MulInt(i64, Box<TDim>),
Div(Box<TDim>, u64),
Broadcast(Vec<TDim>),
Min(Vec<TDim>),
Max(Vec<TDim>),
Ge(Box<TDim>, Box<TDim>),
Eq(Box<TDim>, Box<TDim>),
}Variants§
Val(i64)
Sym(Symbol)
Add(Vec<TDim>)
Mul(Vec<TDim>)
MulInt(i64, Box<TDim>)
Div(Box<TDim>, u64)
Broadcast(Vec<TDim>)
Min(Vec<TDim>)
Max(Vec<TDim>)
Ge(Box<TDim>, Box<TDim>)
Comparison: evaluates to 1 (true) or 0 (false). lhs >= rhs
Eq(Box<TDim>, Box<TDim>)
Comparison: evaluates to 1 (true) or 0 (false). lhs == rhs
Implementations§
Source§impl TDim
impl TDim
pub fn is_one(&self) -> bool
pub fn to_i64(&self) -> TractResult<i64>
pub fn as_i64(&self) -> Option<i64>
pub fn eval_to_i64(&self, values: &SymbolValues) -> TractResult<i64>
pub fn eval(&self, values: &SymbolValues) -> TDim
pub fn eval_with_scenario(&self, scenario: &str) -> TDim
pub fn substitute(&self, from: &Symbol, to: &Self) -> TractResult<Self>
pub fn substitute_all(&self, map: &HashMap<Symbol, Self>) -> TractResult<Self>
pub fn reduce(self) -> TDim
pub fn find_scope(&self) -> Option<SymbolScope>
Sourcepub fn expand_polynomial(self) -> TDim
pub fn expand_polynomial(self) -> TDim
Fully distribute every Mul of Adds in self into a flat sum of
products, then simplify. Used to compare two algebraically equal
but differently-factored TDims for equality (e.g. Reshape volume
checks on graphs where the same dimension is built two ways).
Cost can blow up combinatorially on very deeply factored expressions — call this only at boundaries where structural equality is needed, not as a general-purpose simplifier.
pub fn simplify(self) -> TDim
pub fn simplify_with_extra_assertions(self, extra: &[Assertion]) -> TDim
pub fn low_inclusive_bound(&self) -> Option<i64>
pub fn high_inclusive_bound(&self) -> Option<i64>
pub fn prove_positive_or_zero(&self) -> bool
pub fn prove_strict_positive(&self) -> bool
pub fn prove_negative_or_zero(&self) -> bool
pub fn prove_strict_negative(&self) -> bool
Sourcepub fn lcm(&self, other: &TDim) -> Option<TDim>
pub fn lcm(&self, other: &TDim) -> Option<TDim>
Least common multiple of two TDims when both reduce to positive
integers.
Returns Val(0) if either operand is 0, and None if either is
symbolic, negative, or if the LCM would overflow i64. Callers
that need a safe answer for symbolic operands should fall back at
the call site.
pub fn gcd(&self) -> u64
pub fn div_ceil(self, rhs: u64) -> TDim
pub fn guess_slope(&self, sym: &Symbol) -> (i64, u64)
pub fn symbols(&self) -> HashSet<Symbol>
pub fn compatible_with(&self, other: &TDim) -> bool
Trait Implementations§
Source§impl<'a> AddAssign<&'a TDim> for TDim
impl<'a> AddAssign<&'a TDim> for TDim
Source§fn add_assign(&mut self, rhs: &'a TDim)
fn add_assign(&mut self, rhs: &'a TDim)
+= operation. Read moreSource§impl<I> AddAssign<I> for TDim
impl<I> AddAssign<I> for TDim
Source§fn add_assign(&mut self, rhs: I)
fn add_assign(&mut self, rhs: I)
+= operation. Read moreSource§impl DimLike for TDim
impl DimLike for TDim
fn maybe_div(&self, other: &Self) -> TractResult<(Self, u64)>
Source§fn to_i64(&self) -> TractResult<i64>
fn to_i64(&self) -> TractResult<i64>
Source§fn eval(&self, values: &SymbolValues) -> Self
fn eval(&self, values: &SymbolValues) -> Self
fn substitute(&self, from: &Symbol, to: &Self) -> TractResult<Self>
fn substitute_all(&self, map: &HashMap<Symbol, Self>) -> TractResult<Self>
Source§fn eval_to_i64(&self, values: &SymbolValues) -> TractResult<i64>
fn eval_to_i64(&self, values: &SymbolValues) -> TractResult<i64>
fn broadcast(self, other: Self) -> TractResult<Self>
fn compatible_with(&self, other: &Self) -> bool
fn mini(self, other: Self) -> Self
fn maxi(self, other: Self) -> Self
fn to_usize(&self) -> TractResult<usize>
fn to_isize(&self) -> TractResult<isize>
fn to_i32(&self) -> TractResult<i32>
Source§impl<I: AsPrimitive<u64> + PrimInt> DivAssign<I> for TDim
impl<I: AsPrimitive<u64> + PrimInt> DivAssign<I> for TDim
Source§fn div_assign(&mut self, rhs: I)
fn div_assign(&mut self, rhs: I)
/= operation. Read moreSource§impl<'a> MulAssign<&'a TDim> for TDim
impl<'a> MulAssign<&'a TDim> for TDim
Source§fn mul_assign(&mut self, rhs: &'a TDim)
fn mul_assign(&mut self, rhs: &'a TDim)
*= operation. Read moreSource§impl<I: Into<TDim>> MulAssign<I> for TDim
impl<I: Into<TDim>> MulAssign<I> for TDim
Source§fn mul_assign(&mut self, rhs: I)
fn mul_assign(&mut self, rhs: I)
*= operation. Read moreSource§impl<I: AsPrimitive<u64> + PrimInt> RemAssign<I> for TDim
impl<I: AsPrimitive<u64> + PrimInt> RemAssign<I> for TDim
Source§fn rem_assign(&mut self, rhs: I)
fn rem_assign(&mut self, rhs: I)
%= operation. Read moreSource§impl<'a> SubAssign<&'a TDim> for TDim
impl<'a> SubAssign<&'a TDim> for TDim
Source§fn sub_assign(&mut self, rhs: &'a TDim)
fn sub_assign(&mut self, rhs: &'a TDim)
-= operation. Read moreSource§impl<I> SubAssign<I> for TDim
impl<I> SubAssign<I> for TDim
Source§fn sub_assign(&mut self, rhs: I)
fn sub_assign(&mut self, rhs: I)
-= operation. Read moreimpl Eq for TDim
Auto Trait Implementations§
impl Freeze for TDim
impl !RefUnwindSafe for TDim
impl Send for TDim
impl Sync for TDim
impl Unpin for TDim
impl UnsafeUnpin for TDim
impl !UnwindSafe for TDim
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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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