Skip to content

Commit 178a113

Browse files
committed
BUG: fixes for Dask
[skip cirrus] [skip circle]
1 parent 1fa31c6 commit 178a113

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

scipy/cluster/hierarchy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4154,7 +4154,7 @@ def leaders(Z, T):
41544154
if T.shape[0] != Z.shape[0] + 1:
41554155
raise ValueError('Mismatch: len(T)!=Z.shape[0] + 1.')
41564156

4157-
n_clusters = int(xp.unique_values(T).shape[0])
4157+
n_clusters = int(np.asarray(xp.unique_values(T)).shape[0])
41584158
n_obs = int(Z.shape[0] + 1)
41594159
L = np.zeros(n_clusters, dtype=np.int32)
41604160
M = np.zeros(n_clusters, dtype=np.int32)

scipy/cluster/vq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ def _kmeans(obs, guess, thresh=1e-5, xp=None):
317317
# recalc code_book as centroids of associated obs
318318
obs = np.asarray(obs)
319319
obs_code = np.asarray(obs_code)
320+
code_book_len = np.asarray(code_book).shape[0]
320321
code_book, has_members = _vq.update_cluster_means(obs, obs_code,
321-
code_book.shape[0])
322+
code_book_len)
322323
obs = xp.asarray(obs)
323324
obs_code = xp.asarray(obs_code)
324325
code_book = xp.asarray(code_book)

scipy/differentiate/tests/test_differentiate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
@pytest.mark.skip_xp_backends('array_api_strict', reason=array_api_strict_skip_reason)
2222
@pytest.mark.skip_xp_backends('jax.numpy',reason=jax_skip_reason)
23+
@pytest.mark.skip_xp_backends('dask.array', reason='boolean indexing assignment')
2324
class TestDerivative:
2425

2526
def f(self, x):

scipy/integrate/tests/test_tanhsinh.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def wrapped(*arg_arrays):
4848
@pytest.mark.skip_xp_backends(
4949
'array_api_strict', reason='Currently uses fancy indexing assignment.'
5050
)
51+
@pytest.mark.skip_xp_backends(
52+
'dask.array', reason='boolean indexing assignment'
53+
)
5154
@pytest.mark.skip_xp_backends(
5255
'jax.numpy', reason='JAX arrays do not support item assignment.'
5356
)

scipy/ndimage/_morphology.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,7 @@ def morphological_laplace(input, size=None, footprint=None,
17261726
tmp2 = grey_erosion(input, size, footprint, structure, None, mode,
17271727
cval, origin)
17281728
np.add(tmp1, tmp2, tmp2)
1729+
input = np.asarray(input)
17291730
np.subtract(tmp2, input, tmp2)
17301731
np.subtract(tmp2, input, tmp2)
17311732
return tmp2

scipy/ndimage/_support_alternative_backends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ def wrapper(*args, **kwds):
5050
elif result is None:
5151
# inplace operations
5252
return result
53-
else:
54-
# lists/tuples
53+
elif isinstance(result, (list, tuple)):
5554
return type(result)(
5655
xp.asarray(x) if isinstance(x, np.ndarray) else x
5756
for x in result
5857
)
58+
else:
59+
return result
5960
return wrapper
6061
return inner
6162

scipy/optimize/_chandrupatla.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _chandrupatla(func, a, b, *, args=(), xatol=None, xrtol=None,
134134
func, xs, fs, args, shape, dtype, xp = temp
135135
x1, x2 = xs
136136
f1, f2 = fs
137-
status = xp.full_like(x1, xp.asarray(eim._EINPROGRESS),
137+
status = xp.full_like(x1, eim._EINPROGRESS,
138138
dtype=xp.int32) # in progress
139139
nit, nfev = 0, 2 # two function evaluations performed above
140140
finfo = xp.finfo(dtype)
@@ -218,7 +218,7 @@ def post_termination_check(work):
218218
j = ((1 - xp.sqrt(1 - xi1)) < phi1) & (phi1 < xp.sqrt(xi1))
219219

220220
f1j, f2j, f3j, alphaj = work.f1[j], work.f2[j], work.f3[j], alpha[j]
221-
t = xp.full_like(alpha, xp.asarray(0.5))
221+
t = xp.full_like(alpha, 0.5)
222222
t[j] = (f1j / (f1j - f2j) * f3j / (f3j - f2j)
223223
- alphaj * f1j / (f3j - f1j) * f2j / (f2j - f3j))
224224

@@ -400,8 +400,7 @@ def _chandrupatla_minimize(func, x1, x2, x3, *, args=(), xatol=None,
400400
x1, x2, x3 = xs
401401
f1, f2, f3 = fs
402402
phi = xp.asarray(0.5 + 0.5*5**0.5, dtype=dtype)[()] # golden ratio
403-
status = xp.full_like(x1, xp.asarray(eim._EINPROGRESS),
404-
dtype=xp.int32) # in progress
403+
status = xp.full_like(x1, eim._EINPROGRESS, dtype=xp.int32) # in progress
405404
nit, nfev = 0, 3 # three function evaluations performed above
406405
fatol = xp.finfo(dtype).smallest_normal if fatol is None else fatol
407406
frtol = xp.finfo(dtype).smallest_normal if frtol is None else frtol

0 commit comments

Comments
 (0)