Skip to content

Commit c896956

Browse files
author
Guillaume Lemaitre
committed
Handle negative n_jobs as in sklearn
1 parent 8029ea9 commit c896956

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

hdbscan/hdbscan_.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from sklearn.externals import six
2020
from warnings import warn
2121
from sklearn.utils import check_array
22+
from sklearn.externals.joblib.parallel import cpu_count
2223

2324
from scipy.sparse import csgraph
2425

@@ -239,7 +240,7 @@ def _hdbscan_boruvka_kdtree(X, min_samples=5, alpha=1.0,
239240
leaf_size = 3
240241

241242
if core_dist_n_jobs < 1:
242-
raise ValueError('Parallel core distance computation requires 1 or more jobs!')
243+
core_dist_n_jobs = max(cpu_count() + 1 + core_dist_n_jobs, 1)
243244

244245
tree = KDTree(X, metric=metric, leaf_size=leaf_size, **kwargs)
245246
alg = KDTreeBoruvkaAlgorithm(tree, min_samples, metric=metric, leaf_size=leaf_size // 3,
@@ -267,7 +268,7 @@ def _hdbscan_boruvka_balltree(X, min_samples=5, alpha=1.0,
267268
leaf_size = 3
268269

269270
if core_dist_n_jobs < 1:
270-
raise ValueError('Parallel core distance computation requires 1 or more jobs!')
271+
core_dist_n_jobs = max(cpu_count() + 1 + core_dist_n_jobs, 1)
271272

272273
tree = BallTree(X, metric=metric, leaf_size=leaf_size, **kwargs)
273274
alg = BallTreeBoruvkaAlgorithm(tree, min_samples, metric=metric, leaf_size=leaf_size // 3,
@@ -362,7 +363,8 @@ def hdbscan(X, min_cluster_size=5, min_samples=None, alpha=1.0,
362363
363364
core_dist_n_jobs : int, optional
364365
Number of parallel jobs to run in core distance computations (if
365-
supported by the specific algorithm).
366+
supported by the specific algorithm). For ``core_dist_n_jobs``
367+
below -1, (n_cpus + 1 + core_dist_n_jobs) are used.
366368
(default 4)
367369
368370

0 commit comments

Comments
 (0)