Skip to content

at.set behavior for Dask arrays? #134

Closed
@mdhaber

Description

@mdhaber

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).

import numpy as np
import dask.array as xp
from scipy._lib._array_api import array_namespace

# import array_api_extra as xpx  # this works
import scipy._lib.array_api_extra as xpx  # this doesn't

x = xp.asarray([1., 2., 3.])
y = xp.asarray([1., 2.5, 3.])
xp = array_namespace(x, y)

r = xp.vecdot(x, y)
mask = xp.asarray(False)
y = xp.asarray(xp.nan)

# r[mask] = xp.nan  # This works
r = xpx.at(r, mask).set(y)  # This doesn't

np.asarray(r)
# TypeError: 'numpy.float64' object does not support item assignment

But this brings up a question - why does array_api_extra.at.set get involved with Dask here anyway? The documentation of Dask Array says:
image

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 a where?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions