-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
A ValueError is raised if one gives a numpy array with shape (2, 0, 1) to such Cython functions with a 3d memoryview as argument:
cimport numpy as np
import numpy as np
np.import_array()
cpdef myfunc3d(np.float64_t[:, :, ::1] arr):
if arr.size > 0:
print(arr[0, 0, 0])
else:
print('size == 0')The code to get the error:
import numpy as np
arr = np.ones((2, 0, 1))
print(arr.flags)
myfunc3d(arr)which gives:
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-81a397764d36> in <module>()
1 arr = np.ones((2, 0, 1))
2 print(arr.flags)
----> 3 myfunc3d(arr)
_cython_magic_5dfab2d7f2a0e837d79c56566c9147b4.pyx in _cython_magic_5dfab2d7f2a0e837d79c56566c9147b4.myfunc3d()
ValueError: Buffer and memoryview are not contiguous in the same dimension.
In [ ]:
Strangely, no error is raised for a shape (1, 0, 1)!
Reactions are currently unavailable