Skip to content

Support boolean input in dpnp.positive - #3128

Open
antonwolfy wants to merge 1 commit into
masterfrom
support-boolean-positive
Open

antonwolfy wants to merge 1 commit into
masterfrom
support-boolean-positive

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

NumPy 2.6 defines numpy.positive and the unary + operator for boolean arrays: they return a boolean copy of the input instead of raising TypeError. This PR aligns dpnp.positive and + on dpnp.ndarray with that behavior.

>>> import dpnp as np
>>> x = np.array([True, False])
>>> +x
array([ True, False])

dpnp.tensor.positive has no boolean loop, so for boolean input dpnp.positive runs the dpnp.tensor abs kernel, which returns boolean values unchanged. NumPy reuses its absolute loop for this case the same way. Other dtypes still use the positive kernel. dpnp.tensor.positive and + on usm_ndarray are unchanged.

The acceptance function that raised TypeError for boolean input is removed, since boolean input now has its own loop and never goes through type promotion.

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

NumPy 2.6 defines `positive` and the unary `+` operator for boolean
arrays, returning a boolean copy instead of raising `TypeError`.
Align `dpnp.positive` by running the `abs` kernel for boolean input,
which is the identity on bool, as NumPy reuses its `absolute` loop.

`dpnp.tensor.positive` is unchanged.
@antonwolfy antonwolfy added this to the 0.22.0 release milestone Oct 25, 2026
@antonwolfy antonwolfy self-assigned this Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 82.644% (+0.004%) from 82.64% — support-boolean-positive into master

This branch has not been deployed

No deployments
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.

2 participants