Commit 5d84296d authored by Julien Jerphanion's avatar Julien Jerphanion

[DEBUG] Compilation problems

Using pip 21.3.1 from /home/jjerphan/.local/share/miniconda3/envs/kdtree/lib/python3.9/site-packages/pip (python 3.9)
Obtaining file:///home/jjerphan/dev/kdtree
  Running command python setup.py egg_info

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
              # the asynchronous construction of the tree.
              active Counter counter = consume Counter()
              active QueryActor query_actor

          for idx_worker in range(n_workers):
              query_actor = consume QueryActor(
                                             ^
  ------------------------------------------------------------

  kdtree.pyx:785:44: Call with wrong number of arguments (expected 0, got 11)
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/home/jjerphan/dev/kdtree/setup.py", line 20, in <module>
      ext_modules=cythonize(extensions),
    File "/home/jjerphan/dev/kdtree/src/cython/Cython/Build/Dependencies.py", line 1110, in cythonize
      cythonize_one(*args)
    File "/home/jjerphan/dev/kdtree/src/cython/Cython/Build/Dependencies.py", line 1277, in cythonize_one
      raise CompileError(None, pyx_file)
  Cython.Compiler.Errors.CompileError: kdtree.pyx
  Compiling kdtree.pyx because it changed.
  [1/1] Cythonizing kdtree.pyx
  Preparing metadata (setup.py) ... error
parent 0fa3e92a
......@@ -518,28 +518,46 @@ cdef cypclass Node activable:
cdef cypclass QueryActor activable:
D_t * query_points
D_t * data_ptr
I_t * node_bounds_ptr
NodeData_t * node_data_ptr
I_t * indices_ptr
NeighborsHeaps heaps
I_t idx_worker
I_t idx_start
I_t idx_end
KDTree tree
D_t * query_points
NeighborsHeaps heaps
I_t n_features
I_t n_nodes
I_t node_bounds_ptr_offset
__init__(
self,
D_t * query_points,
KDTree tree,
D_t * data_ptr,
I_t * node_bounds_ptr,
NodeData_t * node_data_ptr,
I_t * indices_ptr,
NeighborsHeaps heaps,
I_t idx_worker,
I_t idx_start,
I_t idx_end,
I_t n_features,
I_t n_nodes,
I_t node_bounds_ptr_offset,
):
self.query_points = query_points
self.data_ptr = data_ptr
self.node_bounds_ptr = node_bounds_ptr
self.node_data_ptr = node_data_ptr
self.indices_ptr = indices_ptr
self.heaps = heaps
self.idx_worker = idx_worker
self.idx_start = idx_start
self.idx_end = idx_end
self.tree = tree
self.query_points = query_points
self.heaps = heaps
self.n_features = n_features
self.n_nodes = n_nodes
self.node_bounds_ptr_offset = node_bounds_ptr_offset
int query(self) except -1:
cdef:
......@@ -548,26 +566,47 @@ cdef cypclass QueryActor activable:
D_t reduced_dist_LB
for idx_pt in range(idx_start, idx_end):
query_point = self.query_points + idx_pt * self.tree._n_features
reduced_dist_LB = self.tree.min_rdist(0, query_point)
self._query_single_depthfirst(self.tree, 0, self.query_points,
idx_pt, self.heaps, reduced_dist_LB)
query_point = self.query_points + idx_pt * self.n_features
reduced_dist_LB = self.min_rdist(0, query_point)
self._query_single_depthfirst(0, idx_pt, reduced_dist_LB)
D_t min_rdist(self,
I_t idx_node,
D_t * pt,
) except -1:
"""Compute the minimum reduced-distance between a point and a node"""
cdef:
D_t d, d_lo, d_hi, node_min_j, node_max_j, rdist = 0.0
I_t j
for j in range(self.n_features):
node_min_j = deref(self.node_bounds_ptr + idx_node + j * self.n_nodes)
node_max_j = deref(self.node_bounds_ptr + idx_node + j * self.n_nodes + self.node_bounds_ptr_offset)
d_lo = node_min_j - pt[j]
d_hi = pt[j] - node_max_j
# We use the following identity:
#
# 0.5 * (x + abs(x)) = 0.5 * max(x, 0)
#
# twice.
d = 0.5 * ((d_lo + fabs(d_lo)) + (d_hi + fabs(d_hi)))
rdist += d ** 2
return rdist
int _query_single_depthfirst(self,
KDTree tree,
I_t idx_node,
D_t * query_points,
I_t idx_pt,
NeighborsHeaps heaps,
D_t reduced_dist_LB,
) except -1:
"""Recursive Single-tree k-neighbors query, depth-first approach"""
cdef NodeData_t node_info = tree._node_data_ptr[idx_node]
cdef NodeData_t node_info = self.node_data_ptr[idx_node]
cdef D_t sq_dist, reduced_dist_LB_1, reduced_dist_LB_2
cdef I_t i, idx_left_node, idx_right_node
cdef D_t * query_point = query_points + idx_pt * tree._n_features
cdef D_t * query_point = query_points + idx_pt * self.n_features
#------------------------------------------------------------
# Case 1: query point is outside node radius:
......@@ -583,10 +622,10 @@ cdef cypclass QueryActor activable:
for i in range(node_info.idx_start, node_info.idx_end):
sq_dist = sqeuclidean_dist(
x1=query_point,
x2=tree._data_ptr + tree._indices_ptr[i] * tree._n_features,
k=tree._n_features,
x2=self.data_ptr + self.indices_ptr[i] * self.n_features,
k=self.n_features,
)
heaps.push(idx_pt, sq_dist, tree._indices_ptr[i])
heaps.push(idx_pt, sq_dist, self.indices_ptr[i])
#------------------------------------------------------------
# Case 3: Node is not a leaf. Recursively query subnodes
......@@ -594,16 +633,16 @@ cdef cypclass QueryActor activable:
else:
idx_left_node = 2 * idx_node + 1
idx_right_node = idx_left_node + 1
reduced_dist_LB_1 = tree.min_rdist(idx_left_node, query_point)
reduced_dist_LB_2 = tree.min_rdist(idx_right_node, query_point)
reduced_dist_LB_1 = self.min_rdist(idx_left_node, query_point)
reduced_dist_LB_2 = self.min_rdist(idx_right_node, query_point)
# recursively query subnodes
if reduced_dist_LB_1 <= reduced_dist_LB_2:
self._query_single_depthfirst(tree, idx_left_node, query_points, idx_pt, heaps, reduced_dist_LB_1)
self._query_single_depthfirst(tree, idx_right_node, query_points, idx_pt, heaps, reduced_dist_LB_2)
self._query_single_depthfirst(idx_left_node, idx_pt, reduced_dist_LB_1)
self._query_single_depthfirst(idx_right_node, idx_pt, reduced_dist_LB_2)
else:
self._query_single_depthfirst(tree, idx_right_node, query_points, idx_pt, heaps, reduced_dist_LB_2)
self._query_single_depthfirst(tree, idx_left_node, query_points, idx_pt, heaps, reduced_dist_LB_1)
self._query_single_depthfirst(idx_right_node, idx_pt, reduced_dist_LB_2)
self._query_single_depthfirst(idx_left_node, idx_pt, reduced_dist_LB_1)
return 0
......@@ -744,44 +783,22 @@ cdef cypclass KDTree:
for idx_worker in range(n_workers):
query_actor = consume QueryActor(
_query_points,
self,
query_points,
self._node_bounds_ptr,
self._node_data_ptr,
self._indices_ptr,
heaps,
idx_worker,
n_points_worker * idx_worker,
min(n_points_worker * (idx_worker + 1), n_query),
n_features,
self._n_nodes,
self._node_bounds_ptr_offset,
)
query_actor.query(NULL)
heaps.sort()
D_t min_rdist(
KDTree self,
I_t idx_node,
D_t* pt,
) except -1:
"""Compute the minimum reduced-distance between a point and a node"""
cdef:
D_t d, d_lo, d_hi, node_min_j, node_max_j, rdist=0.0
I_t j
for j in range(self._n_features):
node_min_j = deref(self._node_bounds_ptr + idx_node + j * self._n_nodes)
node_max_j = deref(self._node_bounds_ptr + idx_node + j * self._n_nodes + self._node_bounds_ptr_offset)
d_lo = node_min_j - pt[j]
d_hi = pt[j] - node_max_j
# We use the following identity:
#
# 0.5 * (x + abs(x)) = 0.5 * max(x, 0)
#
# twice.
d = 0.5 * ((d_lo + fabs(d_lo)) + (d_hi + fabs(d_hi)))
rdist += d ** 2
return rdist
cdef public int main() nogil:
# Entry point for the compiled binary file
printf("empty public int main() nogil:")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment