diff --git a/onnxruntime/core/framework/op_node_proto_helper.cc b/onnxruntime/core/framework/op_node_proto_helper.cc index 960c997124..478a80e20c 100644 --- a/onnxruntime/core/framework/op_node_proto_helper.cc +++ b/onnxruntime/core/framework/op_node_proto_helper.cc @@ -90,34 +90,35 @@ inline constexpr int ArrayTypeToAttributeType() { } \ } -#define ORT_DEFINE_GET_ATTRS(IMPL_T, T, list) \ - template <> \ - template <> \ - Status OpNodeProtoHelper::GetAttrs( \ - const std::string& name, std::vector& values) const { \ - const AttributeProto* attr = TryGetAttribute(name); \ - if (!attr) { \ - return Status(ONNXRUNTIME, FAIL, "No attribute with this name is defined."); \ - } \ - values.reserve(attr->list##_size()); \ - for (int i = 0; i < attr->list##_size(); ++i) { \ - values.push_back(static_cast(attr->list(i))); \ - } \ - return Status::OK(); \ - } \ - template <> \ - template <> \ - Status OpNodeProtoHelper::GetAttrs( \ - const std::string& name, gsl::span values) const { \ - const AttributeProto* attr = TryGetAttribute(name); \ - if (!attr) { \ - return Status(ONNXRUNTIME, FAIL, "No attribute with this name is defined."); \ - } \ - ORT_ENFORCE(values.size() == static_cast(attr->list##_size())); \ - for (int i = 0; i < attr->list##_size(); ++i) { \ - values[i] = static_cast(attr->list(i)); \ - } \ - return Status::OK(); \ +#define ORT_DEFINE_GET_ATTRS(IMPL_T, T, list) \ + template <> \ + template <> \ + Status OpNodeProtoHelper::GetAttrs( \ + const std::string& name, std::vector& values) const { \ + const AttributeProto* attr = TryGetAttribute(name); \ + if (!attr) { \ + return Status(ONNXRUNTIME, FAIL, "No attribute with this name is defined."); \ + } \ + values.reserve(attr->list##_size()); \ + for (int i = 0; i < attr->list##_size(); ++i) { \ + values.push_back(static_cast(attr->list(i))); \ + } \ + return Status::OK(); \ + } \ + template <> \ + template <> \ + Status OpNodeProtoHelper::GetAttrs( \ + const std::string& name, gsl::span values) const { \ + const AttributeProto* attr = TryGetAttribute(name); \ + if (!attr) { \ + return Status(ONNXRUNTIME, FAIL, "No attribute with this name is defined."); \ + } \ + ORT_RETURN_IF(values.size() != static_cast(attr->list##_size()), \ + "GetAttrs failed. Expect values.size()=" , (attr->list##_size()) , ", got " , values.size()); \ + for (int i = 0; i < attr->list##_size(); ++i) { \ + values[i] = static_cast(attr->list(i)); \ + } \ + return Status::OK(); \ } // Will not work for std::strings