Skip to content

Commit

Permalink
fix get data
Browse files Browse the repository at this point in the history
  • Loading branch information
yurymalkov committed Dec 5, 2018
1 parent ece9c2b commit e53fc53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions hnswlib/hnswalg.h
Expand Up @@ -20,7 +20,7 @@ namespace hnswlib {
typedef unsigned int tableint;
typedef unsigned int linklistsizeint;

template<typename dist_t, typename data_t>
template<typename dist_t>
class HierarchicalNSW : public AlgorithmInterface<dist_t> {
public:

Expand Down Expand Up @@ -600,6 +600,7 @@ namespace hnswlib {
revSize_ = 1.0 / mult_;
ef_ = 10;
for (size_t i = 0; i < cur_element_count; i++) {
label_lookup_[getExternalLabel(i)]=i;
unsigned int linkListSize;
readBinaryPOD(input, linkListSize);
if (linkListSize == 0) {
Expand All @@ -617,6 +618,7 @@ namespace hnswlib {
return;
}

template<typename data_t>
std::vector<data_t> getDataByLabel(labeltype label)
{
tableint label_c = label_lookup_[label];
Expand Down Expand Up @@ -645,6 +647,7 @@ namespace hnswlib {
throw std::runtime_error("The number of elements exceeds the specified limit");
};
cur_c = cur_element_count;
label_lookup_[label] = cur_c; // expected unique, if not will overwrite
cur_element_count++;
}
std::unique_lock <std::mutex> lock_el(link_list_locks_[cur_c]);
Expand All @@ -667,7 +670,7 @@ namespace hnswlib {
// Initialisation of the data and label
memcpy(getExternalLabeLp(cur_c), &label, sizeof(labeltype));
memcpy(getDataByInternalId(cur_c), data_point, data_size_);
label_lookup_[label] = cur_c; // expected unique, if not will overwrite


if (curlevel) {
linkLists_[cur_c] = (char *) malloc(size_links_per_element_ * curlevel + 1);
Expand Down
8 changes: 4 additions & 4 deletions python_bindings/bindings.cpp
Expand Up @@ -97,7 +97,7 @@ class Index {
throw new std::runtime_error("The index is already initiated.");
}
cur_l = 0;
appr_alg = new hnswlib::HierarchicalNSW<dist_t, data_t>(l2space, maxElements, M, efConstruction, random_seed);
appr_alg = new hnswlib::HierarchicalNSW<dist_t>(l2space, maxElements, M, efConstruction, random_seed);
index_inited = true;
ep_added = false;
}
Expand All @@ -119,7 +119,7 @@ class Index {
std::cerr<<"Warning: Calling load_index for an already inited index. Old index is being deallocated.";
delete appr_alg;
}
appr_alg = new hnswlib::HierarchicalNSW<dist_t, data_t>(l2space, path_to_index, false, max_elements);
appr_alg = new hnswlib::HierarchicalNSW<dist_t>(l2space, path_to_index, false, max_elements);
cur_l = appr_alg->cur_element_count;
}
void normalize_vector(float *data, float *norm_array){
Expand Down Expand Up @@ -230,7 +230,7 @@ class Index {

std::vector<std::vector<data_t>> data;
for (auto id : ids) {
data.push_back(appr_alg->getDataByLabel(id));
data.push_back(appr_alg->template getDataByLabel<data_t>(id));
}
return data;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ class Index {
bool normalize;
int num_threads_default;
hnswlib::labeltype cur_l;
hnswlib::HierarchicalNSW<dist_t, data_t> *appr_alg;
hnswlib::HierarchicalNSW<dist_t> *appr_alg;
hnswlib::SpaceInterface<float> *l2space;

~Index() {
Expand Down

0 comments on commit e53fc53

Please sign in to comment.