File size: 857 Bytes
dc2106c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "onnx/defs/schema.h"
#include "onnx/defs/shape_inference.h"

namespace ONNX_NAMESPACE {

void AssertAttributeProtoTypeAndLength(

    const AttributeProto* attr_proto,

    int expected_length,

    TensorProto_DataType expected_type,

    bool required) {
  if (nullptr == attr_proto) {
    if (required) {
      fail_shape_inference("Unspecified required attribute.");
    }
    return;
  }
  const auto& [type, length] = getAttributeProtoElemTypeAndLength(attr_proto);
  if (type != expected_type) {
    fail_shape_inference(
        "Attribute '", attr_proto->name(), "' must have type ", TensorProto_DataType_Name(expected_type), ".");
  }
  if (length != expected_length) {
    fail_shape_inference("Attribute '", attr_proto->name(), "' must have ", expected_length, " elements.");
  }
}

} // namespace ONNX_NAMESPACE