8000 CLN BFS Style Improvement (#26096) · Micky774/scikit-learn@792833a · GitHub
[go: up one dir, main page]

Skip to content

Commit 792833a

Browse files
Micky774thomasjpfan
andcommitted
CLN BFS Style Improvement (scikit-learn#26096)
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
1 parent d013d38 commit 792833a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

sklearn/cluster/_hdbscan/_tree.pyx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,23 @@ cdef dict _compute_stability(
272272
return dict(result_pre_dict)
273273

274274

275-
cdef list bfs_from_cluster_tree(cnp.ndarray[CONDENSED_t, ndim=1, mode='c'] hierarchy, cnp.intp_t bfs_root):
275+
cdef list bfs_from_cluster_tree(
276+
cnp.ndarray[CONDENSED_t, ndim=1, mode='c'] condensed_tree,
277+
cnp.intp_t bfs_root
278+
):
276279

277-
cdef list result
278-
cdef cnp.ndarray[cnp.intp_t, ndim=1, mode='c'] to_process
280+
cdef:
281+
list result = []
282+
cnp.ndarray[cnp.intp_t, ndim=1] process_queue = (
283+
np.array([bfs_root], dtype=np.intp)
284+
)
285+
cnp.ndarray[cnp.intp_t, ndim=1] children = condensed_tree['child']
286+
cnp.intp_t[:] parents = condensed_tree['parent']
279287

280-
result = []
281-
to_process = np.array([bfs_root], dtype=np.intp)
282288

283-
while to_process.shape[0] > 0:
284-
result.extend(to_process.tolist())
285-
to_process = hierarchy['child'][np.in1d(hierarchy['parent'], to_process)]
289+
while process_queue.shape[0] > 0:
290+
result.extend(process_queue.tolist())
291+
process_queue = children[np.isin(parents, process_queue)]
286292

287293
return result
288294

0 commit comments

Comments
 (0)
0