GetInputTensor

Description

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

Prototype

const Tensor *GetInputTensor(const size_t index) const

Parameters

Parameter

Input/Output

Description

index

Input

Operator input index, starting from 0.

Returns

Pointer to the input tensor. If the input index is invalid, a null pointer is returned.

For details about the definition of the tensor type, see Tensor.

Restrictions

If the input is not set to data dependency, when this API is called to obtain a tensor, only the correct shape, format, and datatype information can be obtained from the tensor, and the actual tensor data address (the obtained address is nullptr) cannot be obtained.

Example

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;
  }
  // ...
}