File indexing completed on 2025-08-28 08:58:47
0001 #include "onnx/defs/schema.h"
0002 #include "onnx/defs/shape_inference.h"
0003
0004 namespace ONNX_NAMESPACE {
0005
0006 void AssertAttributeProtoTypeAndLength(
0007 const AttributeProto* attr_proto,
0008 int expected_length,
0009 TensorProto_DataType expected_type,
0010 bool required) {
0011 if (nullptr == attr_proto) {
0012 if (required) {
0013 fail_shape_inference("Unspecified required attribute.");
0014 }
0015 return;
0016 }
0017 const auto& [type, length] = getAttributeProtoElemTypeAndLength(attr_proto);
0018 if (type != expected_type) {
0019 fail_shape_inference(
0020 "Attribute '", attr_proto->name(), "' must have type ", TensorProto_DataType_Name(expected_type), ".");
0021 }
0022 if (length != expected_length) {
0023 fail_shape_inference("Attribute '", attr_proto->name(), "' must have ", expected_length, " elements.");
0024 }
0025 }
0026
0027 }