GetOutputShape

Function Usage

Obtains the pointer to an output shape based on the operator output index. The output index refers to the actual index after operator instantiation, not the index in the prototype definition.

Prototype

1
Shape *GetOutputShape(const size_t index)

Parameters

Parameter

Input/Output

Description

index

Input

Operator output index, starting from 0.

Returns

Pointer to a specified output shape. If the input index is invalid, a null pointer is returned.

For details about the definition of the shape type, see Shape.

Constraints

None

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ge::graphStatus InferShapeForReshape(InferShapeContext *context) {
  const gert::Shape *x_shape = context->GetInputShape(0);        // Obtain the shape of input 0.
  const gert::Tensor *shape_tensor = context->GetInputTensor(1); // Obtain the data dependency of input tensor 1.
  gert::Shape *output_shape = context->GetOutputShape(0);
  if (x_shape == nullptr || shape_tensor == nullptr || output_shape == nullptr) {
    // Defensive programming. In an undesirable scenario, an error is printed and a failure message is returned.
    return ge::GRAPH_FAILED;
  }
  // ...
}