Skip to content

Fix for gh-2121 #2122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix for gh-2121 #2122

wants to merge 1 commit into from

Conversation

ndgrigorian
Copy link
Collaborator

This PR proposes a fix for gh-2121, which is caused by underlying memory of a boolean array not necessarily representing only 0s and 1s, in particular when it is a view from a non-boolean array

This PR adds a path to astype that guarantees astype(a, "?") will give an output array of only 0 and 1

  • 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?
  • If this PR is a work in progress, are you opening the PR as a draft?

underlying memory of a boolean array may not be 0 and 1 when a boolean view is made from a non-boolean array, leading to unexpected results when copying element-wise, especially in astype

use a special path for boolean inputs to astype to make sure output is 0 and 1
Copy link

github-actions bot commented Jul 9, 2025

Copy link

github-actions bot commented Jul 9, 2025

Array API standard conformance tests for dpctl=0.21.0dev0=py310h93fe807_58 ran successfully.
Passed: 1116
Failed: 5
Skipped: 119

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 85.887% (-0.003%) from 85.89%
when pulling f791949 on resolve-gh-2121
into e2789db on master.

@ndgrigorian ndgrigorian marked this pull request as ready for review July 10, 2025 03:27
@@ -739,6 +739,9 @@ def astype(
order=copy_order,
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
)
# see #2121
if ary_dtype == dpt.bool:
usm_ary = dpt.not_equal(usm_ary, 0, order=order)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue is resolved. Thank you @ndgrigorian!
The only question is about order keyword, why do we pass it as order=order and would it be more efficient to use order=copy_order instead to be aligned with order of R array?

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