|
46 | 46 | def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): |
47 | 47 |
|
48 | 48 | 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): |
52 | 52 | result = bool(result) |
53 | 53 | return result |
54 | 54 |
|
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) |
57 | 57 |
|
58 | 58 | # Make sure y is an inexact type to avoid bad behavior on abs(MIN_INT). |
59 | 59 | # This will cause casting of x later. Also, make sure to allow subclasses |
60 | 60 | # (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) |
63 | 63 |
|
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): |
67 | 67 | return within_tol(x, y, atol, rtol) |
68 | 68 | else: |
69 | 69 | finite = xfin & yfin |
70 | | - cond = zeros_like(finite, subok=True) |
| 70 | + cond = np.zeros_like(finite, subok=True) |
71 | 71 | # Because we're using boolean indexing, x & y must be the same shape. |
72 | 72 | # Ideally, we'd just do x, y = broadcast_arrays(x, y). It's in |
73 | 73 | # 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) |
76 | 76 | # Avoid subtraction with infinite/nan values... |
77 | 77 | cond[finite] = within_tol(x[finite], y[finite], atol, rtol) |
78 | 78 | # Check for equality of infinite values... |
79 | 79 | cond[~finite] = (x[~finite] == y[~finite]) |
80 | 80 | if equal_nan: |
81 | 81 | # Make NaN == NaN |
82 | | - both_nan = isnan(x) & isnan(y) |
| 82 | + both_nan = np.isnan(x) & np.isnan(y) |
83 | 83 | cond[both_nan] = both_nan[both_nan] |
84 | 84 |
|
85 | | - if isscalar(a) and isscalar(b): |
| 85 | + if np.isscalar(a) and np.isscalar(b): |
86 | 86 | return bool(cond) |
87 | 87 | else: |
88 | 88 | return cond |
|
0 commit comments