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

Coverage Status

coverage: 86.244% (-0.006%) from 86.25%
when pulling 33b2c8d on disallow_conv_to_scalar_ndim
into e041fca on master.

)

def __float__(self):
if self.size == 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need to check the size on that case?

pytest.skip("No SYCL devices available")
Y = np.arange(1, X.size + 1, dtype=dtype)
X.usm_data.copy_from_host(Y.view("|u1"))
Y.shape = tuple()
Copy link
Collaborator

Choose a reason for hiding this comment

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

In-place modification of ndarray.shape is a pending deprecation based on NumPy changelog.
It is going to be deprecated in NumPy 2.5 release.

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