-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
at.set
behavior for Dask arrays?
#134
Comments
The documentation you reference is specifically for assignment. In-place operations don't work with bool masks: >>> import dask.array as da
>>> a = da.arange(5)
>>> mask = da.zeros_like(a, dtype=bool)
>>> a[mask] = 1 # OK
>>> a[mask] += 1
ValueError: Boolean index assignment in Dask expects equally shaped arrays.
Example: da1[da2] = da3 where da1.shape == (4,), da2.shape == (4,) and da3.shape == (4,).
Alternatively, you can use the extended API that supportsindexing with tuples.
Example: da1[(da2,)] = da3. What's happening under the hood, which also explains the misleading exception, is that there is no I've reproduced your failure. It's a bug in import dask.array as da
x = xp.zeros(1)
y = x[0] # a writeable da.Array, but the chunk is a read-only np.generic
y[()] = 1 # No failure here
y.compute() # TypeError: 'numpy.float64' object does not support item assignment In turn, this caused a call inside FWIW the code above fails for numpy too, but numpy is technically compliant with the API standard here because the standard caters for read-only arrays, but makes no provision that a function (in this case |
Upstream issue: dask/dask#11722 xpx patch: #135 |
Upstream fix: dask/dask#11723 |
Thanks for taking a look, creating the upstream issue, and providing a patch for In that context, though (specifically this line), it does seem like an in-place assignment would be preferable to |
Except... Dask in-place assignment with bool masks are internally implemented with where, but unlike array-api-extra they failed to implement dtype propagation rules: >>> import numpy as np
>>> a = np.asarray([1,2])
>>> a[[True, False]] = 3.3
>>> a
array([3, 2])
>>> import dask.array as da
>>> a = da.asarray([1, 2])
>>> a[da.asarray([True, False])] = 3.3
>>> a
dask.array<where, shape=(2,), dtype=float64, chunksize=(2,), chunktype=numpy.ndarray>
>>> a.compute()
array([3.3, 2. ]) |
Ah, ok then. |
Re: scipy/scipy#22469 (comment)
I encountered some code involving Dask and
at.set
that works as expected in 0.6.0 but not in the more recent commit used by SciPy (c23ac01).But this brings up a question - why does
![image](https://private-user-images.githubusercontent.com/6570539/410115598-a0e3925c-91c9-45f8-bc51-731dcc9697e5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODg0ODIsIm5iZiI6MTczOTQ4ODE4MiwicGF0aCI6Ii82NTcwNTM5LzQxMDExNTU5OC1hMGUzOTI1Yy05MWM5LTQ1ZjgtYmM1MS03MzFkY2M5Njk3ZTUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTNUMjMwOTQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MGU2MGNlN2JmZmYxMmM0OWFkOTIxMDQ2YWNmMjNmZDU0Y2VmN2E4ODJkZmViYWZhMmYwMmRkZDlhYzJhOGFjZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KcXp5qkZQadm56tasmUUbwarNRj_isfLyX7s9MWnrtM)
array_api_extra.at.set
get involved with Dask here anyway? The documentation of Dask Array says:The last line is what's relevant. Doing the regular indexing assignment (when
y
is a scalar, at least) seems to be something Dask can do, so why replace that with awhere
?The text was updated successfully, but these errors were encountered: