Skip to content

Commit 1cdc2a6

Browse files
authored
Merge pull request #928 from IntelPython/flags-cleanup
Changed instances of writeable to writable, added docstrings to _flags.pyx
2 parents 051e473 + 5e40d55 commit 1cdc2a6

File tree

7 files changed

+53
-18
lines changed

7 files changed

+53
-18
lines changed

dpctl/memory/_memory.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ cdef class _Memory:
207207
self.memory_ptr = other_buf.p
208208
self.nbytes = other_buf.nbytes
209209
self.queue = other_buf.queue
210-
# self.writeable = other_buf.writeable
210+
# self.writable = other_buf.writable
211211
self.refobj = other
212212
else:
213213
raise ValueError(
@@ -333,7 +333,7 @@ cdef class _Memory:
333333
def __get__(self):
334334
cdef dict iface = {
335335
"data": (<size_t>(<void *>self.memory_ptr),
336-
True), # bool(self.writeable)),
336+
True), # bool(self.writable)),
337337
"shape": (self.nbytes,),
338338
"strides": None,
339339
"typestr": "|u1",

dpctl/memory/_sycl_usm_array_interface_utils.pxi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ cdef class _USMBufferData:
122122
`__sycl_usm_array_interface__` dictionary
123123
"""
124124
cdef DPCTLSyclUSMRef p
125-
cdef int writeable
125+
cdef int writable
126126
cdef object dt
127127
cdef Py_ssize_t itemsize
128128
cdef Py_ssize_t nbytes
@@ -140,7 +140,7 @@ cdef class _USMBufferData:
140140
cdef size_t arr_data_ptr = 0
141141
cdef DPCTLSyclUSMRef memRef = NULL
142142
cdef Py_ssize_t itemsize = -1
143-
cdef int writeable = -1
143+
cdef int writable = -1
144144
cdef int nd = -1
145145
cdef DPCTLSyclQueueRef QRef = NULL
146146
cdef object dt
@@ -156,9 +156,9 @@ cdef class _USMBufferData:
156156
if not ary_data_tuple or len(ary_data_tuple) != 2:
157157
raise ValueError("__sycl_usm_array_interface__ is malformed:"
158158
" 'data' field is required, and must be a tuple"
159-
" (usm_pointer, is_writeable_boolean).")
159+
" (usm_pointer, is_writable_boolean).")
160160
arr_data_ptr = <size_t>ary_data_tuple[0]
161-
writeable = 1 if ary_data_tuple[1] else 0
161+
writable = 1 if ary_data_tuple[1] else 0
162162
# Check that memory and syclobj are consistent:
163163
# (USM pointer is bound to this sycl context)
164164
memRef = <DPCTLSyclUSMRef>arr_data_ptr
@@ -207,7 +207,7 @@ cdef class _USMBufferData:
207207
buf = _USMBufferData.__new__(_USMBufferData)
208208
buf.p = <DPCTLSyclUSMRef>(
209209
arr_data_ptr + (<Py_ssize_t>min_disp) * itemsize)
210-
buf.writeable = writeable
210+
buf.writable = writable
211211
buf.itemsize = itemsize
212212
buf.nbytes = <Py_ssize_t> nbytes
213213

dpctl/tensor/_flags.pyx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from libcpp cimport bool as cpp_bool
2323
from dpctl.tensor._usmarray cimport (
2424
USM_ARRAY_C_CONTIGUOUS,
2525
USM_ARRAY_F_CONTIGUOUS,
26-
USM_ARRAY_WRITEABLE,
26+
USM_ARRAY_WRITABLE,
2727
usm_ndarray,
2828
)
2929

@@ -33,7 +33,10 @@ cdef cpp_bool _check_bit(int flag, int mask):
3333

3434

3535
cdef class Flags:
36-
"""Helper class to represent flags of :class:`dpctl.tensor.usm_ndarray`."""
36+
"""
37+
Helper class to represent memory layout flags of
38+
:class:`dpctl.tensor.usm_ndarray`.
39+
"""
3740
cdef int flags_
3841
cdef usm_ndarray arr_
3942

@@ -43,51 +46,83 @@ cdef class Flags:
4346

4447
@property
4548
def flags(self):
49+
"""
50+
Integer representation of the memory layout flags of
51+
:class:`dpctl.tensor.usm_ndarray` instance.
52+
"""
4653
return self.flags_
4754

4855
@property
4956
def c_contiguous(self):
57+
"""
58+
True if the memory layout of the
59+
:class:`dpctl.tensor.usm_ndarray` instance is C-contiguous.
60+
"""
5061
return _check_bit(self.flags_, USM_ARRAY_C_CONTIGUOUS)
5162

5263
@property
5364
def f_contiguous(self):
65+
"""
66+
True if the memory layout of the
67+
:class:`dpctl.tensor.usm_ndarray` instance is F-contiguous.
68+
"""
5469
return _check_bit(self.flags_, USM_ARRAY_F_CONTIGUOUS)
5570

5671
@property
5772
def writable(self):
58-
return _check_bit(self.flags_, USM_ARRAY_WRITEABLE)
73+
"""
74+
True if :class:`dpctl.tensor.usm_ndarray` instance is writable.
75+
"""
76+
return _check_bit(self.flags_, USM_ARRAY_WRITABLE)
5977

6078
@property
6179
def fc(self):
80+
"""
81+
True if the memory layout of the :class:`dpctl.tensor.usm_ndarray`
82+
instance is C-contiguous and F-contiguous.
83+
"""
6284
return (
6385
_check_bit(self.flags_, USM_ARRAY_C_CONTIGUOUS)
6486
and _check_bit(self.flags_, USM_ARRAY_F_CONTIGUOUS)
6587
)
6688

6789
@property
6890
def forc(self):
91+
"""
92+
True if the memory layout of the :class:`dpctl.tensor.usm_ndarray`
93+
instance is C-contiguous or F-contiguous.
94+
"""
6995
return (
7096
_check_bit(self.flags_, USM_ARRAY_C_CONTIGUOUS)
7197
or _check_bit(self.flags_, USM_ARRAY_F_CONTIGUOUS)
7298
)
7399

74100
@property
75101
def fnc(self):
102+
"""
103+
True if the memory layout of the :class:`dpctl.tensor.usm_ndarray`
104+
instance is F-contiguous and not C-contiguous.
105+
"""
76106
return (
77107
_check_bit(self.flags_, USM_ARRAY_C_CONTIGUOUS)
78108
and not _check_bit(self.flags_, USM_ARRAY_F_CONTIGUOUS)
79109
)
80110

81111
@property
82112
def contiguous(self):
113+
"""
114+
True if the memory layout of the :class:`dpctl.tensor.usm_ndarray`
115+
instance is C-contiguous and F-contiguous.
116+
Equivalent to `forc.`
117+
"""
83118
return self.forc
84119

85120
def __getitem__(self, name):
86121
if name in ["C_CONTIGUOUS", "C"]:
87122
return self.c_contiguous
88123
elif name in ["F_CONTIGUOUS", "F"]:
89124
return self.f_contiguous
90-
elif name == "WRITABLE":
125+
elif name in ["WRITABLE", "W"]:
91126
return self.writable
92127
elif name == "FC":
93128
return self.fc

dpctl/tensor/_stride_utils.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cdef int ERROR_UNEXPECTED_STRIDES = 3
2929

3030
cdef int USM_ARRAY_C_CONTIGUOUS = 1
3131
cdef int USM_ARRAY_F_CONTIGUOUS = 2
32-
cdef int USM_ARRAY_WRITEABLE = 4
32+
cdef int USM_ARRAY_WRITABLE = 4
3333

3434

3535
cdef Py_ssize_t shape_to_elem_count(int nd, Py_ssize_t *shape_arr):

dpctl/tensor/_usmarray.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cimport dpctl
2222

2323
cdef public api int USM_ARRAY_C_CONTIGUOUS
2424
cdef public api int USM_ARRAY_F_CONTIGUOUS
25-
cdef public api int USM_ARRAY_WRITEABLE
25+
cdef public api int USM_ARRAY_WRITABLE
2626

2727
cdef public api int UAR_BOOL
2828
cdef public api int UAR_BYTE

dpctl/tensor/_usmarray.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ cdef class usm_ndarray:
366366
ary_iface = self.base_.__sycl_usm_array_interface__
367367
mem_ptr = <char *>(<size_t> ary_iface['data'][0])
368368
ary_ptr = <char *>(<size_t> self.data_)
369-
ro_flag = False if (self.flags_ & USM_ARRAY_WRITEABLE) else True
369+
ro_flag = False if (self.flags_ & USM_ARRAY_WRITABLE) else True
370370
ary_iface['data'] = (<size_t> mem_ptr, ro_flag)
371371
ary_iface['shape'] = self.shape
372372
if (self.strides_):
@@ -637,7 +637,7 @@ cdef class usm_ndarray:
637637
buffer=self.base_,
638638
offset=_meta[2]
639639
)
640-
res.flags_ |= (self.flags_ & USM_ARRAY_WRITEABLE)
640+
res.flags_ |= (self.flags_ & USM_ARRAY_WRITABLE)
641641
res.array_namespace_ = self.array_namespace_
642642
return res
643643

@@ -1175,7 +1175,7 @@ cdef usm_ndarray _transpose(usm_ndarray ary):
11751175
order=('F' if (ary.flags_ & USM_ARRAY_C_CONTIGUOUS) else 'C'),
11761176
offset=ary.get_offset()
11771177
)
1178-
r.flags_ |= (ary.flags_ & USM_ARRAY_WRITEABLE)
1178+
r.flags_ |= (ary.flags_ & USM_ARRAY_WRITABLE)
11791179
return r
11801180

11811181

@@ -1192,7 +1192,7 @@ cdef usm_ndarray _m_transpose(usm_ndarray ary):
11921192
order=('F' if (ary.flags_ & USM_ARRAY_C_CONTIGUOUS) else 'C'),
11931193
offset=ary.get_offset()
11941194
)
1195-
r.flags_ |= (ary.flags_ & USM_ARRAY_WRITEABLE)
1195+
r.flags_ |= (ary.flags_ & USM_ARRAY_WRITABLE)
11961196
return r
11971197

11981198

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def test_pyx_capi_check_constants():
517517
assert cc_flag > 0 and 0 == (cc_flag & (cc_flag - 1))
518518
fc_flag = _pyx_capi_int(X, "USM_ARRAY_F_CONTIGUOUS")
519519
assert fc_flag > 0 and 0 == (fc_flag & (fc_flag - 1))
520-
w_flag = _pyx_capi_int(X, "USM_ARRAY_WRITEABLE")
520+
w_flag = _pyx_capi_int(X, "USM_ARRAY_WRITABLE")
521521
assert w_flag > 0 and 0 == (w_flag & (w_flag - 1))
522522

523523
bool_typenum = _pyx_capi_int(X, "UAR_BOOL")

0 commit comments

Comments
 (0)