8.6 KiB
If
@sphinxdirective
Versioned name: If-8
Category: Condition
Short description: If operation contains two internal networks(subgraphs) such as then_body and else_body,
and performs one of them depending on cond value. If cond is True, then_body is executed. If cond is False,
the operation executes the else_body subgraph.
Detailed description
If must not contain empty subgraphs. Each of them must have at least one operation Result.
Also the number of outputs from If always must be greater than zero and equal to the number of outputs from each subgraph.
If attributes:
-
Subgraphs:
then_body/else_bodyare subgraphs that are executed depending on thecondvalue. The subgraph is described operation by operation as a typical IR network. The subgraph has inputs (Parameteroperations) and outputs (Resultoperations).-
Subgraph's inputs - inputs to the subgraph which associated with If inputs via port_map.
The subgraph can have any number of inputs (even zero).
-
Subgraph's outputs - outputs from the subgraph which associated with If outputs via port_map.
The subgraph must contain at least one output. Each If output is associated with one output from the subgraph. Therefore the number of
then_bodyoutputs is equal to the number of outputs from If and the number ofelse_bodyoutputs. The type of the subgraph output and the type of the associated output from If must be equal.
-
-
Port maps:
port_map is a set of rules to map input or output data tensors of If operation onto the subgraph data tensors. The
port_mapentries can beinputandoutput. Each entry describes a corresponding mapping rule. If has two port_maps:then_port_mapforthen_bodyandelse_port_mapforelse_body.-
Port map attributes:
-
external_port_id
- Description: external_port_id is a port ID of If operation.
- Range of values: IDs of the If inputs and outputs
- Type:
unsigned int - Default value: None
- Required: yes
-
internal_layer_id
- Description: internal_layer_id is a
ParameterorResultoperation ID inside the subgraph to map to. - Range of values: IDs of the
ParameterorResultoperations in the subgraph - Type:
unsigned int - Default value: None
- Required: yes
- Description: internal_layer_id is a
-
-
If Inputs
-
cond: A scalar or 1D tensor with 1 element of
booleantype specifying which subgraph to execute.Truevalue means to execute thethen_body,False-else_body. Required. -
Multiple other inputs: Tensors of different types and shapes. Optional.
If Outputs
- Multiple outputs: Results of execution of one of the subgraph. Tensors of any type and shape.
Body Inputs
- Multiple inputs: Tensors of different types and shapes. Optional.
Body Outputs
- Multiple outputs: Results of execution of the subgraph. Tensors of any type and shape.
Examples
Example 1: a typical If structure
.. code-block:: cpp
2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4@endsphinxdirective