Skip to content

Dask Array's pad should handle 0-dim constants on the edge #4841

@jakirkham

Description

@jakirkham

Dask Array's pad doesn't currently treat 0-dim constants correctly. As a result, calls like this error.

a_gpu_pad = da.pad(a_gpu, 1, "constant", constant_values=cp.array(0, dtype=a_gpu.dtype))
Details
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-e3963ccbcb84> in <module>
----> 1 a_gpu_pad = da.pad(a_gpu, 1, "constant", constant_values=cp.array(0, dtype=a_gpu.dtype))

~/miniconda/envs/img_exp/lib/python3.7/site-packages/dask/array/creation.py in pad(array, pad_width, mode, **kwargs)
   1063         return pad_stats(array, pad_width, mode, *kwargs.values())
   1064     elif mode in ["constant", "edge", "linear_ramp"]:
-> 1065         return pad_edge(array, pad_width, mode, *kwargs.values())
   1066     elif mode in ["reflect", "symmetric", "wrap"]:
   1067         return pad_reuse(array, pad_width, mode, *kwargs.values())

~/miniconda/envs/img_exp/lib/python3.7/site-packages/dask/array/creation.py in pad_edge(array, pad_width, mode, *args)
    830     """
    831 
--> 832     args = tuple(expand_pad_value(array, e) for e in args)
    833 
    834     result = array

~/miniconda/envs/img_exp/lib/python3.7/site-packages/dask/array/creation.py in <genexpr>(.0)
    830     """
    831 
--> 832     args = tuple(expand_pad_value(array, e) for e in args)
    833 
    834     result = array

~/miniconda/envs/img_exp/lib/python3.7/site-packages/dask/array/creation.py in expand_pad_value(array, pad_value)
    774     else:
    775         raise TypeError(
--> 776             "`pad_value` must be composed of integral typed values."
    777         )
    778 

TypeError: `pad_value` must be composed of integral typed values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions