2
通過一些源代碼去scikit學習,我在tree.pxd
注意到以下一些類型聲明:用Cython:正確的方式來聲明一個unsigned int
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
是否真的有必要存在?
FYI:http://stackoverflow.com/questions/20987390/cython-why-when-is-it-preferable-to-use-py-ssize-t-for-indexing –
謝謝@WarrenWeckesser。你的文章讓我做這個'__init __。pxd'文件:https://github.com/cython/cython/blob/master/Cython/Includes/numpy/__init__.pxd#L325 – hlin117