@@ -38,6 +38,9 @@ cdef extern from "numpy/arrayobject.h":
38
38
np.npy_intp* strides,
39
39
void * data, int flags, object obj)
40
40
41
+ cdef extern from " numpy/arrayobject.h" :
42
+ int PyArray_SetBaseObject(np.ndarray arr, PyObject * obj) except - 1
43
+
41
44
# =============================================================================
42
45
# Types and constants
43
46
# =============================================================================
@@ -179,10 +182,10 @@ cdef class DepthFirstTreeBuilder(TreeBuilder):
179
182
sample_weight_ptr = < DOUBLE_t* > sample_weight.data
180
183
181
184
# Initial capacity
182
- cdef int init_capacity
185
+ cdef SIZE_t init_capacity
183
186
184
187
if tree.max_depth <= 10 :
185
- init_capacity = ( 2 ** (tree.max_depth + 1 )) - 1
188
+ init_capacity = < SIZE_t > (( 2 ** (tree.max_depth + 1 )) - 1 )
186
189
else :
187
190
init_capacity = 2047
188
191
@@ -923,8 +926,7 @@ cdef class Tree:
923
926
shape[2 ] = < np.npy_intp> self .max_n_classes
924
927
cdef np.ndarray arr
925
928
arr = np.PyArray_SimpleNewFromData(3 , shape, np.NPY_DOUBLE, self .value)
926
- Py_INCREF(self )
927
- arr.base = < PyObject* > self
929
+ PyArray_SetBaseObject(arr, < PyObject* > self )
928
930
return arr
929
931
930
932
cdef np.ndarray _get_jac_ndarray(self ):
@@ -938,7 +940,7 @@ cdef class Tree:
938
940
cdef np.ndarray arr
939
941
arr = np.PyArray_SimpleNewFromData(2 , shape, np.NPY_DOUBLE, self .jac)
940
942
Py_INCREF(self )
941
- arr.base = < PyObject* > self
943
+ PyArray_SetBaseObject( arr, < PyObject* > self )
942
944
return arr
943
945
944
946
cdef np.ndarray _get_precond_ndarray(self ):
@@ -952,7 +954,7 @@ cdef class Tree:
952
954
cdef np.ndarray arr
953
955
arr = np.PyArray_SimpleNewFromData(2 , shape, np.NPY_DOUBLE, self .precond)
954
956
Py_INCREF(self )
955
- arr.base = < PyObject* > self
957
+ PyArray_SetBaseObject( arr, < PyObject* > self )
956
958
return arr
957
959
958
960
cdef np.ndarray _get_node_ndarray(self ):
@@ -970,7 +972,7 @@ cdef class Tree:
970
972
arr = PyArray_NewFromDescr(< PyTypeObject * > np.ndarray,
971
973
< np.dtype> NODE_DTYPE, 1 , shape,
972
974
strides, < void * > self .nodes,
973
- np.NPY_DEFAULT , None )
975
+ np.NPY_ARRAY_DEFAULT , None )
974
976
Py_INCREF(self )
975
- arr.base = < PyObject* > self
977
+ PyArray_SetBaseObject( arr, < PyObject* > self )
976
978
return arr
0 commit comments