diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index 41e36b0..6f0602d 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -192,7 +192,7 @@ jobs: steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: recursive - uses: actions/setup-python@v5 @@ -201,7 +201,7 @@ jobs: python-version: '3.10' - name: Set up QEMU if: runner.os == 'Linux' - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 with: platforms: all - name: Build wheels @@ -215,15 +215,16 @@ jobs: CIBW_BUILD_VERBOSITY: 1 CIBW_ARCHS: ${{ matrix.arch }} MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macosx_deployment_target }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: + name: artifact path: ./wheelhouse/*.whl build_sdist: name: Build source distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: recursive - uses: actions/setup-python@v5 @@ -232,8 +233,9 @@ jobs: python-version: '3.10' - name: Build sdist run: python setup.py sdist - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: + name: artifact path: dist/*.tar.gz upload_pypi: @@ -242,11 +244,11 @@ jobs: # upload to PyPI on every tag starting with 'v' if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: artifact path: dist - - uses: pypa/gh-action-pypi-publish@v1.4.2 + - uses: pypa/gh-action-pypi-publish@v1.8.11 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/cpp/prtree.h b/cpp/prtree.h index 8976963..c74aedc 100644 --- a/cpp/prtree.h +++ b/cpp/prtree.h @@ -77,8 +77,10 @@ auto list_list_to_arrays(vec> out_ll) } vec out; out.reserve(sum); - for (const auto &v : out_ll) - out.insert(out.end(), v.begin(), v.end()); + for (auto &v : out_ll) + out.insert(out.end(), + std::make_move_iterator(v.begin()), + std::make_move_iterator(v.end())); return make_tuple( std::move(as_pyarray(out_s)), @@ -104,14 +106,14 @@ static const float REBUILD_THRE = 1.25; #define unlikely(x) (x) #endif -std::string compress(std::string &data) +inline std::string compress(const std::string &data) { std::string output; snappy::Compress(data.data(), data.size(), &output); return output; } -std::string decompress(std::string &data) +inline std::string decompress(const std::string &data) { std::string output; snappy::Uncompress(data.data(), data.size(), &output); @@ -702,25 +704,22 @@ class PRTreeElement template void bfs(const std::function> &)> &func, vec> &flat_tree, const BB target) { - queue que; - auto qpush_if_intersect = [&](const size_t &i) + vec que; + que.reserve(flat_tree.size()); + auto qpush_if_intersect = [&](size_t i) { PRTreeElement &r = flat_tree[i]; - // std::cout << "i " << (long int) i << " : " << (bool) r.leaf << std::endl; if (r(target)) { - // std::cout << " is pushed" << std::endl; - que.emplace(i); + que.push_back(i); } }; - // std::cout << "size: " << flat_tree.size() << std::endl; qpush_if_intersect(0); - while (!que.empty()) + size_t qhead = 0; + while (qhead < que.size()) { - size_t idx = que.front(); - // std::cout << "idx: " << (long int) idx << std::endl; - que.pop(); + size_t idx = que[qhead++]; PRTreeElement &elem = flat_tree[idx]; if (elem.leaf) @@ -733,7 +732,8 @@ void bfs(const std::function> &)> &func for (size_t offset = 0; offset < B; offset++) { size_t jdx = idx * B + offset + 1; - qpush_if_intersect(jdx); + if (jdx < flat_tree.size()) + qpush_if_intersect(jdx); } } } diff --git a/requirements-dev.txt b/requirements-dev.txt index d129afb..758e422 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ pytest==7.1.2 pybind11==2.9.0 -cmake==3.22.4 \ No newline at end of file +cmake==3.22.4 diff --git a/requirements.txt b/requirements.txt index d291914..17e330d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -numpy>=1.16,<2.0 \ No newline at end of file +numpy>=1.16,<2.0 diff --git a/run_profile.sh b/run_profile.sh old mode 100755 new mode 100644 index efc6ee5..510d573 --- a/run_profile.sh +++ b/run_profile.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash set -e rm -rf build dist .pytest_cache @@ -8,4 +9,4 @@ python docs/run_profile.py so_path=src/python_prtree/PRTree.cpython-310-x86_64-linux-gnu.so google-pprof --callgrind $so_path build.prof > cg_build.prof google-pprof --callgrind $so_path find_all.prof > cg_find_all.prof -google-pprof --callgrind $so_path insert.prof > cg_insert.prof \ No newline at end of file +google-pprof --callgrind $so_path insert.prof > cg_insert.prof diff --git a/run_test.sh b/run_test.sh old mode 100755 new mode 100644 index 4cac5a5..e1476e8 --- a/run_test.sh +++ b/run_test.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash set -e rm -rf build dist .pytest_cache