Follow
Function Usage
Specifies that the data type, format, and shape of the current input or output are the same as those of a previously defined input.
Prototype
OpParamDef &Follow(const char *paramName);
OpParamDef &Follow(const char *paramName, FollowType ftype);
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
paramName |
Input |
Input name that has been defined. |
ftype |
Input |
Enumeration type of FollowType, indicating the follow type. The options are as follows:
|
Returns
OpParamDef operator definition. For details, see OpParamDef.
Constraints
- The data source of Follow can only be input.
- For shape inference, an input parameter can only be followed by an output parameter rather than another input parameter.
- Chain-type follow is supported. For example, C follows B, and B follows A. However, the follow type cannot be changed (ftype must be consistent) during the process.
- The Follow API has simpler logic than the InferShape function. Using the Follow API is recommended so that you do not have to register the InferShape function.
- The InferShape function and the Follow API cannot be used together. If they are used together, the InferShape function prevails. Ensure that all output shapes can be deduced from the InferShape function.
- The input parameter type of Follow can also be DataTypeList or FormatList. After the Follow API is called, the data type/format of the current input/output is the same as that of combined paramName.
Example
If the output y1 follows the input x1, the data type, format, and shape of y1 are the same as those of x1.
this->Input("x1")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT, ge::DT_FLOAT})
.Format({ge::FORMAT_ND, ge::FORMAT_ND});
this->Input("x2")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT, ge::DT_FLOAT})
.Format({ge::FORMAT_ND, ge::FORMAT_ND});
this->Output("y1")
.ParamType(REQUIRED)
.Follow("x1")
.OutputShapeDependOnCompute();
Parent topic: OpParamDef