Switch

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products √
Atlas inference products √
Atlas training products √

Function Description

Switch is a basic control flow operator. It forwards the input tensor data to the corresponding output port based on the Boolean scalar input pred: when pred is true, data is forwarded to output_true; otherwise, it is forwarded to output_false. The shapes and data types of the two outputs output_true and output_false of this operator are the same as those of the input data. Switch usually works with the Merge operator to implement branch control.

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
data Input The tensor to be forwarded. TensorType::ALL() ND
pred Input A Boolean scalar that determines the output port to which the data is forwarded. DT_BOOL ND
output_false Output When pred is false, data is forwarded to this output. The shape and data type are the same as those of data. TensorType::ALL() ND
output_true Output When pred is true, data is forwarded to this output. The shape and data type are the same as those of data. TensorType::ALL() ND

Constraint Description

  • The input pred must be a Boolean scalar (rank 0 or unknown rank). Otherwise, shape inference fails.
  • The data type of the input pred must be DT_BOOL. Otherwise, data type inference fails.

Invocation Description

The Switch operator is a basic control flow operator. It is usually used as a branch selection node in a graph, and is not invoked separately.

Invocation Method Invocation Sample Description
Graph-mode invocation test_geir_switch Invokes the Switch operator by building a graph through the operator IR.