Commit cb21e78e authored by Julien Jerphanion's avatar Julien Jerphanion

Notes from Tue 23 Nov 12:17:31 CET 2021 meeting

parent 5d84296d
SHELL = /bin/bash SHELL = /bin/bash
PROJECT = kdtree PROJECT = kdtree
# This can be change to use venv directly
VENV_PATH=`conda info --base`/envs/${PROJECT} VENV_PATH=`conda info --base`/envs/${PROJECT}
PIP_EXECUTABLE=${VENV_PATH}/bin/pip PIP_EXECUTABLE=${VENV_PATH}/bin/pip
PYTHON_EXECUTABLE=${VENV_PATH}/bin/python PYTHON_EXECUTABLE=${VENV_PATH}/bin/python
......
...@@ -518,12 +518,13 @@ cdef cypclass Node activable: ...@@ -518,12 +518,13 @@ cdef cypclass Node activable:
cdef cypclass QueryActor activable: cdef cypclass QueryActor activable:
D_t * query_points D_t * query_points_ptr
D_t * data_ptr D_t * data_ptr
I_t * node_bounds_ptr I_t * node_bounds_ptr
NodeData_t * node_data_ptr NodeData_t * node_data_ptr
I_t * indices_ptr I_t * indices_ptr
NeighborsHeaps heaps NeighborsHeaps heaps
I_t idx_worker I_t idx_worker
I_t idx_start I_t idx_start
I_t idx_end I_t idx_end
...@@ -533,7 +534,7 @@ cdef cypclass QueryActor activable: ...@@ -533,7 +534,7 @@ cdef cypclass QueryActor activable:
__init__( __init__(
self, self,
D_t * query_points, D_t * query_points_ptr,
D_t * data_ptr, D_t * data_ptr,
I_t * node_bounds_ptr, I_t * node_bounds_ptr,
NodeData_t * node_data_ptr, NodeData_t * node_data_ptr,
...@@ -544,9 +545,9 @@ cdef cypclass QueryActor activable: ...@@ -544,9 +545,9 @@ cdef cypclass QueryActor activable:
I_t idx_end, I_t idx_end,
I_t n_features, I_t n_features,
I_t n_nodes, I_t n_nodes,
I_t node_bounds_ptr_offset, I_t node_bounds_ptr_offset
): ):
self.query_points = query_points self.query_points_ptr = query_points_ptr
self.data_ptr = data_ptr self.data_ptr = data_ptr
self.node_bounds_ptr = node_bounds_ptr self.node_bounds_ptr = node_bounds_ptr
self.node_data_ptr = node_data_ptr self.node_data_ptr = node_data_ptr
...@@ -565,10 +566,21 @@ cdef cypclass QueryActor activable: ...@@ -565,10 +566,21 @@ cdef cypclass QueryActor activable:
D_t * query_point D_t * query_point
D_t reduced_dist_LB D_t reduced_dist_LB
# [[1 2 3],
# [4 5 6],
# [7 8 9]]
# F-ordered: [1 4 7 2 5 8 3 6 9]
for idx_pt in range(idx_start, idx_end): for idx_pt in range(idx_start, idx_end):
query_point = self.query_points + idx_pt * self.n_features # We use C-ordering
reduced_dist_LB = self.min_rdist(0, query_point) query_point = self.query_points_ptr + idx_pt * self.n_features
self._query_single_depthfirst(0, idx_pt, reduced_dist_LB) reduced_dist_LB = self.min_rdist(idx_node=0, pt=query_point)
self._query_single_depthfirst(
idx_node=0,
idx_pt=idx_pt,
reduced_dist_LB=reduced_dist_LB,
)
D_t min_rdist(self, D_t min_rdist(self,
I_t idx_node, I_t idx_node,
...@@ -580,6 +592,7 @@ cdef cypclass QueryActor activable: ...@@ -580,6 +592,7 @@ cdef cypclass QueryActor activable:
I_t j I_t j
for j in range(self.n_features): for j in range(self.n_features):
# We use C-ordering
node_min_j = deref(self.node_bounds_ptr + idx_node + j * self.n_nodes) 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) node_max_j = deref(self.node_bounds_ptr + idx_node + j * self.n_nodes + self.node_bounds_ptr_offset)
...@@ -606,7 +619,7 @@ cdef cypclass QueryActor activable: ...@@ -606,7 +619,7 @@ cdef cypclass QueryActor activable:
cdef D_t sq_dist, reduced_dist_LB_1, reduced_dist_LB_2 cdef D_t sq_dist, reduced_dist_LB_1, reduced_dist_LB_2
cdef I_t i, idx_left_node, idx_right_node cdef I_t i, idx_left_node, idx_right_node
cdef D_t * query_point = query_points + idx_pt * self.n_features cdef D_t * query_point_ptr = query_points_ptr + idx_pt * self.n_features
#------------------------------------------------------------ #------------------------------------------------------------
# Case 1: query point is outside node radius: # Case 1: query point is outside node radius:
...@@ -621,7 +634,7 @@ cdef cypclass QueryActor activable: ...@@ -621,7 +634,7 @@ cdef cypclass QueryActor activable:
elif node_info.is_leaf: elif node_info.is_leaf:
for i in range(node_info.idx_start, node_info.idx_end): for i in range(node_info.idx_start, node_info.idx_end):
sq_dist = sqeuclidean_dist( sq_dist = sqeuclidean_dist(
x1=query_point, x1=query_point_ptr,
x2=self.data_ptr + self.indices_ptr[i] * self.n_features, x2=self.data_ptr + self.indices_ptr[i] * self.n_features,
k=self.n_features, k=self.n_features,
) )
...@@ -633,8 +646,8 @@ cdef cypclass QueryActor activable: ...@@ -633,8 +646,8 @@ cdef cypclass QueryActor activable:
else: else:
idx_left_node = 2 * idx_node + 1 idx_left_node = 2 * idx_node + 1
idx_right_node = idx_left_node + 1 idx_right_node = idx_left_node + 1
reduced_dist_LB_1 = self.min_rdist(idx_left_node, query_point) reduced_dist_LB_1 = self.min_rdist(idx_left_node, query_point_ptr)
reduced_dist_LB_2 = self.min_rdist(idx_right_node, query_point) reduced_dist_LB_2 = self.min_rdist(idx_right_node, query_point_ptr)
# recursively query subnodes # recursively query subnodes
if reduced_dist_LB_1 <= reduced_dist_LB_2: if reduced_dist_LB_1 <= reduced_dist_LB_2:
...@@ -765,7 +778,7 @@ cdef cypclass KDTree: ...@@ -765,7 +778,7 @@ cdef cypclass KDTree:
I_t n_query = query_points.shape[0] I_t n_query = query_points.shape[0]
I_t n_features = query_points.shape[1] I_t n_features = query_points.shape[1]
I_t n_neighbors = knn_indices.shape[1] I_t n_neighbors = knn_indices.shape[1]
D_t * _query_points = <D_t *> query_points.data D_t * query_points_ptr = <D_t *> query_points.data
D_t rdist_lower_bound D_t rdist_lower_bound
I_t n_workers = omp_get_max_threads() I_t n_workers = omp_get_max_threads()
I_t n_points_worker = <I_t> ceil(n_query / n_workers) I_t n_points_worker = <I_t> ceil(n_query / n_workers)
...@@ -783,7 +796,8 @@ cdef cypclass KDTree: ...@@ -783,7 +796,8 @@ cdef cypclass KDTree:
for idx_worker in range(n_workers): for idx_worker in range(n_workers):
query_actor = consume QueryActor( query_actor = consume QueryActor(
query_points, query_points_ptr,
self._data_ptr,
self._node_bounds_ptr, self._node_bounds_ptr,
self._node_data_ptr, self._node_data_ptr,
self._indices_ptr, self._indices_ptr,
......
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