SymbolicDim¶
- class onnx_ir.SymbolicDim(value)¶
Immutable symbolic dimension that can be shared across multiple shapes.
SymbolicDim is used to represent a symbolic (non-integer) dimension in a tensor shape. It is immutable and can be compared or hashed. It supports SymPy expressions for symbolic arithmetic.
Example:
>>> import onnx_ir as ir >>> # Simple symbolic dimension (backward compatible) >>> batch = ir.SymbolicDim("batch") >>> batch.value 'batch' >>> # Arithmetic operations return new SymbolicDim with SymPy expression >>> seq_plus_one = ir.SymbolicDim("seq_len") + 1 >>> seq_plus_one.value 'seq_len + 1' >>> # Evaluate with concrete values >>> seq_plus_one.evaluate({"seq_len": 128}) 129
- Parameters:
value (str | None)
- display(*, page=False)¶
Pretty print the object.
- Parameters:
page (bool) – Whether to page the output.
- Return type:
None
- evaluate(bindings)[source]¶
Evaluate the symbolic dimension with concrete values.
- Parameters:
bindings (Mapping[str, int]) – A mapping from symbol names to integer values.
- Returns:
The concrete integer value if fully evaluated, or a SymbolicDim containing the partially evaluated expression or None.
- Return type:
Example:
>>> dim = ir.SymbolicDim("N") + 1 >>> dim.evaluate({"N": 10}) 11