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

Fixes setting of writable flag for views and writing to read-only arrays with out keyword #1527

Merged
merged 6 commits into from
Feb 6, 2024

Conversation

ndgrigorian
Copy link
Collaborator

This pull request makes changes to _usmarray.pyx to guarantee that the writable flag is handled correctly for views created via real, imag, T, mT, and shape-setting and indexing properties.

__getitem__ now only adjusts the flag after all writing to the result has been performed, fixing the practice of setting elements to a read-only array.

Elementwise functions, clip, and matmul also now contain early (top-level) checks for the writable flag of a provided out array, fixing an edge case where the writable flag would be overridden by copying to the original array. This practice also prevents unnecessary computation and memory allocation.

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

`writable` flag was not being set correctly for indexing, real views, imaginary views, tranposes, and where shape is set directly

Also fixes cases where flag could be overridden by functions with `out` kwarg
Now flags are set based on input regardless of whether a new array is writable
per review feedback
Copy link

github-actions bot commented Feb 5, 2024

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

@coveralls
Copy link
Collaborator

coveralls commented Feb 5, 2024

Coverage Status

coverage: 91.037% (-0.03%) from 91.065%
when pulling 356cf22 on writable-flag-views
into 89266a7 on master.

Copy link

github-actions bot commented Feb 5, 2024

Array API standard conformance tests for dpctl=0.15.1dev3=py310h15de555_72 ran successfully.
Passed: 909
Failed: 0
Skipped: 86

1 similar comment
Copy link

github-actions bot commented Feb 5, 2024

Array API standard conformance tests for dpctl=0.15.1dev3=py310h15de555_72 ran successfully.
Passed: 909
Failed: 0
Skipped: 86

Copy link

github-actions bot commented Feb 6, 2024

Array API standard conformance tests for dpctl=0.15.1dev3=py310h15de555_75 ran successfully.
Passed: 909
Failed: 0
Skipped: 86

Copy link

github-actions bot commented Feb 6, 2024

Array API standard conformance tests for dpctl=0.15.1dev3=py310h15de555_73 ran successfully.
Passed: 907
Failed: 2
Skipped: 86

@ndgrigorian ndgrigorian changed the title Fixes setting of writable flag for views, read-only arrays for out keyword Fixes setting of writable flag for views and writing to read-only arrays with out keyword Feb 6, 2024
Copy link

github-actions bot commented Feb 6, 2024

Array API standard conformance tests for dpctl=0.15.1dev3=py310h15de555_82 ran successfully.
Passed: 907
Failed: 2
Skipped: 86

Copy link
Contributor

@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.

More tests are needed, and perhaps usm_ndarray._set_writable_flag could be implemented using newly added _copy_writable function, but this can be done in a separate PR.

Thanks @ndgrigorian for finding and fixing this bug!

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