Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include <cstring>
#include "core/graph/constants.h"
#include "core/graph/op.h"
 
using namespace ONNX_NAMESPACE;
using namespace ::onnxruntime::common;
namespace onnxruntime {
 
bool TypeUtils::IsValidAttribute(const AttributeProto& attr) {
  if (attr.name().empty()) {
    return false;
  }
 
  if (attr.type() == AttributeProto_AttributeType_UNDEFINED) {
    const int num_fields =
        attr.has_f() +
        attr.has_i() +
        attr.has_s() +
        attr.has_t() +
        attr.has_g() +
        (attr.floats_size() > 0) +
        (attr.ints_size() > 0) +
        (attr.strings_size() > 0) +
        (attr.tensors_size() > 0) +
        (attr.graphs_size() > 0);
 
    if (num_fields != 1) {
      return false;
    }
  }
  return true;
}
 
Status TypeUtils::GetType(const AttributeProto& attr, AttrType& type) {
  if (!TypeUtils::IsValidAttribute(attr)) {
    return Status(ONNXRUNTIME, FAIL, "Invalid AttributeProto.");
  }
 
  type = attr.type();
  if (AttrType::AttributeProto_AttributeType_UNDEFINED == type) {
    if (attr.has_f()) {
      type = AttrType::AttributeProto_AttributeType_FLOAT;
    } else if (attr.has_i()) {
      type = AttrType::AttributeProto_AttributeType_INT;
    } else if (attr.has_s()) {
      type = AttrType::AttributeProto_AttributeType_STRING;
    } else if (attr.has_t()) {
      type = AttrType::AttributeProto_AttributeType_TENSOR;
    } else if (attr.has_g()) {
      type = AttrType::AttributeProto_AttributeType_GRAPH;
    } else if (attr.has_sparse_tensor()) {
      type = AttrType::AttributeProto_AttributeType_SPARSE_TENSOR;
    } else if (attr.floats_size()) {
      type = AttrType::AttributeProto_AttributeType_FLOATS;
    } else if (attr.ints_size()) {
      type = AttrType::AttributeProto_AttributeType_INTS;
    } else if (attr.strings_size()) {
      type = AttrType::AttributeProto_AttributeType_STRINGS;
    } else if (attr.tensors_size()) {
      type = AttrType::AttributeProto_AttributeType_TENSORS;
    } else if (attr.graphs_size()) {
      type = AttrType::AttributeProto_AttributeType_GRAPHS;
    } else if (attr.sparse_tensors_size()) {
      type = AttrType::AttributeProto_AttributeType_SPARSE_TENSORS;
    } else {
      return Status(ONNXRUNTIME, FAIL, "Invalid AttributeProto.");
    }
  }
  return Status::OK();
}
}  // namespace onnxruntime