2012-03-08 03:09:05 +08:00
|
|
|
"""Dataset abstractions for sequential data access. """
|
2012-02-16 04:15:45 +08:00
|
|
|
|
|
|
|
|
cimport numpy as np
|
|
|
|
|
|
2014-03-13 00:03:59 +08:00
|
|
|
# SequentialDataset and its two concrete subclasses are (optionally randomized)
|
|
|
|
|
# iterators over the rows of a matrix X and corresponding target values y.
|
2012-02-16 04:15:45 +08:00
|
|
|
|
2012-03-08 03:09:05 +08:00
|
|
|
cdef class SequentialDataset:
|
2014-03-13 00:03:59 +08:00
|
|
|
cdef int current_index
|
|
|
|
|
cdef np.ndarray index
|
|
|
|
|
cdef int *index_data_ptr
|
2012-02-16 04:15:45 +08:00
|
|
|
cdef Py_ssize_t n_samples
|
2015-05-19 16:24:22 +08:00
|
|
|
cdef np.uint32_t seed
|
2012-02-16 04:15:45 +08:00
|
|
|
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef void next(self, double **x_data_ptr, int **x_ind_ptr,
|
|
|
|
|
int *nnz, double *y, double *sample_weight) nogil
|
2014-03-13 00:03:59 +08:00
|
|
|
cdef void shuffle(self, np.uint32_t seed) nogil
|
2014-10-30 19:00:11 +08:00
|
|
|
cdef int _get_next_index(self) nogil
|
|
|
|
|
cdef int _get_random_index(self) nogil
|
|
|
|
|
|
|
|
|
|
cdef void _sample(self, double **x_data_ptr, int **x_ind_ptr,
|
|
|
|
|
int *nnz, double *y, double *sample_weight,
|
|
|
|
|
int current_index) nogil
|
|
|
|
|
cdef int random(self, double **x_data_ptr, int **x_ind_ptr,
|
|
|
|
|
int *nnz, double *y, double *sample_weight) nogil
|
2012-02-16 04:15:45 +08:00
|
|
|
|
|
|
|
|
|
2012-03-08 03:09:05 +08:00
|
|
|
cdef class ArrayDataset(SequentialDataset):
|
2015-05-19 16:24:22 +08:00
|
|
|
cdef np.ndarray X
|
|
|
|
|
cdef np.ndarray Y
|
|
|
|
|
cdef np.ndarray sample_weights
|
2012-02-16 04:15:45 +08:00
|
|
|
cdef Py_ssize_t n_features
|
|
|
|
|
cdef int stride
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef double *X_data_ptr
|
|
|
|
|
cdef double *Y_data_ptr
|
2012-02-16 04:15:45 +08:00
|
|
|
cdef np.ndarray feature_indices
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef int *feature_indices_ptr
|
|
|
|
|
cdef double *sample_weight_data
|
2012-02-16 04:15:45 +08:00
|
|
|
|
2012-03-08 03:09:05 +08:00
|
|
|
cdef class CSRDataset(SequentialDataset):
|
2015-05-19 16:24:22 +08:00
|
|
|
cdef np.ndarray X_data
|
|
|
|
|
cdef np.ndarray X_indptr
|
|
|
|
|
cdef np.ndarray X_indices
|
|
|
|
|
cdef np.ndarray Y
|
|
|
|
|
cdef np.ndarray sample_weights
|
2012-02-16 04:15:45 +08:00
|
|
|
cdef int stride
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef double *X_data_ptr
|
|
|
|
|
cdef int *X_indptr_ptr
|
|
|
|
|
cdef int *X_indices_ptr
|
|
|
|
|
cdef double *Y_data_ptr
|
2012-02-16 04:15:45 +08:00
|
|
|
cdef np.ndarray feature_indices
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef int *feature_indices_ptr
|
|
|
|
|
cdef double *sample_weight_data
|