fastquadtree 1.2.3__cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl → 1.3.1__cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fastquadtree might be problematic. Click here for more details.

@@ -29,6 +29,14 @@ G = TypeVar("G") # geometry type, e.g. Point or Bounds
29
29
  HitT = TypeVar("HitT") # raw native tuple, e.g. (id,x,y) or (id,x0,y0,x1,y1)
30
30
  ItemType = TypeVar("ItemType", bound=Item) # e.g. PointItem or RectItem
31
31
 
32
+ # Quadtree dtype to numpy dtype mapping
33
+ QUADTREE_DTYPE_TO_NP_DTYPE = {
34
+ "f32": "float32",
35
+ "f64": "float64",
36
+ "i32": "int32",
37
+ "i64": "int64",
38
+ }
39
+
32
40
 
33
41
  def _is_np_array(x: Any) -> bool:
34
42
  mod = getattr(x.__class__, "__module__", "")
@@ -48,6 +56,7 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
48
56
  "_bounds",
49
57
  "_capacity",
50
58
  "_count",
59
+ "_dtype",
51
60
  "_max_depth",
52
61
  "_native",
53
62
  "_next_id",
@@ -62,7 +71,7 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
62
71
  """Create the native engine instance."""
63
72
 
64
73
  @classmethod
65
- def _new_native_from_bytes(cls, data: bytes) -> Any:
74
+ def _new_native_from_bytes(cls, data: bytes, dtype: str) -> Any:
66
75
  """Create the native engine instance from serialized bytes."""
67
76
 
68
77
  @staticmethod
@@ -79,10 +88,12 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
79
88
  *,
80
89
  max_depth: int | None = None,
81
90
  track_objects: bool = False,
91
+ dtype: str = "f32",
82
92
  ):
83
93
  self._bounds = bounds
84
94
  self._max_depth = max_depth
85
95
  self._capacity = capacity
96
+ self._dtype = dtype
86
97
  self._native = self._new_native(bounds, capacity, max_depth)
87
98
 
88
99
  self._track_objects = bool(track_objects)
@@ -138,12 +149,13 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
138
149
  return pickle.dumps(self.to_dict())
139
150
 
140
151
  @classmethod
141
- def from_bytes(cls, data: bytes) -> Self:
152
+ def from_bytes(cls, data: bytes, dtype: str = "f32") -> Self:
142
153
  """
143
- Deserialize a quadtree from bytes.
154
+ Deserialize a quadtree from bytes. Specifiy the dtype if the original tree that was serialized used a non-default dtype.
144
155
 
145
156
  Args:
146
157
  data: Bytes representing the serialized quadtree from `to_bytes()`.
158
+ dtype: The data type used in the native engine ('f32', 'f64', 'i32', 'i64') when saved to bytes.
147
159
 
148
160
  Returns:
149
161
  A new quadtree instance with the same state as when serialized.
@@ -160,7 +172,15 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
160
172
  store_dict = in_dict["store"]
161
173
 
162
174
  qt = cls.__new__(cls) # type: ignore[call-arg]
163
- qt._native = cls._new_native_from_bytes(core_bytes)
175
+ try:
176
+ qt._native = cls._new_native_from_bytes(core_bytes, dtype=dtype)
177
+ except ValueError as ve:
178
+ raise ValueError(
179
+ "Failed to deserialize quadtree native core. "
180
+ "This may be due to a dtype mismatch. "
181
+ "Ensure the dtype used in from_bytes() matches the original tree. "
182
+ "Error details: " + str(ve)
183
+ ) from ve
164
184
 
165
185
  if store_dict is not None:
166
186
  qt._store = ObjStore.from_dict(store_dict, qt._make_item)
@@ -238,7 +258,7 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
238
258
  ) -> int:
239
259
  """
240
260
  Bulk insert with auto-assigned contiguous ids. Faster than inserting one-by-one.<br>
241
- Can accept either a Python sequence of geometries or a NumPy array of shape (N,2) or (N,4) with dtype float32.
261
+ Can accept either a Python sequence of geometries or a NumPy array of shape (N,2) or (N,4) with a dtype that matches the quadtree's dtype.
242
262
 
243
263
  If tracking is enabled, the objects will be bulk stored internally.
244
264
  If no objects are provided, the items will have obj=None (if tracking).
@@ -277,8 +297,12 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
277
297
  if geoms.size == 0:
278
298
  return 0
279
299
 
