@@ -4,7 +4,7 @@ from ._typedefs cimport ITYPE_t
4
4
5
5
cdef inline void dual_swap(floating* darr, ITYPE_t* iarr,
6
6
ITYPE_t a, ITYPE_t b) nogil:
7
- """ Swap the values at index i1 and i2 of both darr and iarr"""
7
+ """ Swap the values at index a and b of both darr and iarr"""
8
8
cdef floating dtmp = darr[a]
9
9
darr[a] = darr[b]
10
10
darr[b] = dtmp
@@ -19,15 +19,19 @@ cdef int simultaneous_sort(
19
19
ITYPE_t size
20
20
) nogil:
21
21
"""
22
- Perform a recursive quicksort on the values array, simultaneously
23
- performing the same swaps on the indices array .
22
+ Perform a recursive quicksort on the values array as to sort them ascendingly.
23
+ This simultaneously perform the swaps on both the values and the indices arrays .
24
24
25
25
The numpy equivalent is:
26
26
27
27
def simultaneous_sort(dist, idx):
28
28
i = np.argsort(dist)
29
29
return dist[i], idx[i]
30
30
31
+ Notes
32
+ -----
33
+ Arrays are manipulated via a pointer to there first element and their size
34
+ as to ease the processing of dynamically allocated buffers.
31
35
"""
32
36
# TODO: In order to support discrete distance metrics, we need to have a
33
37
# simultaneous sort which breaks ties on indices when distances are identical.
@@ -65,7 +69,7 @@ cdef int simultaneous_sort(
65
69
dual_swap(values, indices, 0 , size - 1 )
66
70
pivot_val = values[size - 1 ]
67
71
68
- # partition indices about pivot. At the end of this operation,
72
+ # Partition indices about pivot. At the end of this operation,
69
73
# pivot_idx will contain the pivot value, everything to the left
70
74
# will be smaller, and everything to the right will be larger.
71
75
store_idx = 0
@@ -76,7 +80,7 @@ cdef int simultaneous_sort(
76
80
dual_swap(values, indices, store_idx, size - 1 )
77
81
pivot_idx = store_idx
78
82
79
- # recursively sort each side of the pivot
83
+ # Recursively sort each side of the pivot
80
84
if pivot_idx > 1 :
81
85
simultaneous_sort(values, indices, pivot_idx)
82
86
if pivot_idx + 2 < size:
@@ -93,24 +97,29 @@ cdef inline int heap_push(
93
97
floating val,
94
98
ITYPE_t val_idx,
95
99
) nogil:
96
- """ Push a tuple (val, val_idx) into a fixed-size max-heap.
100
+ """ Push a tuple (val, val_idx) onto a fixed-size max-heap.
97
101
98
- The max-heap is represented as a struct of arrays where:
99
- - values is the array containing the data to construct the heap on
100
- - indices is the array containing the indices (meta-data) of each value.
102
+ The max-heap is represented as a Structure of Arrays where:
103
+ - values is the array containing the data to construct then heap with
104
+ - indices is the array containing the indices (meta-data) of each value
105
+
106
+ Notes
107
+ -----
108
+ Arrays are manipulated via a pointer to there first element and their size
109
+ as to ease the processing of dynamically allocated buffers.
101
110
"""
102
111
cdef:
103
112
ITYPE_t current_idx, left_child_idx, right_child_idx, swap_idx
104
113
105
- # check if val should be in heap
114
+ # Check if val should be in heap
106
115
if val >= values[0 ]:
107
116
return 0
108
117
109
- # insert val at position zero
118
+ # Insert val at position zero
110
119
values[0 ] = val
111
120
indices[0 ] = val_idx
112
121
113
- # descend the heap, swapping values until the max heap criterion is met
122
+ # Descend the heap, swapping values until the max heap criterion is met
114
123
current_idx = 0
115
124
while True :
116
125
left_child_idx = 2 * current_idx + 1
0 commit comments