Commit 543786a4 authored by Robert Bradshaw's avatar Robert Bradshaw

Remove deprecated property syntax from MemoryView utility code.

parent 970c2fc0
...@@ -216,12 +216,14 @@ cdef class array: ...@@ -216,12 +216,14 @@ cdef class array:
free(self.data) free(self.data)
PyObject_Free(self._shape) PyObject_Free(self._shape)
property memview: @property
@cname('get_memview') def memview(self):
def __get__(self): return self.get_memview()
# Make this a property as 'self.data' may be set after instantiation
flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE @cname('get_memview')
return memoryview(self, flags, self.dtype_is_object) cdef get_memview(self):
flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
return memoryview(self, flags, self.dtype_is_object)
def __getattr__(self, attr): def __getattr__(self, attr):
...@@ -533,67 +535,58 @@ cdef class memoryview(object): ...@@ -533,67 +535,58 @@ cdef class memoryview(object):
__pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
# Some properties that have the same sematics as in NumPy # Some properties that have the same sematics as in NumPy
property T: @property
@cname('__pyx_memoryview_transpose') def T(self):
def __get__(self): cdef _memoryviewslice result = memoryview_copy(self)
cdef _memoryviewslice result = memoryview_copy(self) transpose_memslice(&result.from_slice)
transpose_memslice(&result.from_slice) return result
return result
property base: @property
@cname('__pyx_memoryview__get__base') def base(self):
def __get__(self): return self.obj
return self.obj
property shape: @property
@cname('__pyx_memoryview_get_shape') def shape(self):
def __get__(self): return tuple([length for length in self.view.shape[:self.view.ndim]])
return tuple([length for length in self.view.shape[:self.view.ndim]])
property strides: @property
@cname('__pyx_memoryview_get_strides') def strides(self):
def __get__(self): if self.view.strides == NULL:
if self.view.strides == NULL: # Note: we always ask for strides, so if this is not set it's a bug
# Note: we always ask for strides, so if this is not set it's a bug raise ValueError("Buffer view does not expose strides")
raise ValueError("Buffer view does not expose strides")
return tuple([stride for stride in self.view.strides[:self.view.ndim]]) return tuple([stride for stride in self.view.strides[:self.view.ndim]])
property suboffsets: @property
@cname('__pyx_memoryview_get_suboffsets') def suboffsets(self):
def __get__(self): if self.view.suboffsets == NULL:
if self.view.suboffsets == NULL: return (-1,) * self.view.ndim
return (-1,) * self.view.ndim
return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
property ndim: @property
@cname('__pyx_memoryview_get_ndim') def ndim(self):
def __get__(self): return self.view.ndim
return self.view.ndim
property itemsize: @property
@cname('__pyx_memoryview_get_itemsize') def itemsize(self):
def __get__(self): return self.view.itemsize
return self.view.itemsize
property nbytes: @property
@cname('__pyx_memoryview_get_nbytes') def nbytes(self):
def __get__(self): return self.size * self.view.itemsize
return self.size * self.view.itemsize
property size: @property
@cname('__pyx_memoryview_get_size') def size(self):
def __get__(self): if self._size is None:
if self._size is None: result = 1
result = 1
for length in self.view.shape[:self.view.ndim]: for length in self.view.shape[:self.view.ndim]:
result *= length result *= length
self._size = result self._size = result
return self._size return self._size
def __len__(self): def __len__(self):
if self.view.ndim >= 1: if self.view.ndim >= 1:
...@@ -981,10 +974,9 @@ cdef class _memoryviewslice(memoryview): ...@@ -981,10 +974,9 @@ cdef class _memoryviewslice(memoryview):
else: else:
memoryview.assign_item_from_object(self, itemp, value) memoryview.assign_item_from_object(self, itemp, value)
property base: @property
@cname('__pyx_memoryviewslice__get__base') def base(self):
def __get__(self): return self.from_object
return self.from_object
__pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)") __pyx_getbuffer = capsule(<void *> &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment