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

Adds element-wise functions angle and reciprocal #1474

Merged
merged 12 commits into from
Nov 30, 2023

Conversation

ndgrigorian
Copy link
Collaborator

This pull request implements two new element-wise functions, dpctl.tensor.angle and dpctl.tensor.reciprocal.

To support the inclusion of reciprocal, an acceptance function argument to the UnaryElementwiseFunc class is added to align the behavior of reciprocal and divide.

This pull request also slips in bug fixes to usm_ndarray -- namely, the real and imag properties.

imag was not allocating to the same queue as the original array for real-valued types, and would raise an exception for real-valued 0D arrays.

Both real and imag would return None for float16 arrays as a result of incorrect logic in the typenum checks.

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

This change was made to mirror promotion behavior of divide in reciprocal

Adds getter method for the acceptance function

Adds tests for reciprocal
_zero_like did not have logic accounting for 0D arrays, so `x.imag` failed for 0D x
This prevents unexpected behavior when calling `imag`
i.e., for x with a real-valued data type
`dpctl.tensor.atan2(x.imag, x.real)` would not work prior to this change
The logic in these properties did not work for float16 data types, returning None instead of `self` or an array of zeros
Copy link

@coveralls
Copy link
Collaborator

coveralls commented Nov 24, 2023

Coverage Status

coverage: 85.979% (+0.04%) from 85.942%
when pulling f8536c1 on elementwise-angle-reciprocal
into 5ec9fd5 on master.

Copy link

Array API standard conformance tests for dpctl=0.15.1dev2=py310h15de555_26 ran successfully.
Passed: 1019
Failed: 55
Skipped: 59

Copy link

Array API standard conformance tests for dpctl=0.15.1dev2=py310h15de555_27 ran successfully.
Passed: 1019
Failed: 55
Skipped: 59

@ndgrigorian ndgrigorian marked this pull request as ready for review November 24, 2023 19:02
Copy link

Array API standard conformance tests for dpctl=0.15.1dev2=py310h15de555_27 ran successfully.
Passed: 876
Failed: 55
Skipped: 59

@@ -698,7 +699,8 @@ cdef class usm_ndarray:
""" Returns imaginary component for arrays with complex data-types
and returns zero array for all other data-types.
"""
if (self.typenum_ < UAR_CFLOAT):
# explicitly check for UAR_HALF, which is greater than UAR_CFLOAT
if (self.typenum_ < UAR_CFLOAT or self.typenum_ == UAR_HALF):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

Copy link
Collaborator

@oleksandr-pavlyk oleksandr-pavlyk left a comment

Choose a reason for hiding this comment

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

Module the renaming suggestion this PR is in perfect shape. The renaming can be addressed in a separate PR though.

`_acceptance_fn_default1` and `_acceptance_fn_default2` are now
`_acceptance_fn_default_unary` and `_acceptance_fn_default_binary`
@ndgrigorian
Copy link
Collaborator Author

Module the renaming suggestion this PR is in perfect shape. The renaming can be addressed in a separate PR though.

I noticed a typo in the rsqrt docstring, so I went ahead and added the acceptance function naming change as well.

Copy link

Array API standard conformance tests for dpctl=0.15.1dev2=py310h15de555_29 ran successfully.
Passed: 875
Failed: 56
Skipped: 59

@ndgrigorian
Copy link
Collaborator Author

Internal CI failures are not related to this PR and will be investigated separately

I will merge this

@ndgrigorian ndgrigorian merged commit b3ba5ac into master Nov 30, 2023
37 of 43 checks passed
@ndgrigorian ndgrigorian deleted the elementwise-angle-reciprocal branch November 30, 2023 18:06
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