Skip to content

Commit 69f075b

Browse files
Document bulk interfaces (#346)
1 parent dfcc1d5 commit 69f075b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

docs/source/performance.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ Use the correct query method
8080

8181
Use :py:meth:`~rtree.index.Index.count` if you only need a count and
8282
:py:meth:`~rtree.index.Index.intersection` if you only need the ids.
83-
Otherwise, lots of data may potentially be copied.
83+
Otherwise, lots of data may potentially be copied. If possible also
84+
make use of the bulk query methods suffixed with `_v`.

rtree/index.py

+40
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,18 @@ def nearest(
10471047
return self._get_ids(it, p_num_results.contents.value)
10481048

10491049
def intersection_v(self, mins, maxs):
1050+
"""Bulk intersection query for obtaining the ids of entries
1051+
which intersect with the provided bounding boxes. The return
1052+
value is a tuple consisting of two 1D NumPy arrays: one of
1053+
intersecting ids and another containing the counts for each
1054+
bounding box.
1055+
1056+
:param mins: A NumPy array of shape `(n, d)` containing the
1057+
minima to query.
1058+
1059+
:param maxs: A NumPy array of shape `(n, d)` containing the
1060+
maxima to query.
1061+
"""
10501062
import numpy as np
10511063

10521064
assert mins.shape == maxs.shape
@@ -1102,6 +1114,34 @@ def nearest_v(
11021114
strict=False,
11031115
return_max_dists=False,
11041116
):
1117+
"""Bulk ``k``-nearest query for the given bounding boxes. The
1118+
return value is a tuple consisting of, by default, two 1D NumPy
1119+
arrays: one of intersecting ids and another containing the
1120+
counts for each bounding box.
1121+
1122+
:param mins: A NumPy array of shape `(n, d)` containing the
1123+
minima to query.
1124+
1125+
:param maxs: A NumPy array of shape `(n, d)` containing the
1126+
maxima to query.
1127+
1128+
:param num_results: The maximum number of neighbors to return
1129+
for each bounding box. If there are multiple equidistant
1130+
furthest neighbors then, by default, they are *all*
1131+
returned. Hence, the actual number of results can be
1132+
greater than requested.
1133+
1134+
:param max_dists: Optional; a NumPy array of shape `(n,)`
1135+
containing the maximum distance to consider for each
1136+
bounding box.
1137+
1138+
:param strict: If True then each point will never return more
1139+
than `num_results` even in cases of equidistant furthest
1140+
neighbors.
1141+
1142+
:param return_max_dists: If True, the distance of the furthest
1143+
neighbor for each bounding box will also be returned.
1144+
"""
11051145
import numpy as np
11061146

11071147
assert mins.shape == maxs.shape

0 commit comments

Comments
 (0)