diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f1027c..d05a605 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,12 @@ jobs: files: "./dist/*" docker-test: + name: Docker Test gxx${{ matrix.gxx_major }} runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + gxx_major: [14, 15] steps: - name: Checkout code @@ -103,5 +108,5 @@ jobs: - name: Build and test Docker image run: | - docker build -t spatial_graph . + docker build --build-arg GXX_MAJOR=${{ matrix.gxx_major }} -t spatial_graph . docker run --rm spatial_graph diff --git a/Dockerfile b/Dockerfile index 349d162..d5d8214 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,32 +4,36 @@ ENV DEBIAN_FRONTEND=noninteractive \ MAMBA_ROOT_PREFIX=/opt/conda \ PATH=/opt/conda/bin:$PATH +# Allow overriding the major GCC/G++ version at build time (e.g. --build-arg GXX_MAJOR=14) +ARG GXX_MAJOR=15 + RUN apt-get update && \ apt-get install -y --no-install-recommends \ git curl tar bzip2 ca-certificates && \ rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY . /app + # auto-detect arch and grab the matching micromamba binary RUN set -eux; \ arch="$(uname -m)"; \ case "$arch" in \ - x86_64) url_arch=linux-64 ;; \ - aarch64|arm64) url_arch=linux-aarch64 ;; \ - ppc64le) url_arch=linux-ppc64le ;; \ - *) echo "Unsupported arch: $arch"; exit 1 ;; \ + x86_64) url_arch=linux-64; gxx_pkg=gxx_linux-64 ;; \ + aarch64|arm64) url_arch=linux-aarch64; gxx_pkg=gxx_linux-aarch64 ;; \ + ppc64le) url_arch=linux-ppc64le; gxx_pkg=gxx_linux-ppc64le ;; \ + *) echo "Unsupported arch: $arch"; exit 1 ;; \ esac; \ curl -Ls "https://micro.mamba.pm/api/micromamba/$url_arch/latest" \ | tar -xvj -C /usr/local/bin bin/micromamba; \ chmod +x /usr/local/bin/bin/micromamba; \ mv /usr/local/bin/bin/micromamba /usr/local/bin/micromamba; \ - rmdir /usr/local/bin/bin - - -WORKDIR /app -COPY . /app + rmdir /usr/local/bin/bin; \ + micromamba create -y -n test-env -c conda-forge \ + python=3.12 pip gxx "${gxx_pkg}=${GXX_MAJOR}.*"; \ + micromamba run -n test-env pip install -e . --group test -RUN micromamba create -y -n test-env -c conda-forge python=3.12 pip compilers -RUN micromamba run -n test-env pip install -e . --group test SHELL ["micromamba", "run", "-n", "test-env", "/bin/bash", "-o", "pipefail", "-c"] diff --git a/src/spatial_graph/_rtree/src/rtree.h b/src/spatial_graph/_rtree/src/rtree.h index dfa8e73..3217e9d 100644 --- a/src/spatial_graph/_rtree/src/rtree.h +++ b/src/spatial_graph/_rtree/src/rtree.h @@ -6,6 +6,7 @@ #define RTREE_H #include +#include #include "config.h" // rtree_new returns a new rtree @@ -83,8 +84,8 @@ int rtree_delete(struct rtree *tr, const coord_t *min, const coord_t *max, const // rectangle, and perform a comparison of its data to the provided data using // a compare function. The first item that is found is deleted. // -// Returns false if the system is out of memory. -bool rtree_delete_with_comparator(struct rtree *tr, const coord_t *min, +// Returns the number of deleted items (0 or 1) or -1 if an OOM error occured. +int rtree_delete_with_comparator(struct rtree *tr, const coord_t *min, const coord_t *max, const item_t item, int (*compare)(const item_t a, const item_t b, void *udata), void *udata); diff --git a/src/spatial_graph/_rtree/wrapper_template.pyx b/src/spatial_graph/_rtree/wrapper_template.pyx index f0844b6..c378085 100644 --- a/src/spatial_graph/_rtree/wrapper_template.pyx +++ b/src/spatial_graph/_rtree/wrapper_template.pyx @@ -1,19 +1,15 @@ from libc.stdint cimport * +from libcpp cimport bool import numpy as np - -ctypedef int bool - cdef extern from *: """ - typedef int bool; - #define false 0 - #define true 1 - %if $c_distance_function #define KNN_USE_EXACT_DISTANCE %end if #define DIMS $dims + #include + #include typedef $coord_dtype.to_pyxtype() coord_t; typedef $item_dtype.base_c_type item_base_t; @@ -152,7 +148,7 @@ cdef pyx_items_t memview_to_pyx_items_t($item_dtype.to_pyxtype(add_dim=True) ite %end if -cdef bint count_iterator( +cdef bool count_iterator( const coord_t* bb_min, const coord_t* bb_max, const item_t item, @@ -174,7 +170,7 @@ cdef init_search_results_from_memview(search_results* r, $item_dtype.to_pyxtype( r.items = memview_to_pyx_items_t(items) -cdef bint search_iterator( +cdef bool search_iterator( const coord_t* bb_min, const coord_t* bb_max, const item_t item, @@ -203,7 +199,7 @@ cdef init_nearest_results_from_memview(nearest_results* r, r.distances = &distances[0] if distances is not None else NULL -cdef bint nearest_iterator( +cdef bool nearest_iterator( const item_t item, coord_t distance, void* udata