Skip to content

Commit

Permalink
Revert "[ENH] Change assertions in integrity validation to exceptions"
Browse files Browse the repository at this point in the history
  • Loading branch information
rescrv authored Jan 2, 2025
1 parent e434afb commit 62d886a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
9 changes: 4 additions & 5 deletions hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1835,22 +1835,21 @@ namespace hnswlib
std::unordered_set<tableint> s;
for (int j = 0; j < size; j++)
{
if (data[j] < 0 || data[j] >= cur_element_count || data[j] == i)
throw std::runtime_error("HNSW Integrity failure: invalid neighbor index");
assert(data[j] > 0);
assert(data[j] < cur_element_count);
assert(data[j] != i);
inbound_connections_num[data[j]]++;
s.insert(data[j]);
connections_checked++;
}
if (s.size() != size)
throw std::runtime_error("HNSW Integrity failure: duplicate neighbor index");
assert(s.size() == size);
}
}
if (cur_element_count > 1)
{
int min1 = inbound_connections_num[0], max1 = inbound_connections_num[0];
for (int i = 0; i < cur_element_count; i++)
{
// This should always be true regardless the data is corrupted or not
assert(inbound_connections_num[i] > 0);
min1 = std::min(inbound_connections_num[i], min1);
max1 = std::max(inbound_connections_num[i], max1);
Expand Down

0 comments on commit 62d886a

Please sign in to comment.