Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
#include <cmath>
#include "core/util/math_cpuonly.h"
 
namespace onnxruntime {
 
// Computes the squared Euclidean distance between the vectors.
template <typename T>
class Sqeuclidean {
 public:
  T operator()(const T* a1, const T* b1, size_t n) const {
    // if n is too small, Eigen is much slower than a plain loop
    T sum = 0;
    for (size_t k = 0; k != n; ++k) {
      const T t = a1[k] - b1[k];
      sum += t * t;
    }
    return sum;
  }
};
 
// Computes the Euclidean distance between the vectors.
template <typename T>
class Euclidean {
 public:
  T operator()(const T* a1, const T* b1, size_t n) const {
    // if n is too small, Eigen is much slower than a plain loop
    T sum = 0;
    for (size_t k = 0; k != n; ++k) {
      const T t = a1[k] - b1[k];
      sum += t * t;
    }
    return std::sqrt(sum);
  }
};
 
template <typename T>
class SqeuclideanWithEigen {
 public:
  T operator()(const T* a1, const T* b1, size_t n) const {
    return (ConstEigenVectorMap<T>(a1, n) - ConstEigenVectorMap<T>(b1, n)).array().square().sum();
  }
};
 
template <typename T>
class EuclideanWithEigen {
 public:
  T operator()(const T* a1, const T* b1, size_t n) const {
    return std::sqrt((ConstEigenVectorMap<T>(a1, n) - ConstEigenVectorMap<T>(b1, n)).array().square().sum());
  }
};
}  // namespace onnxruntime