Skip to content

BUG: Unexpected pad value when padding an uint64 array #11027

@lagru

Description

@lagru

This seems to be an edge case, nevertheless I wanted to report this behavior. Especially because I find it kind of interesting.

Description

When padding an array of dtype uint64 there are some cases when mode "constant" doesn't append with the correct value but instead pads with 0.

Code to reproduce

>>> offset = 1024
>>> pad_value = np.uint64(-1024)
>>> x = np.zeros(5, dtype=np.uint64) - offset
>>> np.pad(x, 1, mode="constant", constant_values=pad_value)
array([                   0, 18446744073709551615, 18446744073709551615,
       18446744073709551615, 18446744073709551615, 18446744073709551615,
                          0], dtype=uint64)

Expected Result

array([18446744073709551615, 18446744073709551615, 18446744073709551615,
       18446744073709551615, 18446744073709551615, 18446744073709551615,
       18446744073709551615], dtype=uint64)

There are some interesting observations to be made:

  • This only happens for uint64 (uint32, uint16 and below are fine).
  • This behavior is only visible if offset is in [1, 1024] and the argument of np.uint64 in pad_value is in [-1, -1024].
  • np.pad(x, 1, mode="minimum") (or maximum) works fine, regardless of offset.

Platform, versions, etc.

NumPy: 1.14.2
Operating system: Manjaro 17.1.7, x86_64 Linux 4.14.36-1-MANJARO
Python version: 3.6.5 (Anaconda, [GCC 7.2.0] on linux)

I hope this is reproduce-able and not a weird quirk of my setup. Feel free to ask for further diagnostics if you can think of any.

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