@@ -80,11 +80,11 @@ cdef class _QuadTree:
80
80
""" Build a tree from an array of points X."""
81
81
cdef:
82
82
int i
83
- DTYPE_t [3 ] pt
84
- DTYPE_t [3 ] min_bounds, max_bounds
83
+ float32_t [3 ] pt
84
+ float32_t [3 ] min_bounds, max_bounds
85
85
86
86
# validate X and prepare for query
87
- # X = check_array(X, dtype=DTYPE_t , order='C')
87
+ # X = check_array(X, dtype=float32_t , order='C')
88
88
n_samples = X.shape[0 ]
89
89
90
90
capacity = 100
@@ -113,13 +113,13 @@ cdef class _QuadTree:
113
113
# Shrink the cells array to reduce memory usage
114
114
self ._resize(capacity = self .cell_count)
115
115
116
- cdef int insert_point(self , DTYPE_t [3 ] point, SIZE_t point_index,
117
- SIZE_t cell_id = 0 ) except - 1 nogil:
116
+ cdef int insert_point(self , float32_t [3 ] point, intp_t point_index,
117
+ intp_t cell_id = 0 ) except - 1 nogil:
118
118
""" Insert a point in the QuadTree."""
119
119
cdef int ax
120
- cdef SIZE_t selected_child
120
+ cdef intp_t selected_child
121
121
cdef Cell* cell = & self .cells[cell_id]
122
- cdef SIZE_t n_point = cell.cumulative_size
122
+ cdef intp_t n_point = cell.cumulative_size
123
123
124
124
if self .verbose > 10 :
125
125
printf(" [QuadTree] Inserting depth %li \n " , cell.depth)
@@ -177,16 +177,16 @@ cdef class _QuadTree:
177
177
return self .insert_point(point, point_index, cell_id)
178
178
179
179
# XXX: This operation is not Thread safe
180
- cdef SIZE_t _insert_point_in_new_child(
181
- self , DTYPE_t [3 ] point, Cell* cell, SIZE_t point_index, SIZE_t size = 1
180
+ cdef intp_t _insert_point_in_new_child(
181
+ self , float32_t [3 ] point, Cell* cell, intp_t point_index, intp_t size = 1
182
182
) noexcept nogil:
183
183
""" Create a child of cell which will contain point."""
184
184
185
185
# Local variable definition
186
186
cdef:
187
- SIZE_t cell_id, cell_child_id, parent_id
188
- DTYPE_t [3 ] save_point
189
- DTYPE_t width
187
+ intp_t cell_id, cell_child_id, parent_id
188
+ float32_t [3 ] save_point
189
+ float32_t width
190
190
Cell* child
191
191
int i
192
192
@@ -247,7 +247,7 @@ cdef class _QuadTree:
247
247
248
248
return cell_id
249
249
250
- cdef bint _is_duplicate(self , DTYPE_t [3 ] point1, DTYPE_t [3 ] point2) noexcept nogil:
250
+ cdef bint _is_duplicate(self , float32_t [3 ] point1, float32_t [3 ] point2) noexcept nogil:
251
251
""" Check if the two given points are equals."""
252
252
cdef int i
253
253
cdef bint res = True
@@ -256,11 +256,11 @@ cdef class _QuadTree:
256
256
res &= fabsf(point1[i] - point2[i]) <= EPSILON
257
257
return res
258
258
259
- cdef SIZE_t _select_child(self , DTYPE_t [3 ] point, Cell* cell) noexcept nogil:
259
+ cdef intp_t _select_child(self , float32_t [3 ] point, Cell* cell) noexcept nogil:
260
260
""" Select the child of cell which contains the given query point."""
261
261
cdef:
262
262
int i
263
- SIZE_t selected_child = 0
263
+ intp_t selected_child = 0
264
264
265
265
for i in range (self .n_dimensions):
266
266
# Select the correct child cell to insert the point by comparing
@@ -270,7 +270,7 @@ cdef class _QuadTree:
270
270
selected_child += 1
271
271
return cell.children[selected_child]
272
272
273
- cdef void _init_cell(self , Cell* cell, SIZE_t parent, SIZE_t depth) noexcept nogil:
273
+ cdef void _init_cell(self , Cell* cell, intp_t parent, intp_t depth) noexcept nogil:
274
274
""" Initialize a cell structure with some constants."""
275
275
cell.parent = parent
276
276
cell.is_leaf = True
@@ -280,12 +280,12 @@ cdef class _QuadTree:
280
280
for i in range (self .n_cells_per_cell):
281
281
cell.children[i] = SIZE_MAX
282
282
283
- cdef void _init_root(self , DTYPE_t [3 ] min_bounds, DTYPE_t [3 ] max_bounds
283
+ cdef void _init_root(self , float32_t [3 ] min_bounds, float32_t [3 ] max_bounds
284
284
) noexcept nogil:
285
285
""" Initialize the root node with the given space boundaries"""
286
286
cdef:
287
287
int i
288
- DTYPE_t width
288
+ float32_t width
289
289
Cell* root = & self .cells[0 ]
290
290
291
291
self ._init_cell(root, - 1 , 0 )
@@ -299,7 +299,7 @@ cdef class _QuadTree:
299
299
300
300
self .cell_count += 1
301
301
302
- cdef int _check_point_in_cell(self , DTYPE_t [3 ] point, Cell* cell
302
+ cdef int _check_point_in_cell(self , float32_t [3 ] point, Cell* cell
303
303
) except - 1 nogil:
304
304
""" Check that the given point is in the cell boundaries."""
305
305
@@ -366,8 +366,8 @@ cdef class _QuadTree:
366
366
" in children."
367
367
.format(self .n_points, self .cells[0 ].cumulative_size))
368
368
369
- cdef long summarize(self , DTYPE_t [3 ] point, DTYPE_t * results,
370
- float squared_theta = .5 , SIZE_t cell_id = 0 , long idx = 0
369
+ cdef long summarize(self , float32_t [3 ] point, float32_t * results,
370
+ float squared_theta = .5 , intp_t cell_id = 0 , long idx = 0
371
371
) noexcept nogil:
372
372
""" Summarize the tree compared to a query point.
373
373
@@ -429,7 +429,7 @@ cdef class _QuadTree:
429
429
# Otherwise, we go a higher level of resolution and into the leaves.
430
430
if cell.is_leaf or (
431
431
(cell.squared_max_width / results[idx_d]) < squared_theta):
432
- results[idx_d + 1 ] = < DTYPE_t > cell.cumulative_size
432
+ results[idx_d + 1 ] = < float32_t > cell.cumulative_size
433
433
return idx + self .n_dimensions + 2
434
434
435
435
else :
@@ -446,7 +446,7 @@ cdef class _QuadTree:
446
446
""" return the id of the cell containing the query point or raise
447
447
ValueError if the point is not in the tree
448
448
"""
449
- cdef DTYPE_t [3 ] query_pt
449
+ cdef float32_t [3 ] query_pt
450
450
cdef int i
451
451
452
452
assert len (point) == self .n_dimensions, (
@@ -458,14 +458,14 @@ cdef class _QuadTree:
458
458
459
459
return self ._get_cell(query_pt, 0 )
460
460
461
- cdef int _get_cell(self , DTYPE_t [3 ] point, SIZE_t cell_id = 0
461
+ cdef int _get_cell(self , float32_t [3 ] point, intp_t cell_id = 0
462
462
) except - 1 nogil:
463
463
""" guts of get_cell.
464
464
465
465
Return the id of the cell containing the query point or raise ValueError
466
466
if the point is not in the tree"""
467
467
cdef:
468
- SIZE_t selected_child
468
+ intp_t selected_child
469
469
Cell* cell = & self .cells[cell_id]
470
470
471
471
if cell.is_leaf:
@@ -562,7 +562,7 @@ cdef class _QuadTree:
562
562
raise ValueError (" Can't initialize array!" )
563
563
return arr
564
564
565
- cdef int _resize(self , SIZE_t capacity) except - 1 nogil:
565
+ cdef int _resize(self , intp_t capacity) except - 1 nogil:
566
566
""" Resize all inner arrays to `capacity`, if `capacity` == -1, then
567
567
double the size of the inner arrays.
568
568
@@ -574,7 +574,7 @@ cdef class _QuadTree:
574
574
with gil:
575
575
raise MemoryError ()
576
576
577
- cdef int _resize_c(self , SIZE_t capacity = SIZE_MAX) except - 1 nogil:
577
+ cdef int _resize_c(self , intp_t capacity = SIZE_MAX) except - 1 nogil:
578
578
""" Guts of _resize
579
579
580
580
Returns -1 in case of failure to allocate memory (and raise MemoryError)
@@ -598,10 +598,10 @@ cdef class _QuadTree:
598
598
self .capacity = capacity
599
599
return 0
600
600
601
- def _py_summarize (self , DTYPE_t [:] query_pt , DTYPE_t [:, :] X , float angle ):
601
+ def _py_summarize (self , float32_t [:] query_pt , float32_t [:, :] X , float angle ):
602
602
# Used for testing summarize
603
603
cdef:
604
- DTYPE_t [:] summary
604
+ float32_t [:] summary
605
605
int n_samples
606
606
607
607
n_samples = X.shape[0 ]
0 commit comments