280
- if geoms.dtype != _np.float32:
281
- raise TypeError("Numpy array must use dtype float32")
300
+ # Check if dtype matches quadtree dtype
301
+ expected_np_dtype = QUADTREE_DTYPE_TO_NP_DTYPE.get(self._dtype)
302
+ if geoms.dtype != expected_np_dtype:
303
+ raise TypeError(
304
+ f"Numpy array dtype {geoms.dtype} does not match quadtree dtype {self._dtype}"
305
+ )
282
306
 
283
307
  if self._store is None:
284
308
  # Simple contiguous path with native bulk insert
Binary file
@@ -5,10 +5,17 @@ from typing import Any, Literal, Tuple, overload
5
5
 
6
6
  from ._base_quadtree import Bounds, _BaseQuadTree
7
7
  from ._item import Point, PointItem
8
- from ._native import QuadTree as _RustQuadTree # native point tree
8
+ from ._native import QuadTree as QuadTreeF32, QuadTreeF64, QuadTreeI32, QuadTreeI64
9
9
 
10
10
  _IdCoord = Tuple[int, float, float]
11
11
 
12
+ DTYPE_MAP = {
13
+ "f32": QuadTreeF32,
14
+ "f64": QuadTreeF64,
15
+ "i32": QuadTreeI32,
16
+ "i64": QuadTreeI64,
17
+ }
18
+
12
19
 
13
20
  class QuadTree(_BaseQuadTree[Point, _IdCoord, PointItem]):
