{{py:

"""
Dataset abstractions for sequential data access.

Template file for easily generate fused types consistent code using Tempita
(https://github.com/cython/cython/blob/master/Cython/Tempita/_tempita.py).

Generated file: _seq_dataset.pxd

Each class is duplicated for all dtypes (float and double). The keywords
between double braces are substituted in setup.py.
"""

# name, c_type
dtypes = [('64', 'double'),
          ('32', 'float')]

def get_dispatch(dtypes):
    for name, c_type in dtypes:
        yield name, c_type

}}
{{for name, c_type in get_dispatch(dtypes)}}

#------------------------------------------------------------------------------

"""
Dataset abstractions for sequential data access.
WARNING: Do not edit .pxd file directly, it is generated from .pxd.tp
"""

cimport numpy as np

# SequentialDataset and its two concrete subclasses are (optionally randomized)
# iterators over the rows of a matrix X and corresponding target values y.


cdef class SequentialDataset{{name}}:
    cdef int current_index
    cdef np.ndarray index
    cdef int *index_data_ptr
    cdef Py_ssize_t n_samples
    cdef np.uint32_t seed

    cdef void shuffle(self, np.uint32_t seed) nogil
    cdef int _get_next_index(self) nogil
    cdef int _get_random_index(self) nogil

    cdef void _sample(self, {{c_type}} **x_data_ptr, int **x_ind_ptr,
                      int *nnz, {{c_type}} *y, {{c_type}} *sample_weight,
                      int current_index) nogil
    cdef void next(self, {{c_type}} **x_data_ptr, int **x_ind_ptr,
                   int *nnz, {{c_type}} *y, {{c_type}} *sample_weight) nogil
    cdef int random(self, {{c_type}} **x_data_ptr, int **x_ind_ptr,
                    int *nnz, {{c_type}} *y, {{c_type}} *sample_weight) nogil


cdef class ArrayDataset{{name}}(SequentialDataset{{name}}):
    cdef np.ndarray X
    cdef np.ndarray Y
    cdef np.ndarray sample_weights
    cdef Py_ssize_t n_features
    cdef np.npy_intp X_stride
    cdef {{c_type}} *X_data_ptr
    cdef {{c_type}} *Y_data_ptr
    cdef np.ndarray feature_indices
    cdef int *feature_indices_ptr
    cdef {{c_type}} *sample_weight_data


cdef class CSRDataset{{name}}(SequentialDataset{{name}}):
    cdef np.ndarray X_data
    cdef np.ndarray X_indptr
    cdef np.ndarray X_indices
    cdef np.ndarray Y
    cdef np.ndarray sample_weights
    cdef {{c_type}} *X_data_ptr
    cdef int *X_indptr_ptr
    cdef int *X_indices_ptr
    cdef {{c_type}} *Y_data_ptr
    cdef {{c_type}} *sample_weight_data

{{endfor}}
