Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kdtree
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cython-plus
kdtree
Commits
228d5de5
Commit
228d5de5
authored
Nov 02, 2021
by
Julien Jerphanion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct comments
parent
bccfff3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
26 deletions
+26
-26
kdtree.pyx
kdtree.pyx
+26
-26
No files found.
kdtree.pyx
View file @
228d5de5
...
@@ -21,7 +21,7 @@ cdef lock Scheduler scheduler
...
@@ -21,7 +21,7 @@ cdef lock Scheduler scheduler
cdef
D_t
INF
=
1e38
cdef
D_t
INF
=
1e38
# NOTE: The following extern definition is used to interface
# NOTE: The following extern definition is used to interface
# std::nth_element, a robust partitioning algorithm, in Cython
# std::nth_element, a robust partitioning algorithm, in Cython
cdef
extern
from
*
:
cdef
extern
from
*
:
"""
"""
#include <algorithm>
#include <algorithm>
...
@@ -73,10 +73,10 @@ cdef extern from *:
...
@@ -73,10 +73,10 @@ cdef extern from *:
cdef
cypclass
Counter
activable
:
cdef
cypclass
Counter
activable
:
""" A simple Counter.
""" A simple Counter.
This can be useful for synchronisation for the caller after
This can be useful for synchronisation for the caller after
triggering the actors logic as it wait for the value of
triggering the actors logic as it wait for the value of
the Cou
tn
er to reach a given one before moving on.
the Cou
nt
er to reach a given one before moving on.
"""
"""
I_t
_n
I_t
_n
...
@@ -98,7 +98,7 @@ cdef cypclass Counter activable:
...
@@ -98,7 +98,7 @@ cdef cypclass Counter activable:
cdef
cypclass
Container
activable
:
cdef
cypclass
Container
activable
:
""" A simple wrapper of an array.
""" A simple wrapper of an array.
The wrapped array is passed by the initial caller which then
The wrapped array is passed by the initial caller which then
trigger the actors logic modifying it.
trigger the actors logic modifying it.
...
@@ -331,17 +331,17 @@ cdef cypclass NeighborsHeap activable:
...
@@ -331,17 +331,17 @@ cdef cypclass NeighborsHeap activable:
cdef
cypclass
Node
activable
:
cdef
cypclass
Node
activable
:
"""A KDTree Node
"""A KDTree Node
Node delegate tasks to their children Nodes.
Node delegate
s
tasks to their children Nodes.
Some Nodes are set as Leaves when they are associated
Some Nodes are set as Leaves when they are associated
to ``leaf_size`` or less points.
to ``leaf_size`` or less points.
Leafs are terminal Nodes and do not have children.
Leafs are terminal Nodes and do not have children.
"""
"""
# Reference to the head of the allocated arrays
# Reference to the head of the allocated arrays
# data gets not modified via _data_ptr
# data gets not modified via _data_ptr
D_t
*
_data_ptr
D_t
*
_data_ptr
I_t
*
_indices_ptr
I_t
*
_indices_ptr
...
@@ -369,7 +369,7 @@ cdef cypclass Node activable:
...
@@ -369,7 +369,7 @@ cdef cypclass Node activable:
# We use this to allow using actors for initialisation
# We use this to allow using actors for initialisation
# because __init__ can't be reified.
# because __init__ can't be reified.
void
build_node
(
void
build_node
(
self
,
self
,
D_t
*
data_ptr
,
D_t
*
data_ptr
,
...
@@ -396,19 +396,19 @@ cdef cypclass Node activable:
...
@@ -396,19 +396,19 @@ cdef cypclass Node activable:
if
(
end
-
start
<=
leaf_size
):
if
(
end
-
start
<=
leaf_size
):
self
.
_is_leaf
=
True
self
.
_is_leaf
=
True
# Adding to the global counter the number
# Adding to the global counter the number
# of samples the leaf is responsible of
# of samples the leaf is responsible of
.
counter
.
add
(
NULL
,
end
-
start
)
counter
.
add
(
NULL
,
end
-
start
)
return
return
# We partition the samples in two nodes on a given dimension,
# We partition the samples in two nodes on a given dimension,
# with the middle point as a pivot
# with the middle point as a pivot
.
partition_node_indices
(
data_ptr
,
indices_ptr
,
start
,
mid
,
end
,
dim
,
n_dims
)
partition_node_indices
(
data_ptr
,
indices_ptr
,
start
,
mid
,
end
,
dim
,
n_dims
)
self
.
_point
=
data_ptr
+
mid
self
.
_point
=
data_ptr
+
mid
self
.
_left
=
consume
Node
()
self
.
_left
=
consume
Node
()
self
.
_right
=
consume
Node
()
self
.
_right
=
consume
Node
()
# Recursing on both partition
# Recursing on both partition
s.
self
.
_left
.
build_node
(
NULL
,
self
.
_left
.
build_node
(
NULL
,
data_ptr
,
indices_ptr
,
data_ptr
,
indices_ptr
,
leaf_size
,
n_dims
,
next_dim
,
leaf_size
,
n_dims
,
next_dim
,
...
@@ -429,23 +429,23 @@ cdef cypclass Node activable:
...
@@ -429,23 +429,23 @@ cdef cypclass Node activable:
D_t
tmp
D_t
tmp
if
self
.
_is_leaf
:
if
self
.
_is_leaf
:
# Computing all the euclideans distances here
# Computing all the euclideans distances here
.
for
j
in
range
(
self
.
_start
,
self
.
_end
):
for
j
in
range
(
self
.
_start
,
self
.
_end
):
dist
=
0
dist
=
0
for
k
in
range
(
self
.
_n_dims
):
for
k
in
range
(
self
.
_n_dims
):
tmp
=
(
tmp
=
(
query_points
[
i
*
self
.
_n_dims
+
k
]
-
query_points
[
i
*
self
.
_n_dims
+
k
]
-
self
.
_data_ptr
[
self
.
_indices_ptr
[
j
]
*
self
.
_n_dims
+
k
]
self
.
_data_ptr
[
self
.
_indices_ptr
[
j
]
*
self
.
_n_dims
+
k
]
)
)
dist
+=
tmp
*
tmp
dist
+=
tmp
*
tmp
# The heap is
doing the smart work of keeping
# The heap is
responsible for keeping the closest
#
the closest points for each query point i
#
points for each query point i.
heaps
.
push
(
NULL
,
i
,
dist
,
self
.
_indices_ptr
[
j
])
heaps
.
push
(
NULL
,
i
,
dist
,
self
.
_indices_ptr
[
j
])
return
return
# TODO: one can implement a pruning strategy here
# TODO: one can implement a pruning strategy here
.
self
.
_left
.
query
(
NULL
,
query_points
,
i
,
heaps
)
self
.
_left
.
query
(
NULL
,
query_points
,
i
,
heaps
)
self
.
_right
.
query
(
NULL
,
query_points
,
i
,
heaps
)
self
.
_right
.
query
(
NULL
,
query_points
,
i
,
heaps
)
...
@@ -481,10 +481,10 @@ cdef cypclass KDTree:
...
@@ -481,10 +481,10 @@ cdef cypclass KDTree:
cdef
I_t
n
=
X
.
shape
[
0
]
cdef
I_t
n
=
X
.
shape
[
0
]
cdef
I_t
d
=
X
.
shape
[
1
]
cdef
I_t
d
=
X
.
shape
[
1
]
cdef
I_t
initialised
=
0
cdef
I_t
initialised
=
0
# Accessing _SC_NPROCESSORS_ONLN does not return the
# Accessing _SC_NPROCESSORS_ONLN does not return the
# effective number of threads which were assigned to
# effective number of threads which were assigned to
# this task using `taskset(1)` for instance.
# this task using `taskset(1)` for instance.
#
#
# This OpenMP API is a workable way to access it.
# This OpenMP API is a workable way to access it.
cdef
I_t
num_workers
=
omp_get_max_threads
()
cdef
I_t
num_workers
=
omp_get_max_threads
()
...
@@ -509,10 +509,10 @@ cdef cypclass KDTree:
...
@@ -509,10 +509,10 @@ cdef cypclass KDTree:
# When object are activated (set as Actors), methods
# When object are activated (set as Actors), methods
# are reified. When using those reified methods
# are reified. When using those reified methods
# a new argument is prepredend for a predicate,
# a new argument is prepredend for a predicate,
# which we aren't using
using
here, hence the extra NULL.
# which we aren't using here, hence the extra NULL.
#
#
# Also using this separate method allowing using actors
# Also using this separate method allowing using actors
# because __init__ can't be reified.
# because __init__ can't be reified.
self
.
_root
.
build_node
(
NULL
,
self
.
_root
.
build_node
(
NULL
,
self
.
_data_ptr
,
self
.
_data_ptr
,
self
.
_indices_ptr
,
self
.
_indices_ptr
,
...
@@ -526,7 +526,7 @@ cdef cypclass KDTree:
...
@@ -526,7 +526,7 @@ cdef cypclass KDTree:
initialised
=
counter
.
value
(
NULL
).
getIntResult
()
initialised
=
counter
.
value
(
NULL
).
getIntResult
()
counter
.
reset
(
NULL
)
counter
.
reset
(
NULL
)
void
__dealloc__
(
self
):
void
__dealloc__
(
self
):
scheduler
.
finish
()
scheduler
.
finish
()
...
@@ -557,7 +557,7 @@ cdef cypclass KDTree:
...
@@ -557,7 +557,7 @@ cdef cypclass KDTree:
completed_queries
=
heaps
.
n_pushes
(
NULL
).
getIntResult
()
completed_queries
=
heaps
.
n_pushes
(
NULL
).
getIntResult
()
heaps
.
sort
(
NULL
)
heaps
.
sort
(
NULL
)
while
not
(
heaps
.
is_sorted
(
NULL
).
getIntResult
()):
while
not
(
heaps
.
is_sorted
(
NULL
).
getIntResult
()):
pass
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment