Исходный код СУБД 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "debug.h"
#include <sstream>
#include "core/common/common.h"
#include "flags.h"
 
namespace onnxruntime {
namespace lazytensor {
std::string ToString(const c10::IValue& value) {
  std::stringstream ss;
  if (value.isTensor()) {
    // Produce, e.g., Tensor<Float>(1024, 128)@cpu.
    const auto& tensor = value.toTensor();
    ss << "Tensor"
       << "<" << c10::toString(tensor.scalar_type()) << ">";
    if (tensor.sizes().empty()) {
    } else {
      ss << "(";
      for (int i = 0; i < tensor.dim(); i++) {
        ss << tensor.sizes()[i];
        if (i != tensor.dim() - 1) {
          ss << ",";
        }
      }
      ss << ")";
    }
    ss << "@" << tensor.device();
  } else if (value.isScalar()) {
    // Produce, e.g., Scalar<Float>, which is always on CPU.
    ss << "Scalar<" << c10::toString(value.toScalar().type()) << ">";
  } else {
    ORT_THROW("Unsupported type.");
  }
  return ss.str();
}
 
// Print elements in the stack.
std::string ToString(const at::ArrayRef<c10::IValue>& values) {
  std::stringstream ss;
  for (size_t i = 0; i < values.size(); i++) {
    ss << ToString(values.at(i));
    if (i != values.size() - 1) {
      ss << ", ";
    }
  }
  return ss.str();
}
 
std::string ToString(const torch::jit::Value& value) {
  auto type = value.type();
  return type->str();
}
 
std::string ToString(const torch::jit::Node& node) {
  std::stringstream ss;
  ss << node.kind().toDisplayString() << "(";
  for (size_t i = 0; i < node.inputs().size(); i++) {
    ss << ToString(*node.inputs().at(i));
    if (i != node.inputs().size() - 1) {
      ss << ", ";
    }
  }
  ss << ") -> (";
  for (size_t i = 0; i < node.outputs().size(); i++) {
    ss << ToString(*node.outputs().at(i));
    if (i != node.outputs().size() - 1) {
      ss << ", ";
    }
  }
  ss << ")";
  return ss.str();
}
 
bool CompareTensor(
    const at::Tensor& left, const at::Tensor& right) {
  if (left.sizes() != right.sizes()) {
    return false;
  }
  if (left.scalar_type() != right.scalar_type()) {
    return false;
  }
  if (left.device() != right.device()) {
    return false;
  }
  if (CheckTensorContent() &&
      !at::allclose(left, right, RelativeTolerance(), AbsoluteTolerance())) {
    return false;
  }
  return true;
}
 
bool CompareScalar(
    const at::Scalar& left, const at::Scalar& right) {
  if (left.type() != right.type()) {
    return false;
  }
  if (CheckTensorContent()) {
    if (left.isFloatingPoint()) {
      return left.toDouble() == right.toDouble();
    } else if (left.isIntegral(false)) {
      return left.toLong() == right.toLong();
    } else if (left.isBoolean()) {
      return left.toBool() == right.toBool();
    } else {
      return false;
    }
  }
  return true;
}
 
bool Compare(const c10::IValue& left, const c10::IValue& right) {
  if (left.isTensor() && right.isTensor()) {
    return CompareTensor(left.toTensor(), right.toTensor());
  } else if (left.isScalar() && right.isScalar()) {
    return CompareScalar(left.toScalar(), right.toScalar());
  } else {
    return false;
  }
}
 
bool CompareStack(
    const torch::jit::Stack& left, const torch::jit::Stack& right) {
  if (left.size() != right.size()) {
    return false;
  }
  for (size_t i = 0; i < left.size(); i++) {
    if (!Compare(left[i], right[i])) {
      return false;
    }
  }
  return true;
}
}  // namespace lazytensor
}  // namespace onnxruntime