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

Update empty vals check in dpt.place #1106

Merged

Conversation

vlad-perevezentsev
Copy link
Collaborator

This PR complements #1105 .
The original behavior of numpy.place throws an exception when it gets an empty array of vals argument
BUT if the mask argument contains all False, numpy.place works without exceptions (example).

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

@coveralls
Copy link
Collaborator

coveralls commented Mar 9, 2023

Coverage Status

Coverage: 82.403% (+0.02%) from 82.385% when pulling 10c2022 on vlad-perevezentsev:fix_dpt_place_func into 78875e9 on IntelPython:master.

@@ -293,7 +293,7 @@ def place(arr, mask, vals):
raise dpctl.utils.ExecutionPlacementError
if arr.shape != mask.shape or vals.ndim != 1:
raise ValueError("Array sizes are not as required")
if vals.size == 0:
if vals.size == 0 and dpt.nonzero(mask)[0].size:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The number of set elements in the mask is computed on line 299 and assigned to variable nz_count.

Perhaps it is cleaner to move the check for vals.size == 0 till after nz_count value is known?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, It looks cleaner.
Done!

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.

LGTM! Thank you for catching the issue and providing the fix @vlad-perevezentsev

@oleksandr-pavlyk oleksandr-pavlyk merged commit 5bfc097 into IntelPython:master Mar 10, 2023
@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.2=py310h76be34b_5 ran successfully.
Passed: 36
Failed: 798
Skipped: 280

@vlad-perevezentsev vlad-perevezentsev deleted the fix_dpt_place_func branch June 20, 2023 10:53
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