Repository: microsoft/onnxruntime
File: onnxruntime/core/framework/tensor_type_and_shape.cc (C++)

Code before:
std::unique_ptr<OrtTensorTypeAndShapeInfo> OrtTensorTypeAndShapeInfo::GetTensorShapeAndType(
    const onnxruntime::TensorShape* shape,
    const std::vector<std::string>* dim_params,
    const ONNX_NAMESPACE::TypeProto& type_proto) {
  auto value_case = type_proto.value_case();
  assert(value_case == ONNX_NAMESPACE::TypeProto::kTensorType ||
         value_case == ONNX_NAMESPACE::TypeProto::kSparseTensorType);

  auto dtype = (value_case == ONNX_NAMESPACE::TypeProto::kTensorType) ? type_proto.tensor_type().elem_type()
                                                                      : type_proto.sparse_tensor_type().elem_type();
  ONNXTensorElementDataType type = TensorDataTypeToOnnxRuntimeTensorElementDataType(dtype);
  if (ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED == type) {
    ORT_NOT_IMPLEMENTED("Tensor type is undefined");
  }

  return GetTensorShapeAndTypeHelper(type, shape, dim_params);
}

ORT_API_STATUS_IMPL(OrtApis::Value_GetTensorElementTypeAndShape, _In_ const OrtValue* value,
                    _Out_ ONNXTensorElementDataType* elem_type,
                    _Outptr_ const int64_t** shape_data,
                    _Out_ size_t* shape_data_count) {
  API_IMPL_BEGIN
  if (!value->IsAllocated() || (!value->IsTensor() && !value->IsSparseTensor())) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "the ort_value must contain a constructed tensor or sparse tensor");
  }

  if (elem_type == nullptr) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Output parameter `elem_type` must not be NULL");
  }

  if (shape_data == nullptr) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Output parameter `shape_data` must not be NULL");
  }

  if (shape_data_count == nullptr) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Output parameter `shape_data_count` must not be NULL");
  }

  gsl::span<const int64_t> shape_span;
  onnxruntime::MLDataType ml_data_type = nullptr;
  ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED;

  if (value->IsTensor()) {
    const Tensor& tensor = value->Get<onnxruntime::Tensor>();
    ml_data_type = tensor.DataType();
    shape_span = tensor.Shape().GetDims();

Review comment (suggestion):
```suggestion
                                 "Input parameter `value` must contain a constructed tensor or sparse tensor");
```

Code after:
std::unique_ptr<OrtTensorTypeAndShapeInfo> OrtTensorTypeAndShapeInfo::GetTensorShapeAndType(
    const onnxruntime::TensorShape* shape,
    const std::vector<std::string>* dim_params,
    const ONNX_NAMESPACE::TypeProto& type_proto) {
  auto value_case = type_proto.value_case();
  assert(value_case == ONNX_NAMESPACE::TypeProto::kTensorType ||
         value_case == ONNX_NAMESPACE::TypeProto::kSparseTensorType);

  auto dtype = (value_case == ONNX_NAMESPACE::TypeProto::kTensorType) ? type_proto.tensor_type().elem_type()
                                                                      : type_proto.sparse_tensor_type().elem_type();
  ONNXTensorElementDataType type = TensorDataTypeToOnnxRuntimeTensorElementDataType(dtype);
  if (ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED == type) {
    ORT_NOT_IMPLEMENTED("Tensor type is undefined");
  }

  return GetTensorShapeAndTypeHelper(type, shape, dim_params);
}

ORT_API_STATUS_IMPL(OrtApis::GetTensorElementTypeAndShapeDataReference, _In_ const OrtValue* value,
                    _Out_ ONNXTensorElementDataType* elem_type,
                    _Outptr_result_maybenull_ const int64_t** shape_data,
                    _Out_ size_t* shape_data_count) {
  API_IMPL_BEGIN
  if (!value->IsAllocated() || (!value->IsTensor() && !value->IsSparseTensor())) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Input parameter `value` must contain a constructed tensor or sparse tensor");
  }

  if (elem_type == nullptr) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Output parameter `elem_type` must not be NULL");
  }

  if (shape_data == nullptr) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Output parameter `shape_data` must not be NULL");
  }

  if (shape_data_count == nullptr) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "Output parameter `shape_data_count` must not be NULL");
  }

  gsl::span<const int64_t> shape_span;
  onnxruntime::MLDataType ml_data_type = nullptr;
  ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_UNDEFINED;

  if (value->IsTensor()) {
    const Tensor& tensor = value->Get<onnxruntime::Tensor>();
    ml_data_type = tensor.DataType();
    shape_span = tensor.Shape().GetDims();