-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from nmslib/develop
Merge 0.5.0 changes to master
- Loading branch information
Showing
25 changed files
with
1,066 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
hnswlib.egg-info/ | ||
build/ | ||
dist/ | ||
tmp/ | ||
python_bindings/tests/__pycache__/ | ||
*.pyd | ||
hnswlib.cpython*.so | ||
var/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
language: python | ||
|
||
matrix: | ||
jobs: | ||
include: | ||
- python: 3.6 | ||
- python: 3.7 | ||
- name: Linux Python 3.6 | ||
os: linux | ||
python: 3.6 | ||
|
||
- name: Linux Python 3.7 | ||
os: linux | ||
python: 3.7 | ||
|
||
- name: Windows Python 3.6 | ||
os: windows | ||
language: shell # 'language: python' is an error on Travis CI Windows | ||
before_install: | ||
- choco install python --version 3.6.0 | ||
- python -m pip install --upgrade pip | ||
- python --version | ||
env: PATH=/c/Python36:/c/Python36/Scripts:$PATH | ||
|
||
- name: Windows Python 3.7 | ||
os: windows | ||
language: shell # 'language: python' is an error on Travis CI Windows | ||
before_install: | ||
- choco install python --version 3.7.0 | ||
- python -m pip install --upgrade pip | ||
- python --version | ||
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH | ||
|
||
install: | ||
- | | ||
cd python_bindings | ||
pip install -r requirements.txt | ||
python setup.py install | ||
python -m pip install . | ||
script: | ||
- | | ||
cd python_bindings | ||
python setup.py test | ||
python -m unittest discover --start-directory python_bindings/tests --pattern "*_test*.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include hnswlib/*.h | ||
include LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
pypi: dist | ||
twine upload dist/* | ||
|
||
dist: | ||
-rm dist/* | ||
pip install build | ||
python3 -m build --sdist | ||
|
||
test: | ||
python3 -m unittest discover --start-directory python_bindings/tests --pattern "*_test*.py" | ||
|
||
clean: | ||
rm -rf *.egg-info build dist tmp var tests/__pycache__ hnswlib.cpython*.so | ||
|
||
.PHONY: dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// This is a test file for testing the interface | ||
// >>> virtual std::vector<std::pair<dist_t, labeltype>> | ||
// >>> searchKnnCloserFirst(const void* query_data, size_t k) const; | ||
// of class AlgorithmInterface | ||
|
||
#include "../hnswlib/hnswlib.h" | ||
|
||
#include <assert.h> | ||
|
||
#include <vector> | ||
#include <iostream> | ||
|
||
namespace | ||
{ | ||
|
||
using idx_t = hnswlib::labeltype; | ||
|
||
void test() { | ||
int d = 4; | ||
idx_t n = 100; | ||
idx_t nq = 10; | ||
size_t k = 10; | ||
|
||
std::vector<float> data(n * d); | ||
std::vector<float> query(nq * d); | ||
|
||
std::mt19937 rng; | ||
rng.seed(47); | ||
std::uniform_real_distribution<> distrib; | ||
|
||
for (idx_t i = 0; i < n * d; ++i) { | ||
data[i] = distrib(rng); | ||
} | ||
for (idx_t i = 0; i < nq * d; ++i) { | ||
query[i] = distrib(rng); | ||
} | ||
|
||
|
||
hnswlib::L2Space space(d); | ||
hnswlib::AlgorithmInterface<float>* alg_brute = new hnswlib::BruteforceSearch<float>(&space, 2 * n); | ||
hnswlib::AlgorithmInterface<float>* alg_hnsw = new hnswlib::HierarchicalNSW<float>(&space, 2 * n); | ||
|
||
for (size_t i = 0; i < n; ++i) { | ||
alg_brute->addPoint(data.data() + d * i, i); | ||
alg_hnsw->addPoint(data.data() + d * i, i); | ||
} | ||
|
||
// test searchKnnCloserFirst of BruteforceSearch | ||
for (size_t j = 0; j < nq; ++j) { | ||
const void* p = query.data() + j * d; | ||
auto gd = alg_brute->searchKnn(p, k); | ||
auto res = alg_brute->searchKnnCloserFirst(p, k); | ||
assert(gd.size() == res.size()); | ||
size_t t = gd.size(); | ||
while (!gd.empty()) { | ||
assert(gd.top() == res[--t]); | ||
gd.pop(); | ||
} | ||
} | ||
for (size_t j = 0; j < nq; ++j) { | ||
const void* p = query.data() + j * d; | ||
auto gd = alg_hnsw->searchKnn(p, k); | ||
auto res = alg_hnsw->searchKnnCloserFirst(p, k); | ||
assert(gd.size() == res.size()); | ||
size_t t = gd.size(); | ||
while (!gd.empty()) { | ||
assert(gd.top() == res[--t]); | ||
gd.pop(); | ||
} | ||
} | ||
|
||
delete alg_brute; | ||
delete alg_hnsw; | ||
} | ||
|
||
} // namespace | ||
|
||
int main() { | ||
std::cout << "Testing ..." << std::endl; | ||
test(); | ||
std::cout << "Test ok" << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.