BroadcastShape
Description
Infers the output shape after broadcast based on the input tensor shape. Dual-input and multi-input overloads are supported.
Prototype
bool BroadcastShape(const gert::Shape* in1Shape, const gert::Shape* in2Shape, gert::Shape* outShape)
bool BroadcastShape(const std::vector<const gert::Shape*>& inShapes, gert::Shape* outShape)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
in1Shape |
Input |
Shape of the first input tensor. |
in2Shape |
Input |
Shape of the second input tensor. |
inShapes |
Input |
List of shapes of all input tensors in multi-input use cases. |
outShape |
Output |
Inferred output shape. |
Return Value
Bool type:
- true: The broadcast inference is successful.
- false: The broadcast inference fails, and the input shape cannot be broadcast.
Constraints
None.
Example
The following sample code is for reference only. Do not copy and run it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Dual-input use case auto in1Shape = context->GetInputShape(0); auto in2Shape = context->GetInputShape(1); auto outShape = context->GetOutputShape(0); if (!Ops::Base::BroadcastShape(in1Shape, in2Shape, outShape)) { return ge::GRAPH_FAILED; } // Multi-input use case std::vector<const gert::Shape*> inShapes = {context->GetInputShape(0), context->GetInputShape(1), context->GetInputShape(2)}; auto outShape = context->GetOutputShape(0); if (!Ops::Base::BroadcastShape(inShapes, outShape)) { return ge::GRAPH_FAILED; } |
Parent topic: infershape