shape_controlflow.h#
Shape-inference functions for ONNX operators in the control flow family (If, Loop, Scan, …).
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace onnx_optim
-
namespace shapes#
-
namespace controlflow#
Functions
-
void ComputeShapeIf(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensordescriptors of anIfnode and stores them inctx.If(since opset 1 in theai.onnxdomain) selects one of two subgraphs depending on the booleancondinput and yields the outputs of the selected subgraph as its own outputs. Both subgraphs must declare the same number of outputs as theIfnode and the corresponding outputs must be type-compatible.Shape inference walks both
then_branchandelse_branchsub-graphs by calling :cpp:func:ComputeShapeson a copy ofctx(so that outer-scope values referenced by the sub-graph remain visible) and then merges the resulting per-output descriptors:the element dtype is kept when both branches agree and is set to :cpp:enumerator:
TensorType::kUndefinedotherwise;the shape is kept verbatim when both branches agree (same rank and identical dimensions); when the ranks match but some dimensions differ, those dimensions are replaced by a symbolic placeholder string of the form
"If_<output_name>_d<i>"; rank mismatches between the two branches are rejected withstd::invalid_argument.
- Parameters:
ctx – In/out context. Must already contain entries for every non-empty input of
nodeand for every outer-scope value referenced from the sub-graphs; on return it also contains entries for every non-empty output declared bynode.node – The
IfNodeProtowhose outputs should be described.node.op_type()must be"If"andnodemust declare exactly one input and at least one output.
- Throws:
std::invalid_argument – if
node.op_type()is not"If", ifnodehas no output, if thethen_branchorelse_branchattribute is missing or not aGraphProto, if a sub-graph does not declare the same number of outputs asnode, or if the two branches produce outputs with mismatching rank.
-
void ComputeShapeIf(ShapesContext &ctx, const NodeProto &node)#
-
namespace controlflow#
-
namespace shapes#
-
namespace onnx_optim