RefSwitch

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

RefSwitch is a basic control flow operator. Its function is the same as Switch: it forwards the input tensor data to the corresponding output port based on the Boolean scalar input pred. When pred is true, the data is forwarded to output_true; otherwise, it is forwarded to output_false. The shapes and data types of both outputs are the same as those of the input data. The difference is that RefSwitch is used for reference (ref) type data, and usually works with the RefMerge operator to implement branch control.

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
data Input The reference 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 RefSwitch 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_refswitch Invokes the RefSwitch operator by building a graph through the operator IR.