Skip to content

Padding error when padding width is 0 for antisymmetric and smooth #589

Description

@miaotianyi

Hi, this might be rare to come across, but

pywt.pad([1, 2, 3], 0, mode="antisymmetric")
pywt.pad([1, 2, 3], (2, 0), mode="antisymmetric")
pywt.pad([1, 2, 3], ((5, 0),), mode="antisymmetric")
pywt.pad([1, 2, 3], 0, mode="smooth")
pywt.pad([1, 2, 3], (1, 0), mode="smooth")
pywt.pad([1, 2, 3], ((4, 0),), mode="smooth")

Will all cause errors like

Traceback (most recent call last):
  File "", line 63, in <module>
    pywt.pad([1, 2, 3], 0, mode="smooth")
  File "Anaconda3\lib\site-packages\pywt\_dwt.py", line 476, in pad
    xp = np.pad(x, pad_widths, pad_smooth)
  File "<__array_function__ internals>", line 5, in pad
  File "Anaconda3\lib\site-packages\numpy\lib\arraypad.py", line 767, in pad
    function(view[ind], pad_width[axis], axis, kwargs)
  File "Anaconda3\lib\site-packages\pywt\_dwt.py", line 473, in pad_smooth
    vector[-pad_width[1]:] = \
ValueError: could not broadcast input array from shape (0) into shape (3)

Ideally, a padding width of 0 should make pad an identity function. I noticed that only antisymmetric and smooth modes have this issue. Furthermore, the second 0 in the padding width pair seems to be the source of the problem, as pairs like (3, 0) work without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions