Skip to content

Fix dpnp.repeat with uint64 repeats above the int64 maximum - #3115

Merged
antonwolfy merged 5 commits into
masterfrom
sync-cupy-tests-numpy-2-6
Oct 22, 2026
Merged

antonwolfy merged 5 commits into
masterfrom
sync-cupy-tests-numpy-2-6

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

dpnp.tensor.repeat, and so dpnp.repeat, accepts a uint64 repeats array, but it checked the array for negative values before casting it to int64. A uint64 value is never negative, so values above the int64 maximum got past the check:

  • with more than one element, the value wrapped to a negative number only when copied to int64, and the result was silently wrong
  • with a single element, it was turned into a Python int too large for the output shape, which raised an OverflowError

uint64 repeats are now cast to int64 first, so such values become negative and raise the same ValueError as any other negative repeat:

import dpnp as np

x = np.arange(3)
np.repeat(x, np.array([1, 2**64 - 1, 1], dtype=np.uint64))  # was array([2]), now ValueError
np.repeat(x, np.array([2**64 - 1], dtype=np.uint64))        # was OverflowError, now ValueError

test_repeat_arg_validation now covers both cases, and both checks fail without the fix.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

`dpnp.tensor.repeat` checked a `uint64` repeats array for negative values
before casting it to `int64`, so values above the `int64` maximum passed
the check and wrapped only later. A multi-element array silently gave a
wrong result and a single element raised an `OverflowError`. Cast `uint64`
repeats to `int64` first so such values become negative and raise a
`ValueError`. Also fix the casting rule named in the `TypeError` message,
which is `same_kind`, not `safe`.
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Oct 19, 2026
@antonwolfy antonwolfy self-assigned this Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev15=np2py314h8d9cdd5_13 ran successfully.
Passed: 1376
Failed: 0
Skipped: 6

@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3115/index.html

@coveralls

coveralls commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 82.617% (+0.002%) from 82.615% — sync-cupy-tests-numpy-2-6 into master

Comment thread dpnp/tensor/_manipulation_functions.py
Comment thread dpnp/tensor/_manipulation_functions.py
A uint64 value above the int64 maximum wraps to negative on the cast
to int64, so it was reported as "must be positive" although it is
positive. Since uint64 is never negative, keep the cast and the
existing sign check but raise a message about the int64 maximum for
uint64 repeats, so no extra kernel or host sync is needed. The message
is now also the same for single- and multi-element repeats arrays.
@vlad-perevezentsev
vlad-perevezentsev self-requested a review October 22, 2026 07:33

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thank you @antonwolfy

@antonwolfy
antonwolfy merged commit 028c4b5 into master Oct 22, 2026
95 of 109 checks passed
@antonwolfy
antonwolfy deleted the sync-cupy-tests-numpy-2-6 branch October 22, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants