Skip to content

Commit 281e141

Browse files
committed
Correctly translate numpy code
1 parent efa25da commit 281e141

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

hdbscan/hdbscan_.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,43 @@
4646
def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
4747

4848
def within_tol(x, y, atol, rtol):
49-
with errstate(invalid='ignore'):
50-
result = less_equal(abs(x-y), atol + rtol * abs(y))
51-
if isscalar(a) and isscalar(b):
49+
with np.errstate(invalid='ignore'):
50+
result = np.less_equal(abs(x-y), atol + rtol * abs(y))
51+
if np.isscalar(a) and np.isscalar(b):
5252
result = bool(result)
5353
return result
5454

55-
x = array(a, copy=False, subok=True, ndmin=1)
56-
y = array(b, copy=False, subok=True, ndmin=1)
55+
x = np.array(a, copy=False, subok=True, ndmin=1)
56+
y = np.array(b, copy=False, subok=True, ndmin=1)
5757

5858
# Make sure y is an inexact type to avoid bad behavior on abs(MIN_INT).
5959
# This will cause casting of x later. Also, make sure to allow subclasses
6060
# (e.g., for numpy.ma).
61-
dt = multiarray.result_type(y, 1.)
62-
y = array(y, dtype=dt, copy=False, subok=True)
61+
dt = np.core.multiarray.result_type(y, 1.)
62+
y = np.array(y, dtype=dt, copy=False, subok=True)
6363

64-
xfin = isfinite(x)
65-
yfin = isfinite(y)
66-
if all(xfin) and all(yfin):
64+
xfin = np.isfinite(x)
65+
yfin = np.isfinite(y)
66+
if np.all(xfin) and np.all(yfin):
6767
return within_tol(x, y, atol, rtol)
6868
else:
6969
finite = xfin & yfin
70-
cond = zeros_like(finite, subok=True)
70+
cond = np.zeros_like(finite, subok=True)
7171
# Because we're using boolean indexing, x & y must be the same shape.
7272
# Ideally, we'd just do x, y = broadcast_arrays(x, y). It's in
7373
# lib.stride_tricks, though, so we can't import it here.
74-
x = x * ones_like(cond)
75-
y = y * ones_like(cond)
74+
x = x * np.ones_like(cond)
75+
y = y * np.ones_like(cond)
7676
# Avoid subtraction with infinite/nan values...
7777
cond[finite] = within_tol(x[finite], y[finite], atol, rtol)
7878
# Check for equality of infinite values...
7979
cond[~finite] = (x[~finite] == y[~finite])
8080
if equal_nan:
8181
# Make NaN == NaN
82-
both_nan = isnan(x) & isnan(y)
82+
both_nan = np.isnan(x) & np.isnan(y)
8383
cond[both_nan] = both_nan[both_nan]
8484

85-
if isscalar(a) and isscalar(b):
85+
if np.isscalar(a) and np.isscalar(b):
8686
return bool(cond)
8787
else:
8888
return cond

0 commit comments

Comments
 (0)