Skip to content

Conversation

@ndgrigorian
Copy link
Collaborator

This PR proposes permitting the search values of dpt.searchsorted to be Python scalars, a change coming to the 2026 array API spec

Resolves #2224

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

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

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

@ndgrigorian ndgrigorian force-pushed the allow-scalars-searchsorted-search-values branch from b7de201 to e85940e Compare January 6, 2026 06:31
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_104 ran successfully.
Passed: 1115
Failed: 43
Skipped: 82

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_105 ran successfully.
Passed: 1115
Failed: 43
Skipped: 82

@coveralls
Copy link
Collaborator

coveralls commented Jan 6, 2026

Coverage Status

coverage: 86.248% (+0.003%) from 86.245%
when pulling 65d2651 on allow-scalars-searchsorted-search-values
into 4c57ee7 on master.

@github-actions
Copy link

github-actions bot commented Jan 7, 2026

Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_106 ran successfully.
Passed: 1115
Failed: 43
Skipped: 82

@ndgrigorian ndgrigorian force-pushed the allow-scalars-searchsorted-search-values branch from bda9809 to b7c56e1 Compare January 7, 2026 00:16
@github-actions
Copy link

github-actions bot commented Jan 7, 2026

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

@ndgrigorian ndgrigorian marked this pull request as ready for review January 7, 2026 03:22

if not isinstance(x2, usm_ndarray):
x2 = dpt.asarray(x2, dtype=dt2, usm_type=res_usm_type, sycl_queue=q)
if x2.dtype != dt:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if x2.dtype != dt:
elif x2.dtype != dt:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is not meant to be an elif. x2 is taken to dt2 first if not usm_ndarray then is cast to dt which is the resolved dtype. This way, it passes through dt2 under all circumstances.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then it's unclear for me, why do we need to run 2 kernels in that case?

  1. to convert a scalar to a temporary usm_ndarray and to copy back to the result
  2. to cast the array to dt

What is a drawback to pass dt directly to asarray call?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, in the sequence:

  1. cast x1 to dt
  2. cast x2 to usm_ndarray if any
  3. cast x2 to dt

We have to make step 2 as the 1st or as the last in the sequence, but not in the middle, because currently step 2 depends on events from step 1, but shouldn't.
And from other side, step 2 produces depending events which we must pass to step 3, but we didn't (asarray must be completed before we can start casting x2 to dt).

@github-actions
Copy link

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

"shape as the first argument array"
)
res = empty(x1.shape, dtype=x1_dt, usm_type=x1.usm_type, sycl_queue=q)
res = empty(x1.shape, dtype=x1_dt, usm_type=x1_usm_type, sycl_queue=q)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't that exactly the same as below?

Suggested change
res = empty(x1.shape, dtype=x1_dt, usm_type=x1_usm_type, sycl_queue=q)
res = empty_like(x1)


if not isinstance(x2, usm_ndarray):
x2 = dpt.asarray(x2, dtype=dt2, usm_type=res_usm_type, sycl_queue=q)
if x2.dtype != dt:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Then it's unclear for me, why do we need to run 2 kernels in that case?

  1. to convert a scalar to a temporary usm_ndarray and to copy back to the result
  2. to cast the array to dt

What is a drawback to pass dt directly to asarray call?


if not isinstance(x2, usm_ndarray):
x2 = dpt.asarray(x2, dtype=dt2, usm_type=res_usm_type, sycl_queue=q)
if x2.dtype != dt:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, in the sequence:

  1. cast x1 to dt
  2. cast x2 to usm_ndarray if any
  3. cast x2 to dt

We have to make step 2 as the 1st or as the last in the sequence, but not in the middle, because currently step 2 depends on events from step 1, but shouldn't.
And from other side, step 2 produces depending events which we must pass to step 3, but we didn't (asarray must be completed before we can start casting x2 to dt).

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.

Allow python scalars in the 2nd argument of searchsorted

3 participants