Skip to content

Bitwise elementwise functions #1307

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 6 commits into from
Aug 2, 2023
Merged

Conversation

oleksandr-pavlyk
Copy link
Contributor

Implementation of dpt.bitwise_invert, dpt.bitwise_and, dpt.bitwise_or, dpt.bitwise_xor, dpt.bitwise_left_shift, and dpt.bitwise_right_shift per array API.

  • 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

@coveralls
Copy link
Collaborator

coveralls commented Jul 27, 2023

Coverage Status

coverage: 84.814% (+0.02%) from 84.795% when pulling 9a99003 on bitwise-elementwise-functions into fedc71b on master.

@github-actions
Copy link

Array API standard conformance tests for dpctl= ran successfully.
Passed: 584
Failed: 416
Skipped: 119

@oleksandr-pavlyk oleksandr-pavlyk force-pushed the bitwise-elementwise-functions branch from 84f9109 to 8a2b1d4 Compare July 27, 2023 12:15
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.6dev0=py310h7bf5fec_54 ran successfully.
Passed: 584
Failed: 416
Skipped: 119

Implements bitwise_invert, bitwise_and, bitwise_or, bitwise_xor,
bitwise_left_shift, and bitwise_right_shift

Implements Python API in _tensor_impl for these functions.
Adds logic in vec_cast to return the input if dstT is the same as
srcT.
Adds tensor.bitwise_invert, tensor.bitwise_and, tensor.bitwise_or,
tensor.bitwise_xor, tensor.bitwise_left_shift,
tensor.bitwise_right_shift
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the bitwise-elementwise-functions branch from 8a2b1d4 to d92695a Compare July 31, 2023 21:35
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.6dev0=py310h7bf5fec_70 ran successfully.
Passed: 611
Failed: 389
Skipped: 119

…ined behavior

The array API extends the definition to defined bitshift operators to be zero for
shift-size outside of bitwidth range.

```
In [1]: import dpctl.tensor as dpt, numpy as np

In [2]:  x = dpt.asarray([1, 1])

In [3]: y = dpt.asarray(64)

In [4]: dpt.bitwise_right_shift(x, y)
Out[4]: usm_ndarray([0, 0])

In [5]: x_np, y_np = dpt.asnumpy(x), dpt.asnumpy(y)

In [6]: np.right_shift(x_np, y_np)
Out[6]: array([0, 0])
```
@ndgrigorian
Copy link
Collaborator

ndgrigorian commented Aug 1, 2023

@oleksandr-pavlyk
Array API tests have caught some undesired behavior:

In [1]: import dpctl.tensor as dpt, numpy as np

In [2]: x = dpt.asarray([1, 1])

In [3]: y = dpt.asarray(64)

In [4]: dpt.bitwise_right_shift(x, y)
Out[4]: usm_ndarray([1, 1])

In [5]: x_np, y_np = dpt.asnumpy(x), dpt.asnumpy(y)

In [6]: np.right_shift(x_np, y_np)
Out[6]: array([0, 0])

@ndgrigorian
Copy link
Collaborator

@oleksandr-pavlyk Array API tests have caught some undesired behavior:

In [1]: import dpctl.tensor as dpt, numpy as np

In [2]: x = dpt.asarray([1, 1])

In [3]: y = dpt.asarray(64)

In [4]: dpt.bitwise_right_shift(x, y)
Out[4]: usm_ndarray([1, 1])

In [5]: x_np, y_np = dpt.asnumpy(x), dpt.asnumpy(y)

In [6]: np.right_shift(x_np, y_np)
Out[6]: array([0, 0])

And oddly enough:

In [8]: dpt.bitwise_right_shift(dpt.asarray([1, 1]), dpt.asarray(62))
Out[8]: usm_ndarray([0, 0])

In [9]: dpt.bitwise_right_shift(dpt.asarray([1, 1]), dpt.asarray(65))
Out[9]: usm_ndarray([0, 0])

which is the expected result.

@oleksandr-pavlyk
Copy link
Contributor Author

@ndgrigorian C/C++ spec states that bitshift behavior is undefined if the second argument is negative or not less than total type bitwidth. Additional branching was added ensure compliance with spec.

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

Array API standard conformance tests for dpctl=0.14.6dev0=py310h7bf5fec_77 ran successfully.
Passed: 612
Failed: 388
Skipped: 119

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.

Test is fixed so LGTM!

@oleksandr-pavlyk oleksandr-pavlyk merged commit 79994c1 into master Aug 2, 2023
@oleksandr-pavlyk oleksandr-pavlyk deleted the bitwise-elementwise-functions branch August 2, 2023 03:10
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

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

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

Array API standard conformance tests for dpctl=0.14.6dev0=py310h7bf5fec_77 ran successfully.
Passed: 612
Failed: 388
Skipped: 119

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.

4 participants