diff --git a/generator/format.py b/generator/format.py index ab4ca34870..81deb56531 100644 --- a/generator/format.py +++ b/generator/format.py @@ -163,7 +163,7 @@ def __init__(self, name, typ, const, dflt, inpt, algo, doc): # they are passed as (ptr, dim1, dim2) if typ_cy == 'data_or_file': decl_c = "double* {0}_p, size_t {0}_nrows,"\ - " size_t {0}_ncols, ssize_t {0}_layout".format(d4pname) + " size_t {0}_ncols, Py_ssize_t {0}_layout".format(d4pname) arg_c = "data_or_file({0}_p, {0}_ncols,"\ " {0}_nrows, {0}_layout)".format(d4pname) # default values (see above pydefaults) diff --git a/requirements-dev.txt b/requirements-dev.txt index bfa239408c..b4b11d5b6d 100755 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,8 @@ -Cython==0.29.24 -Jinja2==3.0.2 +Cython==0.29.24 ; python_version <= '3.9' +Cython==0.29.25 ; python_version >= '3.10' +Jinja2==3.0.3 numpy==1.19.2 ; python_version <= '3.8' -numpy==1.19.3 ; python_version >= '3.9' +numpy==1.19.3 ; python_version == '3.9' +numpy==1.21.3 ; python_version >= '3.10' pybind11==2.8.0 cmake==3.21.3 diff --git a/src/daal4py.h b/src/daal4py.h index 55e287f526..709b767bcb 100644 --- a/src/daal4py.h +++ b/src/daal4py.h @@ -171,7 +171,7 @@ struct data_or_file mutable daal::data_management::NumericTablePtr table; std::string file; template - inline data_or_file(T * ptr, size_t ncols, size_t nrows, ssize_t layout) + inline data_or_file(T * ptr, size_t ncols, size_t nrows, Py_ssize_t layout) : table(), file() { if(layout > 0) throw std::invalid_argument("Supporting only homogeneous, contiguous arrays."); diff --git a/src/gettree.pyx b/src/gettree.pyx index d881dfecd0..3186486a06 100644 --- a/src/gettree.pyx +++ b/src/gettree.pyx @@ -31,12 +31,12 @@ cdef extern from "daal4py.h": cdef extern from "tree_visitor.h": cdef struct skl_tree_node: - ssize_t left_child - ssize_t right_child - ssize_t feature + Py_ssize_t left_child + Py_ssize_t right_child + Py_ssize_t feature double threshold double impurity - ssize_t n_node_samples + Py_ssize_t n_node_samples double weighted_n_node_samples cdef struct TreeState: diff --git a/src/tree_visitor.h b/src/tree_visitor.h index de56b7e4e6..59788c32cb 100644 --- a/src/tree_visitor.h +++ b/src/tree_visitor.h @@ -29,12 +29,12 @@ // cython will convert this struct into an numpy structured array // This is the layout that sklearn expects for its tree traversal mechanics struct skl_tree_node { - ssize_t left_child; - ssize_t right_child; - ssize_t feature; + Py_ssize_t left_child; + Py_ssize_t right_child; + Py_ssize_t feature; double threshold; double impurity; - ssize_t n_node_samples; + Py_ssize_t n_node_samples; double weighted_n_node_samples; skl_tree_node() @@ -128,7 +128,7 @@ class toSKLearnTreeObjectVisitor : public TNVT::visitor_type, public TreeStat size_t node_id; size_t max_n_classes; - std::vector parents; + std::vector parents; }; // This is the function for getting the tree state from a forest which we use in cython @@ -199,7 +199,7 @@ bool NodeDepthCountNodeVisitor::onSplitNode(const typename TNVT::split_des template toSKLearnTreeObjectVisitor::toSKLearnTreeObjectVisitor(size_t _depth, size_t _n_nodes, size_t _n_leafs, size_t _max_n_classes) : node_id(0), - parents(arange(-1, _depth-1)) + parents(arange(-1, _depth-1)) { max_n_classes = _max_n_classes; node_count = _n_nodes; @@ -216,7 +216,7 @@ bool toSKLearnTreeObjectVisitor::onSplitNode(const typename TNVT::split_de { if(desc.level > 0) { // has parents - ssize_t parent = parents[desc.level - 1]; + Py_ssize_t parent = parents[desc.level - 1]; if(node_ar[parent].left_child > 0) { assert(node_ar[node_id].right_child < 0); node_ar[parent].right_child = node_id; @@ -254,7 +254,7 @@ template bool toSKLearnTreeObjectVisitor::_onLeafNode(const daal::algorithms::tree_utils::NodeDescriptor &desc) { if(desc.level) { - ssize_t parent = parents[desc.level - 1]; + Py_ssize_t parent = parents[desc.level - 1]; if(node_ar[parent].left_child > 0) { assert(node_ar[node_id].right_child < 0); node_ar[parent].right_child = node_id;