Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions onnxruntime/core/framework/op_node_proto_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,35 @@ inline constexpr int ArrayTypeToAttributeType<std::string>() {
} \
}

#define ORT_DEFINE_GET_ATTRS(IMPL_T, T, list) \
template <> \
template <> \
Status OpNodeProtoHelper<IMPL_T>::GetAttrs<T>( \
const std::string& name, std::vector<T>& 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<T>(attr->list(i))); \
} \
return Status::OK(); \
} \
template <> \
template <> \
Status OpNodeProtoHelper<IMPL_T>::GetAttrs<T>( \
const std::string& name, gsl::span<T> 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<size_t>(attr->list##_size())); \
for (int i = 0; i < attr->list##_size(); ++i) { \
values[i] = static_cast<T>(attr->list(i)); \
} \
return Status::OK(); \
#define ORT_DEFINE_GET_ATTRS(IMPL_T, T, list) \
template <> \
template <> \
Status OpNodeProtoHelper<IMPL_T>::GetAttrs<T>( \
const std::string& name, std::vector<T>& 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<T>(attr->list(i))); \
} \
return Status::OK(); \
} \
template <> \
template <> \
Status OpNodeProtoHelper<IMPL_T>::GetAttrs<T>( \
const std::string& name, gsl::span<T> 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<size_t>(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<T>(attr->list(i)); \
} \
return Status::OK(); \
}

// Will not work for std::strings
Expand Down