Skip to content
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

Fix dpctl.tensor.sum for support zero-dimensional array #1238

Merged
merged 1 commit into from
Jun 13, 2023

Conversation

vlad-perevezentsev
Copy link
Collaborator

This PR changes a bit the behavior for dpctl.tensor.sum function for scalars.
The previous implementation always returned dpt.zeros for zero-dimensions of the input array and worked incorrectly for scalars. According to the Python Array API: If N is 0, the sum is 0 (i.e., the empty sum) [sum].
Now if dpctl.tensor.sum takes a scalar it returns a scalar has the same behavior as numpy

#old impl
a = dpt.asarray(1)
dpt.sum(a)
usm_ndarray(0., dtype=float32)

a = dpt.asarray(())
dpt.sum(a)
usm_ndarray(0., dtype=float32)

#new impl
a = dpt.asarray(1)
dpt.sum(a)
usm_ndarray(1., dtype=float32)

a = dpt.asarray(())
dpt.sum(a)
usm_ndarray(0., dtype=float32)

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

@vlad-perevezentsev vlad-perevezentsev self-assigned this Jun 12, 2023
@vlad-perevezentsev vlad-perevezentsev added the bug Something isn't working label Jun 12, 2023
@coveralls
Copy link
Collaborator

Coverage Status

coverage: 84.1% (+0.02%) from 84.079% when pulling 9579d8a on vlad-perevezentsev:fix_dpctl_sum into 47466ee on IntelPython:master.

Copy link
Collaborator

@ndgrigorian ndgrigorian left a comment

Choose a reason for hiding this comment

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

LGTM!

@ndgrigorian ndgrigorian merged commit f35b34d into IntelPython:master Jun 13, 2023
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3dev3=py310h7bf5fec_33 ran successfully.
Passed: 348
Failed: 652
Skipped: 119

@vlad-perevezentsev vlad-perevezentsev deleted the fix_dpctl_sum branch June 20, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants