Skip to content

Commit bc9c5be

Browse files
Merge pull request #1012 from IntelPython/usm-ndarray-writable-default
Make usm_ndarray be writable by default
2 parents 2d12eb2 + 368782e commit bc9c5be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
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 ((<usm_ndarray> 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:

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,13 @@ def test_full_dtype_inference():
999999
assert np.issubdtype(dpt.full(10, 4).dtype, np.integer)
10001000
assert dpt.full(10, True).dtype is dpt.dtype(np.bool_)
10011001
assert np.issubdtype(dpt.full(10, 12.3).dtype, np.floating)
1002-
assert np.issubdtype(dpt.full(10, 0.3 - 2j).dtype, np.complexfloating)
1002+
cdt = dpt.full(10, 0.3 - 2j).dtype
1003+
assert np.issubdtype(cdt, np.complexfloating)
10031004

10041005
assert np.issubdtype(dpt.full(10, 12.3, dtype=int).dtype, np.integer)
10051006
assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=int).dtype, np.integer)
1006-
assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=float).dtype, np.floating)
1007+
rdt = np.finfo(cdt).dtype
1008+
assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=rdt).dtype, np.floating)
10071009

10081010

10091011
def test_full_fill_array():

0 commit comments

Comments
 (0)