Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "core/graph/node_attr_utils.h"
 
#include "core/common/common.h"
#include "core/framework/tensorprotoutils.h"
 
using namespace ONNX_NAMESPACE;
 
namespace onnxruntime::utils {
 
static void SetNameAndType(std::string attr_name, AttributeProto_AttributeType attr_type, AttributeProto& a) {
  a.set_name(std::move(attr_name));
  a.set_type(attr_type);
}
 
#define MAKE_BASIC_ATTR_IMPL(type, enumType, field)                 \
  AttributeProto MakeAttribute(std::string attr_name, type value) { \
    AttributeProto a;                                               \
    a.set_##field(std::move(value));                                \
    SetNameAndType(std::move(attr_name), enumType, a);              \
    return a;                                                       \
  }
 
#define MAKE_ATTR_IMPL(type, enumType, field)                       \
  AttributeProto MakeAttribute(std::string attr_name, type value) { \
    AttributeProto a;                                               \
    *(a.mutable_##field()) = std::move(value);                      \
    SetNameAndType(std::move(attr_name), enumType, a);              \
    return a;                                                       \
  }
 
#define MAKE_LIST_ATTR_IMPL(type, enumType, field)                                    \
  AttributeProto MakeAttribute(std::string attr_name, gsl::span<const type> values) { \
    AttributeProto a;                                                                 \
    auto* mutable_field = a.mutable_##field();                                        \
    for (const auto& val : values) {                                                  \
      *(mutable_field->Add()) = val;                                                  \
    }                                                                                 \
    SetNameAndType(std::move(attr_name), enumType, a);                                \
    return a;                                                                         \
  }
 
MAKE_BASIC_ATTR_IMPL(int64_t, AttributeProto_AttributeType::AttributeProto_AttributeType_INT, i)
MAKE_LIST_ATTR_IMPL(int64_t, AttributeProto_AttributeType::AttributeProto_AttributeType_INTS, ints)
 
MAKE_BASIC_ATTR_IMPL(float, AttributeProto_AttributeType::AttributeProto_AttributeType_FLOAT, f)
MAKE_LIST_ATTR_IMPL(float, AttributeProto_AttributeType::AttributeProto_AttributeType_FLOATS, floats)
 
MAKE_ATTR_IMPL(std::string, AttributeProto_AttributeType::AttributeProto_AttributeType_STRING, s)
MAKE_LIST_ATTR_IMPL(std::string, AttributeProto_AttributeType::AttributeProto_AttributeType_STRINGS, strings)
 
MAKE_ATTR_IMPL(TensorProto, AttributeProto_AttributeType::AttributeProto_AttributeType_TENSOR, t)
MAKE_LIST_ATTR_IMPL(TensorProto, AttributeProto_AttributeType::AttributeProto_AttributeType_TENSORS, tensors)
 
#if !defined(DISABLE_SPARSE_TENSORS)
MAKE_ATTR_IMPL(SparseTensorProto, AttributeProto_AttributeType::AttributeProto_AttributeType_SPARSE_TENSOR,
               sparse_tensor)
MAKE_LIST_ATTR_IMPL(SparseTensorProto, AttributeProto_AttributeType::AttributeProto_AttributeType_SPARSE_TENSORS,
                    sparse_tensors)
#endif
 
MAKE_ATTR_IMPL(TypeProto, AttributeProto_AttributeType::AttributeProto_AttributeType_TYPE_PROTO, tp)
MAKE_LIST_ATTR_IMPL(TypeProto, AttributeProto_AttributeType::AttributeProto_AttributeType_TYPE_PROTOS, type_protos)
 
MAKE_ATTR_IMPL(GraphProto, AttributeProto_AttributeType::AttributeProto_AttributeType_GRAPH, g)
MAKE_LIST_ATTR_IMPL(GraphProto, AttributeProto_AttributeType::AttributeProto_AttributeType_GRAPHS, graphs)
 
#undef MAKE_BASIC_ATTR_IMPL
#undef MAKE_ATTR_IMPL
#undef MAKE_LIST_ATTR_IMPL
 
std::pair<NodeAttributes::iterator, bool> SetNodeAttribute(AttributeProto attribute,
                                                           NodeAttributes& node_attributes) {
  ORT_ENFORCE(utils::HasName(attribute), "AttributeProto must have a name.");
  std::string name = attribute.name();
  return node_attributes.insert_or_assign(std::move(name), std::move(attribute));
}
 
}  // namespace onnxruntime::utils