Skip to content

Conversation

sycloid
Copy link
Contributor

@sycloid sycloid commented Sep 26, 2025

This PR reverts changes from gh-2122 and fixes gh-2121 in dpctl::tensor::type_utils::convert_impl instead.
Doing so improves performance of conversion from boolean arrays by avoiding temporary allocation and the cost of launching a kernel implementing not_equal operation.

The test for gh-2121 exists in test_usm_ndarray_ctor.py::test_astype_gh_2121.

A comment #2121 (comment) was left in #2121 to observe that C++ behaves differently than NumPy and that this was the cause for behavior reported in #2121.

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

@intel-python-devops
Copy link

Can one of the admins verify this patch?

@coveralls
Copy link
Collaborator

coveralls commented Sep 26, 2025

Coverage Status

coverage: 85.264% (+0.002%) from 85.262%
when pulling cc0756f on sycloid:revert-gh-2122-fix-for-gh-2121
into 878cc19 on IntelPython:master.

Also make Caster object static constexpr in generic copy kernel
as it is done in contig kernel.
Since convert_impl input argument is a reference, implement NumPy's
interpretation of bool (underlying byte has any bits set in it) to
override C++'s interpretation (underlying byte has the first bit set).

To allow such an intepretation to work correctly bool arguments
must be passed by reference, rather than by value. Passing by value
creates a copy where C++ masks higher bits out.
@sycloid sycloid force-pushed the revert-gh-2122-fix-for-gh-2121 branch from c3a147f to cc0756f Compare September 29, 2025 14:28
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.

dpt.astype returns wrong result on boolean view of numpy.ndarray
3 participants