Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception throwing #375

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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