|
3 | 3 |
|
4 | 4 | #include <fstream> |
5 | 5 | #include <string> |
6 | | -#include <cstdint> |
7 | 6 | #include <cstddef> |
8 | 7 | #include <stdexcept> |
9 | 8 | #include <type_traits> |
@@ -60,135 +59,9 @@ const char* get_distance_name() { |
60 | 59 | } |
61 | 60 | } |
62 | 61 |
|
63 | | -/** |
64 | | - * Numeric types for `AnnoyIndex_` and `AnnoyData_` template parameters of `AnnoyBuilder`. |
65 | | - * These are typically set by `get_numeric_type()`. |
66 | | - */ |
67 | | -enum class NumericType : char { |
68 | | - UINT8_T, INT8_T, |
69 | | - UINT16_T, INT16_T, |
70 | | - UINT32_T, INT32_T, |
71 | | - UINT64_T, INT64_T, |
72 | | - UNSIGNED_CHAR, SIGNED_CHAR, CHAR, |
73 | | - UNSIGNED_SHORT, SHORT, |
74 | | - UNSIGNED_INT, INT, |
75 | | - UNSIGNED_LONG, LONG, |
76 | | - UNSIGNED_LONG_LONG, LONG_LONG, |
77 | | - SIZE_T, PTRDIFF_T, |
78 | | - FLOAT, DOUBLE, |
79 | | - UNKNOWN |
80 | | -}; |
81 | | - |
82 | | -/** |
83 | | - * @tparam Type_ Some integer or floating-point type, typically used as `AnnoyIndex_` or `AnnoyData_` in `AnnoyBuilder()`. |
84 | | - * @return Identity of the numeric type. |
85 | | - * |
86 | | - * For unknown types, consider using `customize_save_for_annoy_types()` to add more information to the on-disk representation during a `knncolle::Prebuilt::save()` call. |
87 | | - */ |
88 | | -template<typename Type_> |
89 | | -NumericType get_numeric_type() { |
90 | | -#ifdef UINT8_MAX |
91 | | - if constexpr(std::is_same<Type_, std::uint8_t>::value) { |
92 | | - return NumericType::UINT8_T; |
93 | | - } |
94 | | -#endif |
95 | | -#ifdef INT8_MAX |
96 | | - if constexpr(std::is_same<Type_, std::int8_t>::value) { |
97 | | - return NumericType::INT8_T; |
98 | | - } |
99 | | -#endif |
100 | | - |
101 | | -#ifdef UINT16_MAX |
102 | | - if constexpr(std::is_same<Type_, std::uint16_t>::value) { |
103 | | - return NumericType::UINT16_T; |
104 | | - } |
105 | | -#endif |
106 | | -#ifdef INT16_MAX |
107 | | - if constexpr(std::is_same<Type_, std::int16_t>::value) { |
108 | | - return NumericType::INT16_T; |
109 | | - } |
110 | | -#endif |
111 | | - |
112 | | -#ifdef UINT32_MAX |
113 | | - if constexpr(std::is_same<Type_, std::uint32_t>::value) { |
114 | | - return NumericType::UINT32_T; |
115 | | - } |
116 | | -#endif |
117 | | -#ifdef INT32_MAX |
118 | | - if constexpr(std::is_same<Type_, std::int32_t>::value) { |
119 | | - return NumericType::INT32_T; |
120 | | - } |
121 | | -#endif |
122 | | - |
123 | | -#ifdef UINT64_MAX |
124 | | - if constexpr(std::is_same<Type_, std::uint64_t>::value) { |
125 | | - return NumericType::UINT64_T; |
126 | | - } |
127 | | -#endif |
128 | | -#ifdef INT64_MAX |
129 | | - if constexpr(std::is_same<Type_, std::int64_t>::value) { |
130 | | - return NumericType::INT64_T; |
131 | | - } |
132 | | -#endif |
133 | | - |
134 | | - if constexpr(std::is_same<Type_, unsigned char>::value) { |
135 | | - return NumericType::UNSIGNED_CHAR; |
136 | | - } |
137 | | - if constexpr(std::is_same<Type_, signed char>::value) { |
138 | | - return NumericType::SIGNED_CHAR; |
139 | | - } |
140 | | - if constexpr(std::is_same<Type_, char>::value) { |
141 | | - return NumericType::CHAR; |
142 | | - } |
143 | | - |
144 | | - if constexpr(std::is_same<Type_, unsigned short>::value) { |
145 | | - return NumericType::UNSIGNED_SHORT; |
146 | | - } |
147 | | - if constexpr(std::is_same<Type_, short>::value) { |
148 | | - return NumericType::SHORT; |
149 | | - } |
150 | | - |
151 | | - if constexpr(std::is_same<Type_, unsigned int>::value) { |
152 | | - return NumericType::UNSIGNED_INT; |
153 | | - } |
154 | | - if constexpr(std::is_same<Type_, int>::value) { |
155 | | - return NumericType::INT; |
156 | | - } |
157 | | - |
158 | | - if constexpr(std::is_same<Type_, unsigned long>::value) { |
159 | | - return NumericType::UNSIGNED_LONG; |
160 | | - } |
161 | | - if constexpr(std::is_same<Type_, long>::value) { |
162 | | - return NumericType::LONG; |
163 | | - } |
164 | | - |
165 | | - if constexpr(std::is_same<Type_, unsigned long long>::value) { |
166 | | - return NumericType::UNSIGNED_LONG_LONG; |
167 | | - } |
168 | | - if constexpr(std::is_same<Type_, long long>::value) { |
169 | | - return NumericType::LONG_LONG; |
170 | | - } |
171 | | - |
172 | | - if constexpr(std::is_same<Type_, std::size_t>::value) { |
173 | | - return NumericType::SIZE_T; |
174 | | - } |
175 | | - if constexpr(std::is_same<Type_, std::ptrdiff_t>::value) { |
176 | | - return NumericType::PTRDIFF_T; |
177 | | - } |
178 | | - |
179 | | - if constexpr(std::is_same<Type_, float>::value) { |
180 | | - return NumericType::FLOAT; |
181 | | - } |
182 | | - if constexpr(std::is_same<Type_, double>::value) { |
183 | | - return NumericType::DOUBLE; |
184 | | - } |
185 | | - |
186 | | - return NumericType::UNKNOWN; |
187 | | -} |
188 | | - |
189 | 62 | /** |
190 | 63 | * Define a customized saving function to preserve type information from the Annoy index in `knncolle::Prebuilt::save()`. |
191 | | - * Users can provide their own function here, to handle types that are unknown to `get_numeric_type()` or `get_distance_name()`. |
| 64 | + * Users can provide their own function here, to handle types that are unknown to `knncolle::get_numeric_type()` or `get_distance_name()`. |
192 | 65 | * Any modifications to this function are not thread-safe and should be done in a serial section. |
193 | 66 | * |
194 | 67 | * @tparam AnnoyDistance_ An **Annoy**-compatible class to compute the distance between vectors. |
|
0 commit comments