pub struct DimExpr { /* private fields */ }Expand description
A canonical integer polynomial over symbolic dimensions.
Invariant: terms never contains a zero coefficient, and every key
([Monomial]) is sorted ascending. The empty map is the integer 0.
The overflow flag marks an expression whose exact value could not be
represented because a coefficient combiner exceeded i64 range. Such an
expression is an opaque unknown (see the module-level overflow contract):
it is never a constant or bare symbol, and it lowers to a fresh symbol.
Implementations§
Source§impl DimExpr
impl DimExpr
Sourcepub fn overflow() -> Self
pub fn overflow() -> Self
An opaque unknown produced by an arithmetic overflow. See the module-level overflow contract. It reports as neither a constant nor a bare symbol, poisons any arithmetic it participates in, and lowers to a fresh symbol.
Sourcepub fn is_overflow(&self) -> bool
pub fn is_overflow(&self) -> bool
Whether this expression is the overflow/unknown sentinel.
Sourcepub fn as_const(&self) -> Option<i64>
pub fn as_const(&self) -> Option<i64>
The integer value, if this expression is a pure constant (includes 0).
Sourcepub fn as_symbol(&self) -> Option<SymbolId>
pub fn as_symbol(&self) -> Option<SymbolId>
The single symbol, if this expression is exactly one symbol with
coefficient 1 (e.g. a bare Dim::Symbolic round-trips through this).
Sourcepub fn add(&self, other: &DimExpr) -> DimExpr
pub fn add(&self, other: &DimExpr) -> DimExpr
self + other.
Overflow-safe: an out-of-range coefficient sum degrades the result to
DimExpr::overflow (never panics, never wraps). See the module-level
overflow contract.
Sourcepub fn mul(&self, other: &DimExpr) -> DimExpr
pub fn mul(&self, other: &DimExpr) -> DimExpr
self * other.
Overflow-safe: an out-of-range coefficient product or accumulation
degrades the result to DimExpr::overflow. See add.
Sourcepub fn checked_div(&self, other: &DimExpr) -> Option<DimExpr>
pub fn checked_div(&self, other: &DimExpr) -> Option<DimExpr>
self / other, only when the division is exact.
Handles the cases the op set actually produces: division by a non-zero
constant (every coefficient must divide evenly) and division by a single
monomial (symbol cancellation, as in Reshape -1 inference where
total = b*s*768 is divided by b*s*12 to yield 64). Anything else —
dividing by a multi-term polynomial, or a non-exact quotient — returns
None so the caller can degrade to a fresh symbol.