在scikit-learn中查看一些源代码,我在tree.pxd
中注意到以下一些类型声明:
import numpy as np
cimport numpy as np
ctypedef np.npy_float32 DTYPE_t # Type of X
ctypedef np.npy_float64 DOUBLE_t # Type of y, sample_weight
ctypedef np.npy_intp SIZE_t # Type for indices and counters
ctypedef np.npy_int32 INT32_t # Signed 32 bit integer
ctypedef np.npy_uint32 UINT32_t # Unsigned 32 bit integer
我知道Cython docs here关于C类型和cython类型之间的区别有一些讨论,但这些类型似乎是来自numpy的类型,并且在文档中没有提到它们。
我对我应该使用的类型感到困惑。对于索引,我应该使用上面定义的SIZE_t
还是unsigned int
?这些ctypedef
确实存在吗?
答案 0 :(得分:3)
根据init.pxd file对于cython的numpy,似乎unsigned int
与npy_uint32
完全相同。
另一方面,根据文件的this line,npy_intp
与Py_intptr_t
相同。而且我很确定这意味着指针的大小,它对应于数组中项目之间的间距等。
我认为基于this discussion,不提及Py_intptr_t
是首选,以适应架构差异。因此,要真正确定建筑住宿,应使用npy_intp
。