I am trying to calculate the transpose of a Cython typed memoryview slice (eg. a 2D part of a 3D array). I am encountering a transpose error specifically when I try to transpose a 2D slice of a 3D memoryview array.
Here is my test code
import numpy as np
cimport numpy as cnp
cnp.import_array()
cimport cython
cdef int size_dim1 = 2
cdef int size_dim2 = 2
cdef int size_dim3 = 2
cdef int[:, ::1] arr2D = np.asarray(np.zeros((size_dim2, size_dim3), dtype = np.int32))
cdef int[:, :, ::1] arr3D = np.asarray(np.zeros((size_dim1, size_dim2, size_dim3), dtype = np.int32))
arr2D.T # works fine
arr3D.T # works fine
arr3D[0].T # error
The error I get for arr3D[0].T
is ValueError: Cannot transpose memoryview with indirect dimensions
.
I found the error in the Cython source code (source code link, line 938) and the error is raised when one of the .suboffsets
of the memoryview slice is >=0
. But I checked all of the .suboffsets
of arr3D[0]
and they are all -1
(for the first 2 dimensions). So I don't understand how this error is being raised.