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: 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():