Skip to main content

TDim

Enum TDim 

Source
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

Source

pub fn is_one(&self) -> bool

Source

pub fn to_i64(&self) -> TractResult<i64>

Source

pub fn as_i64(&self) -> Option<i64>

Source

pub fn eval_to_i64(&self, values: &SymbolValues) -> TractResult<i64>

Source

pub fn eval(&self, values: &SymbolValues) -> TDim

Source

pub fn eval_with_scenario(&self, scenario: &str) -> TDim

Source

pub fn substitute(&self, from: &Symbol, to: &Self) -> TractResult<Self>

Source

pub fn substitute_all(&self, map: &HashMap<Symbol, Self>) -> TractResult<Self>

Source

pub fn reduce(self) -> TDim

Source

pub fn find_scope(&self) -> Option<SymbolScope>

Source

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.

Source

pub fn simplify(self) -> TDim

Source

pub fn simplify_with_extra_assertions(self, extra: &[Assertion]) -> TDim

Source

pub fn low_inclusive_bound(&self) -> Option<i64>

Source

pub fn high_inclusive_bound(&self) -> Option<i64>

Source

pub fn prove_positive_or_zero(&self) -> bool

Source

pub fn prove_strict_positive(&self) -> bool

Source

pub fn prove_negative_or_zero(&self) -> bool

Source

pub fn prove_strict_negative(&self) -> bool

Source

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.

Source

pub fn gcd(&self) -> u64

Source

pub fn div_ceil(self, rhs: u64) -> TDim

Source

pub fn guess_slope(&self, sym: &Symbol) -> (i64, u64)

Source

pub fn symbols(&self) -> HashSet<Symbol>

Source

pub fn compatible_with(&self, other: &TDim) -> bool

Trait Implementations§

Source§

impl<'a> Add<&'a TDim> for TDim

Source§

type Output = TDim

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a TDim) -> Self

Performs the + operation. Read more
Source§

impl<I> Add<I> for TDim
where I: Into<TDim>,

Source§

type Output = TDim

The resulting type after applying the + operator.
Source§

fn add(self, rhs: I) -> Self

Performs the + operation. Read more
Source§

impl<'a> AddAssign<&'a TDim> for TDim

Source§

