From 7d7afaf8b2809685049719f4e471a1de785a9d5a Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 6 Dec 2022 12:01:07 -0600 Subject: [PATCH 1/2] usm_ndarray is writable by default. In addition `__setitem__` now raises on attempt to modify the read-only array. --- dpctl/tensor/_usmarray.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dpctl/tensor/_usmarray.pyx b/dpctl/tensor/_usmarray.pyx index 62ebc83a86..96a865fcb6 100644 --- a/dpctl/tensor/_usmarray.pyx +++ b/dpctl/tensor/_usmarray.pyx @@ -257,7 +257,7 @@ cdef class usm_ndarray: self.shape_ = shape_ptr self.strides_ = strides_ptr self.typenum_ = typenum - self.flags_ = contig_flag + self.flags_ = (contig_flag | USM_ARRAY_WRITABLE) self.nd_ = nd self.array_namespace_ = array_namespace @@ -952,6 +952,8 @@ cdef class usm_ndarray: _copy_from_numpy_into, _copy_from_usm_ndarray_to_usm_ndarray, ) + if (( Xv).flags_ & USM_ARRAY_WRITABLE) == 0: + raise ValueError("Can not modify read-only array.") if isinstance(val, usm_ndarray): _copy_from_usm_ndarray_to_usm_ndarray(Xv, val) else: From 368782ed7d317ce441867056d3294656e05e5c54 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 6 Dec 2022 15:29:18 -0600 Subject: [PATCH 2/2] Modified test_full_dtype_inference to run on Iris Xe GPU --- dpctl/tests/test_usm_ndarray_ctor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dpctl/tests/test_usm_ndarray_ctor.py b/dpctl/tests/test_usm_ndarray_ctor.py index 694ec64f69..20ffa1779c 100644 --- a/dpctl/tests/test_usm_ndarray_ctor.py +++ b/dpctl/tests/test_usm_ndarray_ctor.py @@ -999,11 +999,13 @@ def test_full_dtype_inference(): assert np.issubdtype(dpt.full(10, 4).dtype, np.integer) assert dpt.full(10, True).dtype is dpt.dtype(np.bool_) assert np.issubdtype(dpt.full(10, 12.3).dtype, np.floating) - assert np.issubdtype(dpt.full(10, 0.3 - 2j).dtype, np.complexfloating) + cdt = dpt.full(10, 0.3 - 2j).dtype + assert np.issubdtype(cdt, np.complexfloating) assert np.issubdtype(dpt.full(10, 12.3, dtype=int).dtype, np.integer) assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=int).dtype, np.integer) - assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=float).dtype, np.floating) + rdt = np.finfo(cdt).dtype + assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=rdt).dtype, np.floating) def test_full_fill_array():