-
Notifications
You must be signed in to change notification settings - Fork 189
Use firedrake-rtree for spatial indexing
#4981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leo-collins
wants to merge
42
commits into
main
Choose a base branch
from
leo/rust-rstar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
8a07281
use rstar capi for cell location
leo-collins 85ae5e9
add logging
leo-collins 5169948
remove allgather logs
leo-collins 3b96b1e
update comments
leo-collins 281c971
fix cached property
leo-collins e8da836
merge logging
leo-collins ab58a9b
more logs
leo-collins 8f7bd74
more logging
leo-collins dcc3052
adapt to new API
leo-collins 1ffbc5d
rebase
leo-collins 94d0165
spatial index in 1D
leo-collins 37a8a3f
partial fix
leo-collins c7de8cd
fix test
leo-collins e5722a0
tidy up cython
leo-collins 613c5f1
fixes
leo-collins d1b9295
renaming and use `firedrake_rtree` package
leo-collins c291d33
firedrake-rtree fixes
leo-collins dfe8df1
remove unused stuff from rtree cython
leo-collins ebd96dc
free ids in error case
leo-collins 470c1be
add firedrake-rtree dependency
leo-collins c7eadf4
remove unnecessary stuff from petschdr
leo-collins b6dc90d
fix function at
leo-collins 4f17f7a
misc tidying
leo-collins 13d273a
fixes
leo-collins 6af9f5f
fixup mesh.py
leo-collins add7f7d
add rtree libspatialindex back in
leo-collins fe32bd8
add spatialindex to supermesh extension
leo-collins 7457c9b
add extra runtime path
leo-collins 06f65d3
lowercase r
leo-collins 1ade5a8
fix
leo-collins cbf72d4
libsupermesh fix
leo-collins 970dde5
remove library
leo-collins 6e6f3e3
docs fixes
leo-collins eb6604c
remove rtree import from setup.py
leo-collins 2a959d1
docs fix
leo-collins 0840c77
use libsupermesh branch for docs
leo-collins 695d241
installation and workflow
leo-collins a219492
review suggestions
leo-collins e352521
merge conflicts
leo-collins 5395ca6
fix docstrings
leo-collins 8b2cfbe
lint
leo-collins d82c3b1
Apply suggestions from code review
leo-collins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,103 @@ | ||
| # cython: language_level=3 | ||
|
|
||
| cimport numpy as np | ||
| import numpy as np | ||
| import ctypes | ||
| import cython | ||
| from libc.stddef cimport size_t | ||
| from libc.stdint cimport uintptr_t, uint32_t | ||
|
|
||
| cdef extern from "rtree-capi.h": | ||
| ctypedef enum RTreeError: | ||
| Success | ||
| NullPointer | ||
| InvalidDimension | ||
|
|
||
| ctypedef struct RTreeH: | ||
| pass | ||
|
|
||
| RTreeError rtree_bulk_load( | ||
| RTreeH **tree, | ||
| const double *mins, | ||
| const double *maxs, | ||
| const size_t *ids, | ||
| size_t n, | ||
| uint32_t dim | ||
| ) | ||
|
|
||
| RTreeError rtree_free(RTreeH *tree) | ||
|
|
||
|
|
||
| cdef class RTree(object): | ||
| """Python class for holding an Rtree.""" | ||
|
|
||
| cdef RTreeH* tree | ||
|
|
||
| def __cinit__(self, uintptr_t tree_handle): | ||
| self.tree = <RTreeH*>0 | ||
| if tree_handle == 0: | ||
| raise RuntimeError("invalid tree handle") | ||
| self.tree = <RTreeH*>tree_handle | ||
|
|
||
| def __dealloc__(self): | ||
| if self.tree != <RTreeH*>0: | ||
| rtree_free(self.tree) | ||
|
|
||
| @property | ||
| def ctypes(self): | ||
| """Returns a ctypes pointer to the rtree.""" | ||
| return ctypes.c_void_p(<uintptr_t> self.tree) | ||
|
|
||
|
|
||
| @cython.boundscheck(False) | ||
| @cython.wraparound(False) | ||
| def build_from_aabb(np.ndarray[np.float64_t, ndim=2, mode="c"] coords_min, | ||
| np.ndarray[np.float64_t, ndim=2, mode="c"] coords_max, | ||
| np.ndarray[np.npy_uintp, ndim=1, mode="c"] ids = None): | ||
| """Builds rtree from two arrays of shape (n, dim) containing the coordinates | ||
| of the lower and upper corners of n axis-aligned bounding boxes, and an | ||
| optional array of shape (n,) containing integer ids for each box. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| coords_min : numpy.ndarray | ||
| Lower corner coordinates of the bounding boxes, with shape `(n, dim)`. | ||
| coords_max : numpy.ndarray | ||
| Upper corner coordinates of the bounding boxes, with shape `(n, dim)`. | ||
| ids : numpy.ndarray | ||
| Optional integer ids for each box, with shape `(n,)`. If not provided, | ||
| defaults to `0, 1, ..., n-1`. | ||
|
|
||
| Returns | ||
| ------- | ||
| RTree | ||
| An RTree object containing the Rtree. | ||
| """ | ||
| cdef: | ||
| RTreeH* rtree | ||
| size_t n | ||
| size_t dim | ||
| RTreeError err | ||
|
|
||
| if coords_min.shape[0] != coords_max.shape[0] or coords_min.shape[1] != coords_max.shape[1]: | ||
| raise ValueError("coords_min and coords_max must have the same shape") | ||
|
|
||
| n = <size_t>coords_min.shape[0] | ||
| dim = <size_t>coords_min.shape[1] | ||
| if ids is None: | ||
| ids = np.arange(n, dtype=np.uintp) | ||
| elif ids.shape[0] != n: | ||
| raise ValueError("Mismatch between number of boxes and number of ids") | ||
|
|
||
| err = rtree_bulk_load( | ||
| &rtree, | ||
| <const double*>coords_min.data, | ||
| <const double*>coords_max.data, | ||
| <const size_t*>ids.data, | ||
| n, | ||
| dim | ||
| ) | ||
| if err != Success: | ||
| raise RuntimeError("rtree_bulk_load failed") | ||
|
|
||
| return RTree(<uintptr_t>rtree) | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.