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

Allow for mutation of usm_ndarray.flags.writable flag #1141

Merged
merged 2 commits into from
Mar 27, 2023

Conversation

oleksandr-pavlyk
Copy link
Collaborator

Closes gh-1138

Example:

In [3]: x = dpt.ones((2,2))

In [4]: x.flags.writable
Out[4]: True

In [5]: x.flags.writable = False

In [6]: x.flags.writable
Out[6]: False

In [7]: x[:] = 0
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 x[:] = 0

File ~/repos/dpctl/dpctl/tensor/_usmarray.pyx:1002, in dpctl.tensor._usmarray.usm_ndarray.__setitem__()
   1000
   1001         if (self.flags_ & USM_ARRAY_WRITABLE) == 0:
-> 1002             raise ValueError("Can not modify read-only array.")
   1003
   1004         _meta = _basic_slice_meta(

ValueError: Can not modify read-only array.
  • 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?

Example:

```
import dpctl.tensor as dpt, pytest

x = dpt.ones((2,2))
x.flags.writable = False
with pytest.raises(ValueError):
   x[:] = 0  # can not mutate read-only array
x.flags["W"] = True
x[:] = 0   # works fine now
```
@github-actions
Copy link

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_27 ran successfully.
Passed: 46
Failed: 788
Skipped: 280

@coveralls
Copy link
Collaborator

Coverage Status

Coverage: 82.843% (+0.003%) from 82.84% when pulling b63907a on flags-gh-1138 into 26b2eaa on master.

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.

LGTM!

@oleksandr-pavlyk oleksandr-pavlyk merged commit bd9e465 into master Mar 27, 2023
@oleksandr-pavlyk oleksandr-pavlyk deleted the flags-gh-1138 branch March 27, 2023 18:52
@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.3dev0=py310h76be34b_27 ran successfully.
Passed: 46
Failed: 788
Skipped: 280

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.

All flags are read-only?
3 participants