Skip to content

Add boolean mask validation when slicing#2929

Open
ndgrigorian wants to merge 3 commits into
masterfrom
resolve-indexing-bugs-with-boolean-masks
Open

Add boolean mask validation when slicing#2929
ndgrigorian wants to merge 3 commits into
masterfrom
resolve-indexing-bugs-with-boolean-masks

Conversation

@ndgrigorian
Copy link
Copy Markdown
Collaborator

@ndgrigorian ndgrigorian commented May 22, 2026

This PR proposes the addition of validation for the shape of masks when slicing tensor.usm_ndarrays and dpnp_arrays.

This aligns with NumPy for specific edge cases, such as:

import dpnp.tensor as dpt

x = dpt.reshape(dpt.arange(3**5, dtype="i4"), (3,) * 5)
ii = dpt.asarray(1)
i0 = dpt.asarray(0, dtype='?')
i1 = dpt.asarray(0, dtype='?')

x[ii, i0[dpt.newaxis], ii, i1[dpt.newaxis], :]

which previously would give usm_ndarray([], dtype=int32), but now raises an error, which aligns with NumPy.

  • 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?

@github-actions
Copy link
Copy Markdown
Contributor

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

@antonwolfy antonwolfy added this to the 0.21.0 release milestone May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Array API standard conformance tests for dpnp=0.21.0dev0=py313h509198e_45 ran successfully.
Passed: 1357
Failed: 3
Skipped: 16

@ndgrigorian ndgrigorian marked this pull request as ready for review May 22, 2026 09:00
@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.242% (+0.003%) from 78.239% — resolve-indexing-bugs-with-boolean-masks into master

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