Skip to content

Commit 5feed1a

Browse files
usm_ndarray is writable by default. set-item raises on attempt to modify read-only array
1 parent 2d12eb2 commit 5feed1a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

dpctl/tensor/_usmarray.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ cdef class usm_ndarray:
257257
self.shape_ = shape_ptr
258258
self.strides_ = strides_ptr
259259
self.typenum_ = typenum
260-
self.flags_ = contig_flag
260+
self.flags_ = (contig_flag | USM_ARRAY_WRITABLE)
261261
self.nd_ = nd
262262
self.array_namespace_ = array_namespace
263263

@@ -952,6 +952,8 @@ cdef class usm_ndarray:
952952
_copy_from_numpy_into,
953953
_copy_from_usm_ndarray_to_usm_ndarray,
954954
)
955+
if (Xv.flags_ & USM_ARRAY_WRITABLE) == 0:
956+
raise ValueError("Can not modify read-only array.")
955957
if isinstance(val, usm_ndarray):
956958
_copy_from_usm_ndarray_to_usm_ndarray(Xv, val)
957959
else:

0 commit comments

Comments
 (0)