valΒΆ

onnx_ir.val(name, dtype=None, shape=None, *, type=None, const_value=None)ΒΆ

Create a Value with the given name and type.

This is a convenience constructor for creating a Value that allows you to specify dtype and shape in a more relaxed manner. Whereas to create a Value directly, you need to create a TypeProtocol and Shape object first, this function allows you to specify dtype as a DataType and shape as a sequence of integers or symbolic dimensions.

Example:

>>> import onnx_ir as ir
>>> t = ir.val("x", ir.DataType.FLOAT, ["N", 42, 3])
>>> t.name
'x'
>>> t.type
Tensor(FLOAT)
>>> t.shape
Shape([SymbolicDim(N), 42, 3])

Added in version 0.1.9.

Parameters:
  • name (str | None) – The name of the value.

  • dtype (ir.DataType | None) – The data type of the TensorType of the value. This is used only when type is None.

  • shape (ir.Shape | Sequence[int | str | None] | None) – The shape of the value.

  • type (ir.TypeProtocol | None) – The type of the value. Only one of dtype and type can be specified.

  • const_value (ir.TensorProtocol | None) – The constant tensor that initializes the value. Supply this argument when you want to create an initializer. The type and shape can be obtained from the tensor.

Returns:

A Value object.

Return type:

ir.Value