| 1005 | } |
| 1006 | |
| 1007 | DatasetPtr |
| 1008 | IVF::CalDistanceById(const float* query, const int64_t* ids, int64_t count) const { |
| 1009 | auto result = Dataset::Make(); |
| 1010 | result->Owner(true, allocator_); |
| 1011 | auto* distances = static_cast<float*>(allocator_->Allocate(sizeof(float) * count)); |
| 1012 | result->Distances(distances); |
| 1013 | if (this->use_reorder_) { |
| 1014 | auto computer = this->reorder_codes_->FactoryComputer(query); |
| 1015 | Vector<InnerIdType> inner_ids(count, allocator_); |
| 1016 | for (int64_t i = 0; i < count; ++i) { |
| 1017 | inner_ids[i] = this->label_table_->GetIdByLabel(ids[i]); |
| 1018 | } |
| 1019 | this->reorder_codes_->Query(distances, computer, inner_ids.data(), count); |
| 1020 | return result; |
| 1021 | } |
| 1022 | auto computer = this->bucket_->FactoryComputer(query); |
| 1023 | for (int64_t i = 0; i < count; ++i) { |
| 1024 | auto inner_id = this->label_table_->GetIdByLabel(ids[i]); |
| 1025 | auto location = this->get_location(inner_id); |
| 1026 | distances[i] = this->bucket_->QueryOneById(computer, location.first, location.second); |
| 1027 | } |
| 1028 | return result; |
| 1029 | } |
| 1030 | float |
| 1031 | IVF::CalcDistanceById(const float* query, int64_t id) const { |
| 1032 | if (this->use_reorder_) { |
no test coverage detected