Skip to content

Commit

Permalink
Merge pull request #375 from yoshoku/fix_errors
Browse files Browse the repository at this point in the history
Fix exception throwing
  • Loading branch information
yurymalkov authored Mar 22, 2022
2 parents 9d933ac + 5f074d5 commit eae971a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions hnswlib/bruteforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace hnswlib {
size_per_element_ = data_size_ + sizeof(labeltype);
data_ = (char *) malloc(maxElements * size_per_element_);
if (data_ == nullptr)
std::runtime_error("Not enough memory: BruteforceSearch failed to allocate data");
throw std::runtime_error("Not enough memory: BruteforceSearch failed to allocate data");
cur_element_count = 0;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ namespace hnswlib {
size_per_element_ = data_size_ + sizeof(labeltype);
data_ = (char *) malloc(maxelements_ * size_per_element_);
if (data_ == nullptr)
std::runtime_error("Not enough memory: loadIndex failed to allocate data");
throw std::runtime_error("Not enough memory: loadIndex failed to allocate data");

input.read(data_, maxelements_ * size_per_element_);

Expand Down
8 changes: 4 additions & 4 deletions python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Index {
l2space = new hnswlib::InnerProductSpace(dim);
normalize=true;
} else {
throw new std::runtime_error("Space name must be one of l2, ip, or cosine.");
throw std::runtime_error("Space name must be one of l2, ip, or cosine.");
}
appr_alg = NULL;
ep_added = true;
Expand Down Expand Up @@ -129,7 +129,7 @@ class Index {

void init_new_index(const size_t maxElements, const size_t M, const size_t efConstruction, const size_t random_seed) {
if (appr_alg) {
throw new std::runtime_error("The index is already initiated.");
throw std::runtime_error("The index is already initiated.");
}
cur_l = 0;
appr_alg = new hnswlib::HierarchicalNSW<dist_t>(l2space, maxElements, M, efConstruction, random_seed);
Expand Down Expand Up @@ -668,7 +668,7 @@ class BFIndex {
space = new hnswlib::InnerProductSpace(dim);
normalize=true;
} else {
throw new std::runtime_error("Space name must be one of l2, ip, or cosine.");
throw std::runtime_error("Space name must be one of l2, ip, or cosine.");
}
alg = NULL;
index_inited = false;
Expand All @@ -693,7 +693,7 @@ class BFIndex {

void init_new_index(const size_t maxElements) {
if (alg) {
throw new std::runtime_error("The index is already initiated.");
throw std::runtime_error("The index is already initiated.");
}
cur_l = 0;
alg = new hnswlib::BruteforceSearch<dist_t>(space, maxElements);
Expand Down

0 comments on commit eae971a

Please sign in to comment.