|
| 1 | +# Authors: The scikit-learn developers |
| 2 | +# SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +# See _partitioner.pyx for details. |
| 5 | +from ..utils._typedefs cimport float32_t, float64_t, intp_t, int8_t, int32_t, uint32_t |
| 6 | + |
| 7 | + |
| 8 | +# Mitigate precision differences between 32 bit and 64 bit |
| 9 | +cdef float32_t FEATURE_THRESHOLD = 1e-7 |
| 10 | + |
| 11 | + |
| 12 | +cdef class Partitioner: |
| 13 | + cdef intp_t[::1] samples |
| 14 | + cdef float32_t[::1] feature_values |
| 15 | + cdef intp_t start |
| 16 | + cdef intp_t end |
| 17 | + cdef intp_t n_missing |
| 18 | + cdef const unsigned char[::1] missing_values_in_feature_mask |
| 19 | + |
| 20 | + cdef void sort_samples_and_feature_values( |
| 21 | + self, intp_t current_feature |
| 22 | + ) noexcept nogil |
| 23 | + cdef void init_node_split( |
| 24 | + self, |
| 25 | + intp_t start, |
| 26 | + intp_t end |
| 27 | + ) noexcept nogil |
| 28 | + cdef void find_min_max( |
| 29 | + self, |
| 30 | + intp_t current_feature, |
| 31 | + float32_t* min_feature_value_out, |
| 32 | + float32_t* max_feature_value_out, |
| 33 | + ) noexcept nogil |
| 34 | + cdef void next_p( |
| 35 | + self, |
| 36 | + intp_t* p_prev, |
| 37 | + intp_t* p |
| 38 | + ) noexcept nogil |
| 39 | + cdef intp_t partition_samples( |
| 40 | + self, |
| 41 | + float64_t current_threshold |
| 42 | + ) noexcept nogil |
| 43 | + cdef void partition_samples_final( |
| 44 | + self, |
| 45 | + intp_t best_pos, |
| 46 | + float64_t best_threshold, |
| 47 | + intp_t best_feature, |
| 48 | + intp_t n_missing, |
| 49 | + ) noexcept nogil |
| 50 | + |
| 51 | + |
| 52 | +cdef class DensePartitioner(Partitioner): |
| 53 | + """Partitioner specialized for dense data. |
| 54 | +
|
| 55 | + Note that this partitioner is agnostic to the splitting strategy (best vs. random). |
| 56 | + """ |
| 57 | + cdef const float32_t[:, :] X |
| 58 | + |
| 59 | + |
| 60 | +cdef class SparsePartitioner(Partitioner): |
| 61 | + """Partitioner specialized for sparse CSC data. |
| 62 | +
|
| 63 | + Note that this partitioner is agnostic to the splitting strategy (best vs. random). |
| 64 | + """ |
| 65 | + cdef const float32_t[::1] X_data |
| 66 | + cdef const int32_t[::1] X_indices |
| 67 | + cdef const int32_t[::1] X_indptr |
| 68 | + |
| 69 | + cdef intp_t n_total_samples |
| 70 | + |
| 71 | + cdef intp_t[::1] index_to_samples |
| 72 | + cdef intp_t[::1] sorted_samples |
| 73 | + |
| 74 | + cdef intp_t start_positive |
| 75 | + cdef intp_t end_negative |
| 76 | + cdef bint is_samples_sorted |
| 77 | + |
| 78 | + cdef void extract_nnz( |
| 79 | + self, |
| 80 | + intp_t feature |
| 81 | + ) noexcept nogil |
| 82 | + cdef intp_t _partition( |
| 83 | + self, |
| 84 | + float64_t threshold, |
| 85 | + intp_t zero_pos |
| 86 | + ) noexcept nogil |
0 commit comments