@@ -4,7 +4,7 @@ from ._typedefs cimport ITYPE_t
44
55cdef inline void dual_swap(floating* darr, ITYPE_t* iarr,
66 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"""
88 cdef floating dtmp = darr[a]
99 darr[a] = darr[b]
1010 darr[b] = dtmp
@@ -19,15 +19,19 @@ cdef int simultaneous_sort(
1919 ITYPE_t size
2020) nogil:
2121 """
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 .
2424
2525 The numpy equivalent is:
2626
2727 def simultaneous_sort(dist, idx):
2828 i = np.argsort(dist)
2929 return dist[i], idx[i]
3030
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.
3135 """
3236 # TODO: In order to support discrete distance metrics, we need to have a
3337 # simultaneous sort which breaks ties on indices when distances are identical.
@@ -65,7 +69,7 @@ cdef int simultaneous_sort(
6569 dual_swap(values, indices, 0 , size - 1 )
6670 pivot_val = values[size - 1 ]
6771
68- # partition indices about pivot. At the end of this operation,
72+ # Partition indices about pivot. At the end of this operation,
6973 # pivot_idx will contain the pivot value, everything to the left
7074 # will be smaller, and everything to the right will be larger.
7175 store_idx = 0
@@ -76,7 +80,7 @@ cdef int simultaneous_sort(
7680 dual_swap(values, indices, store_idx, size - 1 )
7781 pivot_idx = store_idx
7882
79- # recursively sort each side of the pivot
83+ # Recursively sort each side of the pivot
8084 if pivot_idx > 1 :
8185 simultaneous_sort(values, indices, pivot_idx)
8286 if pivot_idx + 2 < size:
@@ -93,24 +97,29 @@ cdef inline int heap_push(
9397 floating val,
9498 ITYPE_t val_idx,
9599) 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.
97101
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.
101110 """
102111 cdef:
103112 ITYPE_t current_idx, left_child_idx, right_child_idx, swap_idx
104113
105- # check if val should be in heap
114+ # Check if val should be in heap
106115 if val >= values[0 ]:
107116 return 0
108117
109- # insert val at position zero
118+ # Insert val at position zero
110119 values[0 ] = val
111120 indices[0 ] = val_idx
112121
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
114123 current_idx = 0
115124 while True :
116125 left_child_idx = 2 * current_idx + 1
0 commit comments