fn add_assign(&mut self, rhs: &'a TDim)

Performs the += operation. Read more
Source§

impl<I> AddAssign<I> for TDim
where I: Into<TDim>,

Source§

fn add_assign(&mut self, rhs: I)

Performs the += operation. Read more
Source§

impl Bounded for TDim

Source§

fn min_value() -> Self

Returns the smallest finite number this type can represent
Source§

fn max_value() -> Self

Returns the largest finite number this type can represent
Source§

impl Clone for TDim

Source§

fn clone(&self) -> TDim

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Datum for TDim

Source§

fn name() -> &'static str

Source§

fn datum_type() -> DatumType

Source§

fn is<D: Datum>() -> bool

Source§

impl Debug for TDim

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TDim

Source§

fn default() -> TDim

Returns the “default value” for a type. Read more
Source§

impl DimLike for TDim

Source§

fn maybe_div(&self, other: &Self) -> TractResult<(Self, u64)>

Source§

fn to_i64(&self) -> TractResult<i64>

Convert to regular integer.
Source§

fn eval(&self, values: &SymbolValues) -> Self

Substitute as many symbols as possible in the dim value.
Source§

fn substitute(&self, from: &Symbol, to: &Self) -> TractResult<Self>

Source§

fn substitute_all(&self, map: &HashMap<Symbol, Self>) -> TractResult<Self>

Source§

fn eval_to_i64(&self, values: &SymbolValues) -> TractResult<i64>

Full evaluation of the symbol, failing if a symbol is missing
Source§

fn broadcast(self, other: Self) -> TractResult<Self>

Source§

fn compatible_with(&self, other: &Self) -> bool

Source§

fn mini(self, other: Self) -> Self

Source§

fn maxi(self, other: Self) -> Self

Source§

fn divceil(&self, other: usize) -> Self

Integer divise, rounding up to next integer.
Source§

fn to_usize(&self) -> TractResult<usize>

Source§

fn to_isize(&self) -> TractResult<isize>

Source§

fn to_i32(&self) -> TractResult<i32>

Source§

impl Display for TDim

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: AsPrimitive<u64> + PrimInt> Div<I> for TDim

Source§

type Output = TDim

The resulting type after applying the / operator.
Source§

fn div(self, rhs: I) -> Self

Performs the / operation. Read more
Source§

impl<I: AsPrimitive<u64> + PrimInt> DivAssign<I> for TDim

Source§

fn div_assign(&mut self, rhs: I)

Performs the /= operation. Read more
Source§

impl<'a> From<&'a Symbol> for TDim

Source§

fn from(it: &'a Symbol) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a i32> for TDim

Source§

fn from(v: &'a i32) -> TDim

Converts to this type from the input type.
Source§

impl<'a> From<&'a i64> for TDim

Source§

fn from(v: &'a i64) -> TDim

Converts to this type from the input type.
Source§

impl<'a> From<&'a isize> for TDim

Source§

fn from(v: &'a isize) -> TDim

Converts to this type from the input type.
Source§

impl<'a> From<&'a u64> for TDim

Source§

fn from(v: &'a u64) -> TDim

Converts to this type from the input type.
Source§

impl<'a> From<&'a usize> for TDim

Source§

fn from(v: &'a usize) -> TDim

Converts to this type from the input type.
Source§

impl From<Symbol> for TDim

Source§

fn from(it: Symbol) -> Self

Converts to this type from the input type.
Source§

impl From<TDim> for Tensor

Source§

fn from(it: TDim) -> Tensor

Converts to this type from the input type.
Source§

impl From<i32> for TDim

Source§

fn from(v: i32) -> TDim

Converts to this type from the input type.
Source§

impl From<i64> for TDim

Source§

fn from(v: i64) -> TDim

Converts to this type from the input type.
Source§

impl From<isize> for TDim

Source§

fn from(v: isize) -> TDim

Converts to this type from the input type.
Source§

impl From<u64> for TDim

Source§

fn from(v: u64) -> TDim

Converts to this type from the input type.
Source§

impl From<usize> for TDim

Source§

fn from(v: usize) -> TDim

Converts to this type from the input type.
Source§

impl Hash for TDim

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> Mul<&'a TDim> for TDim

Source§

type Output = TDim

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'a TDim) -> Self

Performs the * operation. Read more
Source§

impl<I: Into<TDim>> Mul<I> for TDim

Source§

type Output = TDim

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: I) -> Self

Performs the * operation. Read more
Source§

impl<'a> MulAssign<&'a TDim> for TDim

Source§

fn mul_assign(&mut self, rhs: &'a TDim)

Performs the *= operation. Read more
Source§

impl<I: Into<TDim>> MulAssign<I> for TDim

Source§

fn mul_assign(&mut self, rhs: I)

Performs the *= operation. Read more
Source§

impl Neg for TDim

Source§

type Output = TDim

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl One for TDim

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl PartialEq for TDim

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Product<&'a TDim> for TDim

Source§

fn product<I: Iterator<Item = &'a TDim>>(iter: I) -> TDim

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Product for TDim

Source§

fn product<I: Iterator<Item = TDim>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<I: AsPrimitive<u64> + PrimInt> Rem<I> for TDim

Source§

type Output = TDim

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: I) -> Self

Performs the % operation. Read more
Source§

impl<I: AsPrimitive<u64> + PrimInt> RemAssign<I> for TDim

Source§

fn rem_assign(&mut self, rhs: I)

Performs the %= operation. Read more
Source§

impl<'a> Sub<&'a TDim> for TDim

Source§

type Output = TDim

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a TDim) -> Self

Performs the - operation. Read more
Source§

impl<I> Sub<I> for TDim
where I: Into<TDim>,

Source§

type Output = TDim

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: I) -> Self

Performs the - operation. Read more
Source§

impl<'a> SubAssign<&'a TDim> for TDim

Source§

fn sub_assign(&mut self, rhs: &'a TDim)

Performs the -= operation. Read more
Source§

impl<I> SubAssign<I> for TDim
where I: Into<TDim>,

Source§

fn sub_assign(&mut self, rhs: I)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a TDim> for TDim

Source§

fn sum<I: Iterator<Item = &'a TDim>>(iter: I) -> TDim

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for TDim

Source§

fn sum<I: Iterator<Item = TDim>>(iter: I) -> TDim

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl ToDim for &TDim

Source§

fn to_dim(&self) -> TDim

Convert self to a TDim.
Source§

impl<'a> TryFrom<&'a TDim> for TDim

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(d: &'a TDim) -> TractResult<TDim>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a TDim> for usize

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(d: &'a TDim) -> TractResult<usize>

Performs the conversion.
Source§

impl Zero for TDim

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> DynEq for T
where T: Eq + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn Any + 'static)) -> bool

Source§

impl<T> DynHash for T
where T: Hash + ?Sized,

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> LowerBounded for T
where T: Bounded,

Source§

fn min_value() -> T

Returns the smallest finite number this type can represent
Source§

impl<I> ToDim for I
where I: Into<TDim> + Clone,

Source§

fn to_dim(&self) -> TDim

Convert self to a TDim.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> UpperBounded for T
where T: Bounded,

Source§

fn max_value() -> T

Returns the largest finite number this type can represent
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,