Commit bd9131dc authored by Stefan Behnel's avatar Stefan Behnel

implement len(cython.view.array) as it seems weird that it is supported for...

implement len(cython.view.array) as it seems weird that it is supported for memoryviews but not the array type
parent 429796f0
......@@ -225,6 +225,8 @@ cdef class array:
flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
return memoryview(self, flags, self.dtype_is_object)
def __len__(self):
return self._shape[0]
def __getattr__(self, attr):
return getattr(self.memview, attr)
......
......@@ -10,6 +10,20 @@ cimport cython as cy
include "cythonarrayutil.pxi"
def length(shape):
"""
>>> len(length((2,)))
2
>>> len(length((2,3)))
2
>>> len(length((5,3,2)))
5
"""
cdef array cvarray = array(shape=shape, itemsize=sizeof(int), format="i", mode='c')
assert len(cvarray) == shape[0]
return cvarray
def contiguity():
'''
>>> contiguity()
......
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