14
21
  """
@@ -29,6 +36,7 @@ class QuadTree(_BaseQuadTree[Point, _IdCoord, PointItem]):
29
36
  capacity: Max number of points per node before splitting.
30
37
  max_depth: Optional max tree depth. If omitted, engine decides.
31
38
  track_objects: Enable id <-> object mapping inside Python.
39
+ dtype: Data type for coordinates and ids in the native engine. Default is 'f32'. Options are 'f32', 'f64', 'i32', 'i64'.
32
40
 
33
41
  Raises:
34
42
  ValueError: If parameters are invalid or inserts are out of bounds.
@@ -41,12 +49,14 @@ class QuadTree(_BaseQuadTree[Point, _IdCoord, PointItem]):
41
49
  *,
42
50
  max_depth: int | None = None,
43
51
  track_objects: bool = False,
52
+ dtype: str = "f32",
44
53
  ):
45
54
  super().__init__(
46
55
  bounds,
47
56
  capacity,
48
57
  max_depth=max_depth,
49
58
  track_objects=track_objects,
59
+ dtype=dtype,
50
60
  )
51
61
 
52
62
  @overload
@@ -148,14 +158,19 @@ class QuadTree(_BaseQuadTree[Point, _IdCoord, PointItem]):
148
158
  return out
149
159
 
150
160
  def _new_native(self, bounds: Bounds, capacity: int, max_depth: int | None) -> Any:
151
- if max_depth is None:
152
- return _RustQuadTree(bounds, capacity)
153
- return _RustQuadTree(bounds, capacity, max_depth=max_depth)
161
+ """Create the native engine instance."""
162
+ rust_cls = DTYPE_MAP.get(self._dtype)
163
+ if rust_cls is None:
164
+ raise TypeError(f"Unsupported dtype: {self._dtype}")
165
+ return rust_cls(bounds, capacity, max_depth)
154
166
 
155
167
  @classmethod
156
- def _new_native_from_bytes(cls, data: bytes) -> Any:
168
+ def _new_native_from_bytes(cls, data: bytes, dtype: str = "f32") -> Any:
157
169
  """Create a new native engine instance from serialized bytes."""
158
- return _RustQuadTree.from_bytes(data)
170
+ rust_cls = DTYPE_MAP.get(dtype)
171
+ if rust_cls is None:
172
+ raise TypeError(f"Unsupported dtype: {dtype}")
173
+ return rust_cls.from_bytes(data)
159
174
 
160
175
  @staticmethod
161
176
  def _make_item(id_: int, geom: Point, obj: Any | None) -> PointItem:
@@ -5,10 +5,21 @@ from typing import Any, Literal, Tuple, overload
5
5
 
6
6
  from ._base_quadtree import Bounds, _BaseQuadTree
7
7
  from ._item import RectItem
8
- from ._native import RectQuadTree as _RustRectQuadTree # native rect tree
8
+ from ._native import (
9
+ RectQuadTree as RectQuadTreeF32,
10
+ RectQuadTreeF64,
11
+ RectQuadTreeI32,
12
+ RectQuadTreeI64,
13
+ )
9
14
 
10
15
  _IdRect = Tuple[int, float, float, float, float]
11
- Point = Tuple[float, float] # only for type hints in docstrings
16
+
17
+ DTYPE_MAP = {
18
+ "f32": RectQuadTreeF32,
19
+ "f64": RectQuadTreeF64,
20
+ "i32": RectQuadTreeI32,
21
+ "i64": RectQuadTreeI64,
22
+ }
12
23
 
13
24
 
14
25
  class RectQuadTree(_BaseQuadTree[Bounds, _IdRect, RectItem]):
@@ -30,6 +41,7 @@ class RectQuadTree(_BaseQuadTree[Bounds, _IdRect, RectItem]):
30
41
  capacity: Max number of points per node before splitting.
31
42
  max_depth: Optional max tree depth. If omitted, engine decides.
32
43
  track_objects: Enable id <-> object mapping inside Python.
44
+ dtype: Data type for coordinates and ids in the native engine. Default is 'f32'. Options are 'f32', 'f64', 'i32', 'i64'.
33
45
 
34
46
  Raises:
35
47
  ValueError: If parameters are invalid or inserts are out of bounds.
@@ -42,12 +54,14 @@ class RectQuadTree(_BaseQuadTree[Bounds, _IdRect, RectItem]):
42
54
  *,
43
55
  max_depth: int | None = None,
44
56
  track_objects: bool = False,
57
+ dtype: str = "f32",
45
58
  ):
46
59
  super().__init__(
47
60
  bounds,
48
61
  capacity,
49
62
  max_depth=max_depth,
50
63
  track_objects=track_objects,
64
+ dtype=dtype,
51
65
  )
52
66
 
53
67
  @overload
@@ -84,14 +98,19 @@ class RectQuadTree(_BaseQuadTree[Bounds, _IdRect, RectItem]):
84
98
  return self._store.get_many_by_ids(self._native.query_ids(rect))
85
99
 
86
100
  def _new_native(self, bounds: Bounds, capacity: int, max_depth: int | None) -> Any:
87
- if max_depth is None:
88
- return _RustRectQuadTree(bounds, capacity)
89
- return _RustRectQuadTree(bounds, capacity, max_depth=max_depth)
101
+ """Create the native engine instance."""
102
+ rust_cls = DTYPE_MAP.get(self._dtype)
103
+ if rust_cls is None:
104
+ raise TypeError(f"Unsupported dtype: {self._dtype}")
105
+ return rust_cls(bounds, capacity, max_depth)
90
106
 
91
107
  @classmethod
92
- def _new_native_from_bytes(cls, data: bytes) -> Any:
108
+ def _new_native_from_bytes(cls, data: bytes, dtype: str = "f32") -> Any:
93
109
  """Create a new native engine instance from serialized bytes."""
94
- return _RustRectQuadTree.from_bytes(data)
110
+ rust_cls = DTYPE_MAP.get(dtype)
111
+ if rust_cls is None:
112
+ raise TypeError(f"Unsupported dtype: {dtype}")
113
+ return rust_cls.from_bytes(data)
95
114
 
96
115
  @staticmethod
97
116
  def _make_item(id_: int, geom: Bounds, obj: Any | None) -> RectItem:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastquadtree
3
- Version: 1.2.3
3
+ Version: 1.3.1
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: 3 :: Only
6
6
  Classifier: Programming Language :: Rust
@@ -26,6 +26,7 @@ Requires-Dist: mkdocs-minify-plugin ; extra == 'dev'
26
26
  Requires-Dist: maturin>=1.5 ; extra == 'dev'
27
27
  Requires-Dist: pyqtree==1.0.0 ; extra == 'dev'
28
28
  Requires-Dist: numpy ; extra == 'dev'
29
+ Requires-Dist: pre-commit ; extra == 'dev'
29
30
  Provides-Extra: dev
30
31
  License-File: LICENSE
31
32
  Summary: Rust-accelerated quadtree for Python with fast inserts, range queries, and k-NN search.
@@ -73,6 +74,7 @@ Rust-optimized quadtree with a clean Python API
73
74
  - Fast KNN and range queries
74
75
  - Optional object tracking for id ↔ object mapping
75
76
  - Fast [serialization](https://elan456.github.io/fastquadtree/benchmark/#serialization-vs-rebuild) to/from bytes
77
+ - Support for multiple data types (f32, f64, i32, i64) for coordinates
76
78
  - [100% test coverage](https://codecov.io/gh/Elan456/fastquadtree) and CI on GitHub Actions
77
79
  - Offers a drop-in [pyqtree shim](https://elan456.github.io/fastquadtree/benchmark/#pyqtree-drop-in-shim-performance-gains) that is 6.567x faster while keeping the same API
78
80
 
@@ -0,0 +1,13 @@
1
+ fastquadtree-1.3.1.dist-info/METADATA,sha256=YIM8YulIaIIme-cHchU0DJfSBmFDlcZ3c32Xep0Mr90,9747
2
+ fastquadtree-1.3.1.dist-info/WHEEL,sha256=cqfH6P_NujaeOc1olR46J5a7YgoxWJnrr5iZ1_DMqps,129
3
+ fastquadtree-1.3.1.dist-info/licenses/LICENSE,sha256=pRuvcuqIMtEUBMgvP1Bc4fOHydzeuA61c6DQoQ1pb1w,1071
4
+ fastquadtree/__init__.py,sha256=rtkveNz7rScRasTRGu1yEqzeoJfLfreJNxg21orPL-U,195
5
+ fastquadtree/_base_quadtree.py,sha256=8YXQ9txNHlOD0wFv78PU17JumL4Nb_WnZIwt1FOgMy8,16325
6
+ fastquadtree/_item.py,sha256=EDS3nJHdVtjDsuTqTZKGTZH8iWJIQ-TKxLXqvMScNPA,2405
7
+ fastquadtree/_native.abi3.so,sha256=pvI0uFkwsJTPJxYEMhjG8AcCV3YcRfgyLeX4Nw-wSXo,729512
8
+ fastquadtree/_obj_store.py,sha256=HeYFGUPYhvxBzL7Js0g0jsIxflpZS6RsXNk50rGeNlA,6522
9
+ fastquadtree/point_quadtree.py,sha256=BbTlY1hJLh5oVI7zgkjMCReO8GlPKy4pJqHHSZKo5SA,6179
10
+ fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ fastquadtree/pyqtree.py,sha256=2Khh1gCPalD4z0gb3EmqtzMoga08E9BkB0j5bwkiRPU,6076
12
+ fastquadtree/rect_quadtree.py,sha256=zD3MqFqDJRd3oJcuT5EMkuMnq_ABfMVhf-wXbidK7jE,4002
13
+ fastquadtree-1.3.1.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- fastquadtree-1.2.3.dist-info/METADATA,sha256=e0f4sEJZ-BgTh9khREHE9BtckrlT0k1fMg2JvW5NWis,9633
2
- fastquadtree-1.2.3.dist-info/WHEEL,sha256=cqfH6P_NujaeOc1olR46J5a7YgoxWJnrr5iZ1_DMqps,129
3
- fastquadtree-1.2.3.dist-info/licenses/LICENSE,sha256=pRuvcuqIMtEUBMgvP1Bc4fOHydzeuA61c6DQoQ1pb1w,1071
4
- fastquadtree/__init__.py,sha256=rtkveNz7rScRasTRGu1yEqzeoJfLfreJNxg21orPL-U,195
5
- fastquadtree/_base_quadtree.py,sha256=-umYxuVnKXd7jXcCU2VU2E55kdfUraVrhoN2lpbPQFI,15262
6
- fastquadtree/_item.py,sha256=EDS3nJHdVtjDsuTqTZKGTZH8iWJIQ-TKxLXqvMScNPA,2405
7
- fastquadtree/_native.abi3.so,sha256=SXIDwHEqzK8j1UK4kOwfg7ayZ23MFqV8hYWvvk8BFlo,540600
8
- fastquadtree/_obj_store.py,sha256=HeYFGUPYhvxBzL7Js0g0jsIxflpZS6RsXNk50rGeNlA,6522
9
- fastquadtree/point_quadtree.py,sha256=AQKZaO14wrf2PX9QLV_mAC5EjqSOQ_csmzeKAK4fZHw,5632
10
- fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- fastquadtree/pyqtree.py,sha256=2Khh1gCPalD4z0gb3EmqtzMoga08E9BkB0j5bwkiRPU,6076
12
- fastquadtree/rect_quadtree.py,sha256=JN72J8kXasl9JHL3qgiDUBNRL2H-TnkB_mgRIUYzyfE,3482
13
- fastquadtree-1.2.3.dist-info/RECORD,,