tvm_tirx.ir.const#
- tvm_tirx.ir.const(value, ty=None, loc=UNKNOWN_LOC, *, dtype=None)#
Construct a constant with an explicit or inferred primitive type.
The primitive type may be supplied positionally, as
ty=or asdtype=. Supply at most one non-None type. When both are omitted or None, boolean, integer and floating-point scalars usebool,int32andfloat32, respectively. The same defaults apply to NumPy scalars, regardless of their original width. Values outside the inferred type’s range raise an error; the type never widens automatically. NaN and infinity are accepted floating-point values. Specifytyordtypeexplicitly to select another width or a vector type.- Parameters:
value (number) – The content of the constant number.
ty (str, DataType or tvm_tirx.ir.PrimType, optional) – The primitive type. None uses the scalar-kind defaults above.
loc (Location, optional) – The location of the constant value in the source.
dtype (str, DataType or tvm_tirx.ir.PrimType, optional) – Keyword-only alias for
ty. None leavestyunchanged. Supplying non-None values for bothtyanddtyperaises TypeError.
- Returns:
const_val (tvm_tirx.ir.Expr) – The result expression.
- Return type:
Examples
ir.const(True) # bool ir.const(1) # int32 ir.const(1.0) # float32 ir.const(1 << 31) # raises ValueError: exceeds int32 range ir.const(1 << 31, ty="int64") # explicit wider type ir.const(1 << 31, dtype="int64") # equivalent type keyword