From e8b3e449e4e8fa9e5a28526e633ffaab0c8bafd8 Mon Sep 17 00:00:00 2001 From: Dmitry Yashunin Date: Sun, 28 Aug 2022 11:46:38 +0200 Subject: [PATCH] Add cpp tests for Windows in CI --- .github/workflows/build.yml | 17 +++++++++++++++-- examples/updates_test.cpp | 25 ++++++++++++++++--------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8fde085..219efec3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,10 @@ jobs: run: python -m unittest discover --start-directory python_bindings/tests --pattern "*_test*.py" test_cpp: - runs-on: ubuntu-latest + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 @@ -34,17 +37,27 @@ jobs: mkdir build cd build cmake .. - make + if [ "$RUNNER_OS" == "Linux" ]; then + make + elif [ "$RUNNER_OS" == "Windows" ]; then + cmake --build ./ --config Release + fi + shell: bash - name: Prepare test data run: | pip install numpy cd examples python update_gen_data.py + shell: bash - name: Test run: | cd build + if [ "$RUNNER_OS" == "Windows" ]; then + cp ./Release/* ./ + fi ./searchKnnCloserFirst_test ./test_updates ./test_updates update + shell: bash diff --git a/examples/updates_test.cpp b/examples/updates_test.cpp index c8775877..d4cc995b 100644 --- a/examples/updates_test.cpp +++ b/examples/updates_test.cpp @@ -1,5 +1,7 @@ #include "../hnswlib/hnswlib.h" #include + + class StopW { std::chrono::steady_clock::time_point time_begin; @@ -22,6 +24,7 @@ class StopW } }; + /* * replacement for the openmp '#pragma omp parallel for' directive * only handles a subset of functionality (no reductions etc) @@ -81,8 +84,6 @@ inline void ParallelFor(size_t start, size_t end, size_t numThreads, Function fn std::rethrow_exception(lastException); } } - - } @@ -94,7 +95,7 @@ std::vector load_batch(std::string path, int size) assert(sizeof(datatype) == 4); std::ifstream file; - file.open(path); + file.open(path, std::ios::binary); if (!file.is_open()) { std::cout << "Cannot open " << path << "\n"; @@ -107,6 +108,7 @@ std::vector load_batch(std::string path, int size) return batch; } + template static float test_approx(std::vector &queries, size_t qsize, hnswlib::HierarchicalNSW &appr_alg, size_t vecdim, @@ -137,6 +139,7 @@ test_approx(std::vector &queries, size_t qsize, hnswlib::HierarchicalNSW< return 1.0f * correct / total; } + static void test_vs_recall(std::vector &queries, size_t qsize, hnswlib::HierarchicalNSW &appr_alg, size_t vecdim, std::vector> &answers, size_t k) @@ -155,6 +158,8 @@ test_vs_recall(std::vector &queries, size_t qsize, hnswlib::HierarchicalN efs.push_back(i); } std::cout << "ef\trecall\ttime\thops\tdistcomp\n"; + + bool test_passed = false; for (size_t ef : efs) { appr_alg.setEf(ef); @@ -171,20 +176,24 @@ test_vs_recall(std::vector &queries, size_t qsize, hnswlib::HierarchicalN std::cout << ef << "\t" << recall << "\t" << time_us_per_query << "us \t"< 0.99) { + test_passed = true; std::cout << "Recall is over 0.99! "<