| 205 | std::max<size_t>(num_points, 1), |
| 206 | static_cast<size_t>(std::numeric_limits<int>::max())} |
| 207 | ) |
| 208 | )); |
| 209 | std::vector<AnnCandidate<T, PID>> best_entries(thread_count); |
| 210 | |
| 211 | #pragma omp parallel for schedule(dynamic) num_threads(thread_count) |
| 212 | for (size_t i = 0; i < num_points; ++i) { |
| 213 | auto tid = omp_get_thread_num(); |
| 214 | AnnCandidate<T, PID>& cur_entry = best_entries[tid]; |
| 215 | const T* cur_data = data + (dim * i); |
| 216 | |
| 217 | T distance = dist_func(cur_data, query, dim); |
| 218 | if (distance < cur_entry.distance) { |
| 219 | cur_entry.id = static_cast<PID>(i); |
| 220 | cur_entry.distance = distance; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | PID nearest_neighbor = 0; |
| 225 | T min_dist = std::numeric_limits<T>::max(); |
| 226 | for (auto& candi : best_entries) { |
| 227 | if (candi.distance < min_dist) { |
| 228 | nearest_neighbor = candi.id; |
| 229 | min_dist = candi.distance; |
| 230 | } |
| 231 | } |
| 232 | return nearest_neighbor; |
| 233 | } |
| 234 | |
| 235 | namespace excode_ipimpl { |
| 236 | |
| 237 | float ip16_fxu1_avx( |
| 238 | const float* __restrict__ query, const uint8_t* __restrict__ compact_code, size_t dim |
| 239 | ); |