If#
Domain:
ai.onnxSince version: 13
If conditional
Inputs
cond (B): Condition for the if. The tensor must contain a single element.
Outputs
outputs (V): Values that are live-out to the enclosing scope. The return values in the
then_branchandelse_branchmust be of the same data type. Thethen_branchandelse_branchmay produce tensors with the same element type and different shapes. If corresponding outputs from the then-branch and the else-branch have static shapes S1 and S2, then the shape of the corresponding output variable of the if-node (if present) must be compatible with both S1 and S2 as it represents the union of both possible shapes.For example, if in a model file, the first output ofthen_branchis typed float tensor with shape [2] and the first output ofelse_branchis another float tensor with shape [3], If’s first output should have (a) no shape set, or (b) a shape of rank 1 with neitherdim_valuenordim_paramset, or (c) a shape of rank 1 with a uniquedim_param. In contrast, the first output cannot have the shape [2] since [2] and [3] are not compatible.
Type Constraints
V: All Tensor and Sequence types Allowed types: seq(tensor(bool)), seq(tensor(complex128)), seq(tensor(complex64)), seq(tensor(double)), seq(tensor(float)), seq(tensor(float16)), seq(tensor(int16)), seq(tensor(int32)), seq(tensor(int64)), seq(tensor(int8)), seq(tensor(string)), seq(tensor(uint16)), seq(tensor(uint32)), seq(tensor(uint64)), seq(tensor(uint8)), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).
B: Only bool Allowed types: tensor(bool).
Examples#
test_cc_if
Attributes:
then_branch = <subgraph>
else_branch = <subgraph>
Inputs:
cond: shape=(), dtype=bool
True
Outputs:
res: shape=(2,), dtype=float32
[1., 2.]
test_cc_if_else
Attributes:
then_branch = <subgraph>
else_branch = <subgraph>
Inputs:
cond: shape=(), dtype=bool
False
Outputs:
res: shape=(2,), dtype=float32
[3., 4.]
Differences with previous version (11)#
SchemaDiff: If (domain 'ai.onnx')
old version: 11
new version: 13
breaking: no
Type constraints:
changed ‘V’: added types: [‘seq(tensor(bool))’, ‘seq(tensor(complex128))’, ‘seq(tensor(complex64))’, ‘seq(tensor(double))’, ‘seq(tensor(float))’, ‘seq(tensor(float16))’, ‘seq(tensor(int16))’, ‘seq(tensor(int32))’, ‘seq(tensor(int64))’, ‘seq(tensor(int8))’, ‘seq(tensor(string))’, ‘seq(tensor(uint16))’, ‘seq(tensor(uint32))’, ‘seq(tensor(uint64))’, ‘seq(tensor(uint8))’]