首页 > 解决方案 > 在 sklearn 源代码中输入 cython 的 SIZE_t

问题描述

我尝试基于此实现 sklearn 的 Criterion 对象的一个​​子集: https ://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_criterion.pyx#L54 。

但是,当我尝试在我的 jupyter 笔记本中运行代码时,它收到一条错误消息,提示 TypeError: object of type 'NoneType' has no len()并且有一些**^**指针指向我在 init 函数中的参数类型,如下所示:

cdef int init(self, const DOUBLE_t[:, ::1] y, DOUBLE_t* sample_weight,
                  double weighted_n_samples, SIZE_t* samples, 
                  SIZE_t start, SIZE_t end):

我尝试将类型SIZE_t 更改为 size_t并将DOUBLE_t 更改为 double,并且错误消失了。但我不确定为什么源代码中包含 SIZE_t 和 DOUBLE_t,以及在我的代码中仅使用 size_t 和 double 作为类型是否安全。谢谢。

可能这与 C 类型有某种关系,但我不确定。

标签: scikit-learncython

解决方案


推荐阅读