69 lines
2.0 KiB
Cython
69 lines
2.0 KiB
Cython
# Authors: Gilles Louppe <g.louppe@gmail.com>
|
|
# Peter Prettenhofer <peter.prettenhofer@gmail.com>
|
|
# Arnaud Joly <arnaud.v.joly@gmail.com>
|
|
#
|
|
# Licence: BSD 3 clause
|
|
|
|
# See _utils.pyx for details.
|
|
|
|
import numpy as np
|
|
cimport numpy as np
|
|
|
|
ctypedef np.npy_intp SIZE_t # Type for indices and counters
|
|
|
|
|
|
# =============================================================================
|
|
# Stack data structure
|
|
# =============================================================================
|
|
|
|
# A record on the stack for depth-first tree growing
|
|
cdef struct StackRecord:
|
|
SIZE_t start
|
|
SIZE_t end
|
|
SIZE_t depth
|
|
SIZE_t parent
|
|
bint is_left
|
|
double impurity
|
|
SIZE_t n_constant_features
|
|
|
|
cdef class Stack:
|
|
cdef SIZE_t capacity
|
|
cdef SIZE_t top
|
|
cdef StackRecord* stack_
|
|
|
|
cdef bint is_empty(self) nogil
|
|
cdef int push(self, SIZE_t start, SIZE_t end, SIZE_t depth, SIZE_t parent,
|
|
bint is_left, double impurity,
|
|
SIZE_t n_constant_features) nogil
|
|
cdef int pop(self, StackRecord* res) nogil
|
|
|
|
|
|
# =============================================================================
|
|
# PriorityHeap data structure
|
|
# =============================================================================
|
|
|
|
# A record on the frontier for best-first tree growing
|
|
cdef struct PriorityHeapRecord:
|
|
SIZE_t node_id
|
|
SIZE_t start
|
|
SIZE_t end
|
|
SIZE_t pos
|
|
SIZE_t depth
|
|
bint is_leaf
|
|
double impurity
|
|
double impurity_left
|
|
double impurity_right
|
|
double improvement
|
|
|
|
cdef class PriorityHeap:
|
|
cdef SIZE_t capacity
|
|
cdef SIZE_t heap_ptr
|
|
cdef PriorityHeapRecord* heap_
|
|
|
|
cdef bint is_empty(self) nogil
|
|
cdef int push(self, SIZE_t node_id, SIZE_t start, SIZE_t end, SIZE_t pos,
|
|
SIZE_t depth, bint is_leaf, double improvement,
|
|
double impurity, double impurity_left,
|
|
double impurity_right) nogil
|
|
cdef int pop(self, PriorityHeapRecord* res) nogil
|