Skip to content

Round signed integers toward negative infinity in dpctl.tensor.floor_divide #1260

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

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

ndgrigorian
Copy link
Collaborator

Resolves #1247

This PR changes the behavior of dpctl.tensor.floor_divide to round the result of division between signed integers toward negative infinity rather than toward 0 (as is the norm in C++).

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

@github-actions
Copy link

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_8 ran successfully.
Passed: 387
Failed: 613
Skipped: 119

@ndgrigorian ndgrigorian force-pushed the floor-divide-negative-fix branch from 29b214d to 7b702bc Compare June 22, 2023 17:39
@coveralls
Copy link
Collaborator

coveralls commented Jun 22, 2023

Coverage Status

coverage: 83.252% (+0.008%) from 83.244% when pulling 3f436b2 on floor-divide-negative-fix into d109770 on master.

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_10 ran successfully.
Passed: 388
Failed: 612
Skipped: 119

@ndgrigorian ndgrigorian changed the title Rounds signed integers toward negative infinity in dpctl.tensor.floor_divide Round signed integers toward negative infinity in dpctl.tensor.floor_divide Jun 22, 2023
@ndgrigorian ndgrigorian requested a review from npolina4 June 22, 2023 22:02
@npolina4
Copy link
Contributor

in: dpt.floor_divide(dpt.asarray(1), 0)
out: usm_ndarray(4294967295)
expected: 0
in: dpt.floor_divide(dpt.asarray(0), 0)
out: usm_ndarray(4294967295)
expected: 0

@ndgrigorian
Copy link
Collaborator Author

ndgrigorian commented Jun 23, 2023

in: dpt.floor_divide(dpt.asarray(1), 0)
out: usm_ndarray(4294967295)
expected: 0
in: dpt.floor_divide(dpt.asarray(0), 0)
out: usm_ndarray(4294967295)
expected: 0
In [2]: x = dpt.asarray(1, dtype="u8")

In [3]: dpt.floor_divide(x, dpt.asarray(0, dtype="u8"))
Out[3]: usm_ndarray(4294967295, dtype=uint64)

In [4]: x = dpt.asarray(4294967295, dtype="u8")

In [5]: dpt.floor_divide(x, dpt.asarray(0, dtype="u8"))
Out[5]: usm_ndarray(4294967295, dtype=uint64)

In [6]: x = dpt.asarray(4294967296, dtype="u8")

In [7]: dpt.floor_divide(x, dpt.asarray(0, dtype="u8"))
Out[7]: usm_ndarray(18446744073709551615, dtype=uint64)

Another ugly case. I was trying to avoid a branch for the denominator = 0 case, but I will add a branch to resolve this after all.

- Also fully enables sycl::vec overload for floor_divide
- Added a test for integer division by 0 behavior
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_11 ran successfully.
Passed: 387
Failed: 613
Skipped: 119

@ndgrigorian ndgrigorian merged commit 36a7cd7 into master Jun 26, 2023
@github-actions
Copy link

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.4=py310h7bf5fec_12 ran successfully.
Passed: 388
Failed: 612
Skipped: 119

@ndgrigorian ndgrigorian deleted the floor-divide-negative-fix branch August 10, 2023 17:16
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.

Floor_divide wrong result for integer dtype
3 participants