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

Writable flag views followup #1529

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions dpctl/tensor/_usmarray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,8 @@ cdef class usm_ndarray:
return _flags.Flags(self, self.flags_)

cdef _set_writable_flag(self, int flag):
cdef int arr_fl = self.flags_
arr_fl ^= (arr_fl & USM_ARRAY_WRITABLE) # unset WRITABLE flag
arr_fl |= (USM_ARRAY_WRITABLE if flag else 0)
self.flags_ = arr_fl
cdef int mask = (USM_ARRAY_WRITABLE if flag else 0)
self.flags_ = _copy_writable(self.flags_, mask)

@property
def usm_type(self):
Expand Down
21 changes: 21 additions & 0 deletions dpctl/tests/elementwise/test_elementwise_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

import dpctl.tensor as dpt
from dpctl.tests.helper import get_queue_or_skip

Expand Down Expand Up @@ -49,6 +51,15 @@ def test_unary_class_str_repr():
assert kl_n in r


def test_unary_read_only_out():
get_queue_or_skip()
x = dpt.arange(32, dtype=dpt.int32)
r = dpt.empty_like(x)
r.flags["W"] = False
with pytest.raises(ValueError):
unary_fn(x, out=r)


def test_binary_class_getters():
fn = binary_fn.get_implementation_function()
assert callable(fn)
Expand Down Expand Up @@ -105,3 +116,13 @@ def test_binary_class_nout():
nout = binary_fn.nout
assert isinstance(nout, int)
assert nout == 1


def test_biary_read_only_out():
get_queue_or_skip()
x1 = dpt.ones(32, dtype=dpt.float32)
x2 = dpt.ones_like(x1)
r = dpt.empty_like(x1)
r.flags["W"] = False
with pytest.raises(ValueError):
binary_fn(x1, x2, out=r)
19 changes: 19 additions & 0 deletions dpctl/tests/test_tensor_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,22 @@ def test_clip_compute_follows_data():

with pytest.raises(ExecutionPlacementError):
dpt.clip(x, out=res)


def test_clip_readonly_out():
get_queue_or_skip()
x = dpt.arange(32, dtype=dpt.int32)
r = dpt.empty_like(x)
r.flags["W"] = False

with pytest.raises(ValueError):
dpt.clip(x, min=0, max=10, out=r)

with pytest.raises(ValueError):
dpt.clip(x, max=10, out=r)

with pytest.raises(ValueError):
dpt.clip(x, min=0, out=r)

with pytest.raises(ValueError):
dpt.clip(x, out=r)
10 changes: 10 additions & 0 deletions dpctl/tests/test_usm_ndarray_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def test_matmul_out():
assert np.allclose(ref, dpt.asnumpy(res))


def test_matmul_readonly_out():
get_queue_or_skip()
m = dpt.ones((10, 10), dtype=dpt.int32)
r = dpt.empty_like(m)
r.flags["W"] = False

with pytest.raises(ValueError):
dpt.matmul(m, m, out=r)


def test_matmul_dtype():
get_queue_or_skip()

Expand Down