Skip to content

Conversation

@vlad-perevezentsev
Copy link
Collaborator

This PR partially aligns usm_ndarray scalar conversion semantics with the Python Array API by allowing numeric scalar conversion only for 0D usm_ndarrays

Conversions to Python numeric scalars via int, float, complex and their corresponding methods (__int__, _float__, __complex__) now raise TypeError when applied to usm_ndarrays with ndim !=0

Note:
For full compliance with the Python Array API, the same check should be used for truth values __bool__ method and integer indexing index method
But these changes would impact dpnp compatibility with Numpy 2.4 which currently disallows only numeric scalar conversation (a minor behavioral difference I think)
In addition several dpctl tests rely on implicit truth conversion for non-0D arrays and must be updated accordingly

test_usm_ndarray_indexing.py::test_nonzero_f_contig
test_usm_ndarray_indexing.py::test_nonzero_compacting
test_usm_ndarray_manipulation.py::test_tile_size_1 
test_usm_ndarray_operators.py::test_comp_ops[dpctl.tensor]
test_usm_ndarray_operators.py::test_comp_ops[namespace1]
test_usm_ndarray_sorting.py::test_radix_sort_size_1_axis 
test_usm_ndarray_sorting.py::test_radix_argsort_size_1_axis 
  • 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?

@vlad-perevezentsev vlad-perevezentsev self-assigned this Dec 22, 2025
@github-actions
Copy link

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_103 ran successfully.
Passed: 1114
Failed: 44
Skipped: 82

@coveralls
Copy link
Collaborator

coveralls commented Dec 22, 2025

Coverage Status

coverage: 86.245%. remained the same
when pulling 239e5b1 on disallow_conv_to_scalar_ndim
into 4c57ee7 on master.

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_108 ran successfully.
Passed: 1112
Failed: 46
Skipped: 82

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