File: grn_distance_instantiation.hpp

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (144 lines) | stat: -rw-r--r-- 6,854 bytes parent folder | download | duplicates (2)
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
137
138
139
140
141
142
143
144
/*
  Copyright (C) 2024  Sutou Kouhei <kou@clear-code.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#if defined(GRN_WITH_SIMSIMD) && defined(GRN_INSTANTIATION_SIMSIMD_ARCH)
namespace grn {
  namespace distance {
    namespace simsimd {
#  ifdef GRN_INSTANTIATION_EXTERN
#    define FUNC_EXPANDED(simsimd_backend,                                     \
                          c_type,                                              \
                          simsimd_type,                                        \
                          grn_metric,                                          \
                          simsimd_metric)                                      \
      float compute_distance_##grn_metric##_##simsimd_backend(                 \
        const c_type *vector_raw1,                                             \
        const c_type *vector_raw2,                                             \
        size_t n_elements);
#  else
#    define FUNC_EXPANDED(simsimd_backend,                                     \
                          c_type,                                              \
                          simsimd_type,                                        \
                          grn_metric,                                          \
                          simsimd_metric)                                      \
      float compute_distance_##grn_metric##_##simsimd_backend(                 \
        const c_type *vector_raw1,                                             \
        const c_type *vector_raw2,                                             \
        size_t n_elements)                                                     \
      {                                                                        \
        return simsimd_##simsimd_backend##_##simsimd_type##_##simsimd_metric(  \
          vector_raw1,                                                         \
          vector_raw2,                                                         \
          n_elements);                                                         \
      }
#  endif
#  define FUNC(simsimd_backend,                                                \
               c_type,                                                         \
               simsimd_type,                                                   \
               grn_metric,                                                     \
               simsimd_metric)                                                 \
    FUNC_EXPANDED(simsimd_backend,                                             \
                  c_type,                                                      \
                  simsimd_type,                                                \
                  grn_metric,                                                  \
                  simsimd_metric)

      FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, float, f32, cosine, cos)
      FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, double, f64, cosine, cos)

      FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, float, f32, inner_product, ip)
      FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, double, f64, inner_product, ip)

      FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, float, f32, l2_norm_squared, l2sq)
      FUNC(GRN_INSTANTIATION_SIMSIMD_ARCH, double, f64, l2_norm_squared, l2sq)

#  undef FUNC
#  undef FUNC_EXPANDED
    } // namespace simsimd
  } // namespace distance
} // namespace grn
#endif

#ifdef GRN_WITH_XSIMD

#  ifndef GRN_INSTANTIATION_EXTERN
#    define GRN_INSTANTIATION_EXTERN
#  endif

GRN_INSTANTIATION_EXTERN template float
grn::distance::l2_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>(
  GRN_INSTANTIATION_XSIMD_ARCH, const float *vector_raw, size_t n_elements);
GRN_INSTANTIATION_EXTERN template float
grn::distance::l2_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>(
  GRN_INSTANTIATION_XSIMD_ARCH, const double *vector_raw, size_t n_elements);

GRN_INSTANTIATION_EXTERN template float
grn::distance::inner_product::operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>(
  GRN_INSTANTIATION_XSIMD_ARCH,
  const float *vector_raw1,
  const float *vector_raw2,
  size_t n_elements);
GRN_INSTANTIATION_EXTERN template float
grn::distance::inner_product::operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>(
  GRN_INSTANTIATION_XSIMD_ARCH,
  const double *vector_raw1,
  const double *vector_raw2,
  size_t n_elements);

GRN_INSTANTIATION_EXTERN template float
grn::distance::difference_l1_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH,
                                              float>(
  GRN_INSTANTIATION_XSIMD_ARCH,
  const float *vector_raw1,
  const float *vector_raw2,
  size_t n_elements);

GRN_INSTANTIATION_EXTERN template float
grn::distance::difference_l1_norm::operator()<GRN_INSTANTIATION_XSIMD_ARCH,
                                              double>(
  GRN_INSTANTIATION_XSIMD_ARCH,
  const double *vector_raw1,
  const double *vector_raw2,
  size_t n_elements);

GRN_INSTANTIATION_EXTERN template float
grn::distance::difference_l2_norm_squared::
operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>(GRN_INSTANTIATION_XSIMD_ARCH,
                                                const float *vector_raw1,
                                                const float *vector_raw2,
                                                size_t n_elements);
GRN_INSTANTIATION_EXTERN template float
grn::distance::difference_l2_norm_squared::
operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>(GRN_INSTANTIATION_XSIMD_ARCH,
                                                 const double *vector_raw1,
                                                 const double *vector_raw2,
                                                 size_t n_elements);

GRN_INSTANTIATION_EXTERN template float
grn::distance::cosine::operator()<GRN_INSTANTIATION_XSIMD_ARCH, float>(
  GRN_INSTANTIATION_XSIMD_ARCH,
  const float *vector_raw1,
  const float *vector_raw2,
  size_t n_elements);
GRN_INSTANTIATION_EXTERN template float
grn::distance::cosine::operator()<GRN_INSTANTIATION_XSIMD_ARCH, double>(
  GRN_INSTANTIATION_XSIMD_ARCH,
  const double *vector_raw1,
  const double *vector_raw2,
  size_t n_elements);
#endif