Skip to content

Commit d42dc66

Browse files
committed
ENH: writeable and owndata flags
1 parent 3b28331 commit d42dc66

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

torch_np/_ndarray.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,18 @@ def flags(self):
115115

116116
# check if F contiguous
117117
from itertools import accumulate
118-
f_strides = tuple(accumulate(list(self._tensor.shape), func=lambda x, y: x*y))
118+
119+
f_strides = tuple(accumulate(list(self._tensor.shape), func=lambda x, y: x * y))
119120
f_strides = (1,) + f_strides[:-1]
120121
is_f_contiguous = f_strides == self._tensor.stride()
121122

122-
return Flags({"C_CONTIGUOUS": self._tensor.is_contiguous(),
123-
"F_CONTIGUOUS": is_f_contiguous,}
123+
return Flags(
124+
{
125+
"C_CONTIGUOUS": self._tensor.is_contiguous(),
126+
"F_CONTIGUOUS": is_f_contiguous,
127+
"OWNDATA": self._tensor._base is None,
128+
"WRITEABLE": True, # pytorch does not have readonly tensors
129+
}
124130
)
125131

126132
@property

0 commit comments

Comments
 (0)