Dask Array's constant pad coerces array to NumPy ndarray
See original GitHub issueCurrently Dask Array’s pad (when using the constant
mode) may end up coercing array data of a different array type to a NumPy ndarray
. For example, the following code will result in a NumPy ndarray
.
a_gpu_pad = da.pad(a_gpu, 1, "constant")
a_gpu_pad.compute()
This still happens if we try to set the constant_values
differently. If we provide a 0-D array, we run into issue ( https://github.com/dask/dask/issues/4841 ).
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
dask.array.pad - Dask documentation
One of the following string values or a user supplied function. 'constant' (default). Pads with a constant value. 'edge'. Pads with the edge...
Read more >xarray.DataArray
DataArray provides a wrapper around numpy ndarrays that uses labeled dimensions and ... Coerce this array's data into a dask arrays with the...
Read more >Interoperability with NumPy — NumPy v1.24 Manual
__array__() : a method returning the NumPy ndarray view of an array-like object; ... This is not optimal, as coercing arrays into ndarrays...
Read more >numpy.pad() function in Python - GeeksforGeeks
numpy.pad() function is used to pad the Numpy arrays. ... Syntax: numpy.pad(array, pad_width, mode='constant', **kwargs). Parameters :.
Read more >UnitsAwareDataArray — Typhon 0.9.0 documentation
DataArray, but transfers units ... a dask array. coords. Dictionary-like container of coordinate arrays. ... The array's data as a numpy.ndarray. variable.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, unfortunately
da.pad
relies onda.asarray
, which in turn relies onnp.asarray
. We’ve started a discussion on how to deal with those cases in #4883.If this particular case (constant padding) is needed immediately, I think we could use
*_like
functions instead, but to solvepad
more generally we will require to deal with the cases I mentioned above.The original issue here with
da.pad
is going to be resolved by https://github.com/dask/dask/pull/6738. However, your issue withmap_overlap
(that internally relies onmap_blocks
) is probably solved by passingmeta=
, please see https://github.com/dask/dask/blob/8d622ad81162245d5e7663522b9721df5b23e9f4/dask/array/core.py#L486-L495