question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dask Array's constant pad coerces array to NumPy ndarray

See original GitHub issue

Currently 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:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pentschevcommented, Jun 7, 2019

No, unfortunately da.pad relies on da.asarray, which in turn relies on np.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 solve pad more generally we will require to deal with the cases I mentioned above.

0reactions
pentschevcommented, Nov 16, 2020

@mrocklin @jakirkham just wanted to ping this issue to get help promote it.

Any tips on solving the coercion issue for cupy arrays in the cupy_backed_array.map_overlap(..., boundary=0.) case?

The original issue here with da.pad is going to be resolved by https://github.com/dask/dask/pull/6738. However, your issue with map_overlap (that internally relies on map_blocks) is probably solved by passing meta=, please see https://github.com/dask/dask/blob/8d622ad81162245d5e7663522b9721df5b23e9f4/dask/array/core.py#L486-L495

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found