Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <algorithm>
#include <cfenv>
#include <cmath>
#include <vector>
 
#include "core/quantization/quantization.h"
 
// Contains utility functions for quantizing test vectors inline.
namespace onnxruntime {
namespace test {
 
template <typename T>
inline T QuantizeTestValue(const float& value,
                           const quantization::Params<T>& params) {
  return quantization::Quantize(value, params);
}
 
template <typename T>
inline std::vector<T> QuantizeTestVector(const std::vector<float>& data,
                                         const quantization::Params<T>& params) {
  std::vector<T> result;
  result.resize(data.size());
 
  quantization::Quantize(data, result, params);
  return result;
}
 
template <typename T>
inline std::vector<T> QuantizeLinearTestVector(
    const std::vector<float>& data,
    quantization::Params<T>& out_params,
    bool force_symmetric = false) {
  std::vector<T> result;
  result.resize(data.size());
 
  out_params = quantization::QuantizeLinear(data, result, force_symmetric);
  return result;
}
 
template <typename T>
std::vector<T> ToVector(const int* value, int size) {
  std::vector<T> data(size);
  for (int i = 0; i < size; i++) {
    data[i] = static_cast<T>(value[i]);
  }
  return data;
}
 
template <typename T>
T GetMiddle(const std::vector<T>& v) {
  const auto min_max_pair = std::minmax_element(v.begin(), v.end());
  return (*(min_max_pair.first) + *(min_max_pair.second)) / 2;
}
 
}  // namespace test
}  // namespace onnxruntime