According the offical doc: http://docs.cython.org/en/latest/src/tutorial/numpy.html we should "ctypedef" a corresponding compile-time type,but I tried several methods to deal with numpy.bool. It's still wrong.
1.
DTYPE2 = np.bool
ctypedef np.bool_t DTYPE2_t
raise: 'bool_t' is not a type identifier
2.
DTYPE2 = np.bint
ctypedef np.bint_t DTYPE2_t
raise: 'bint_t' is not a type identifier
3. add on the top of the .pyx file:
from libcpp cimport bool
#? As recommended by McKelvin in [https://stackoverflow.com/questions/24659723/cython-issue-bool-is-not-a-type-identifier][2]
#from libcpp cimport bool_t
from libcpp.vector cimport vector
no helpful!
4. I've seen the post: Declaring a numpy boolean mask in Cython But I need define the variable in function's parameter to pass a numpy.bool array in.
def Func(np.ndarray[np.bool_t, ndim=1] f)
## def Func(np.ndarray[np.bool, ndim=1] f)
raise: Invalid type
5. ignore the declare? It seems necessory in function's parameters according the offical doc if I want to speedup it:
def naive_convolve(np.ndarray[**DTYPE_t**, ndim=2] f, np.ndarray[DTYPE_t, ndim=2] g):
So what should I do with numpy.bool?
My test is based on the following simple codes:
import numpy as np
cimport numpy as np
cimport cython
DTYPE2 = np.bint
ctypedef np.bint_t DTYPE2_t
def Func(np.ndarray[DTYPE2_t, ndim=1] npdata):
print(npdata)
cython: the most recent version
windows7 OS
I'm sure cython was installed correctly.It can work well when there isn't np.bool.