Skip to content

Commit

Permalink
FIX Updated loop structure in hdbscan _tree.pyx to avoid error (sci…
Browse files Browse the repository at this point in the history
  • Loading branch information
Micky774 committed Jun 9, 2023
1 parent 168b4e7 commit ab48408
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sklearn/cluster/_hdbscan/_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import cython

import numpy as np

cdef extern from "numpy/arrayobject.h":
intp_t * PyArray_SHAPE(cnp.PyArrayObject *)

cdef cnp.float64_t INFTY = np.inf
cdef cnp.intp_t NOISE = -1

Expand Down Expand Up @@ -240,7 +243,7 @@ cdef dict _compute_stability(
cnp.float64_t[::1] result, births
cnp.intp_t[:] parents = condensed_tree['parent']

cnp.intp_t parent, cluster_size, result_index
cnp.intp_t parent, cluster_size, result_index, idx
cnp.float64_t lambda_val
CONDENSED_t condensed_node
cnp.float64_t[:, :] result_pre_dict
Expand All @@ -251,14 +254,15 @@ cdef dict _compute_stability(
largest_child = max(largest_child, smallest_cluster)
births = np.full(largest_child + 1, np.nan, dtype=np.float64)

births = np.full(largest_child + 1, np.nan, dtype=np.float64)
for condensed_node in condensed_tree:
for idx in range(PyArray_SHAPE(<cnp.PyArrayObject*> condensed_tree)[0]):
condensed_node = condensed_tree[idx]
births[condensed_node.child] = condensed_node.value

births[smallest_cluster] = 0.0

result = np.zeros(num_clusters, dtype=np.float64)
for condensed_node in condensed_tree:
for idx in range(PyArray_SHAPE(<cnp.PyArrayObject*> condensed_tree)[0]):
condensed_node = condensed_tree[idx]
parent = condensed_node.parent
lambda_val = condensed_node.value
cluster_size = condensed_node.cluster_size
Expand Down

0 comments on commit ab48408

Please sign in to comment.