CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_seq_dataset.pxd.tp77 linesDownload Raw Back to utils
1{{py:
2
3"""
4Dataset abstractions for sequential data access.
5
6Template file for easily generate fused types consistent code using Tempita
7(https://github.com/cython/cython/blob/master/Cython/Tempita/_tempita.py).
8
9Generated file: _seq_dataset.pxd
10
11Each class is duplicated for all dtypes (float and double). The keywords
12between double braces are substituted during the build.
13"""
14
15# name_suffix, c_type
16dtypes = [('64', 'float64_t'),
17          ('32', 'float32_t')]
18
19}}
20"""Dataset abstractions for sequential data access."""
21
22from ._typedefs cimport float32_t, float64_t, intp_t, uint32_t
23
24# SequentialDataset and its two concrete subclasses are (optionally randomized)
25# iterators over the rows of a matrix X and corresponding target values y.
26
27{{for name_suffix, c_type in dtypes}}
28
29#------------------------------------------------------------------------------
30
31cdef class SequentialDataset{{name_suffix}}:
32    cdef int current_index
33    cdef int[::1] index
34    cdef int *index_data_ptr
35    cdef Py_ssize_t n_samples
36    cdef uint32_t seed
37
38    cdef void shuffle(self, uint32_t seed) noexcept nogil
39    cdef int _get_next_index(self) noexcept nogil
40    cdef int _get_random_index(self) noexcept nogil
41
42    cdef void _sample(self, {{c_type}} **x_data_ptr, int **x_ind_ptr,
43                      int *nnz, {{c_type}} *y, {{c_type}} *sample_weight,
44                      int current_index) noexcept nogil
45    cdef void next(self, {{c_type}} **x_data_ptr, int **x_ind_ptr,
46                   int *nnz, {{c_type}} *y, {{c_type}} *sample_weight) noexcept nogil
47    cdef int random(self, {{c_type}} **x_data_ptr, int **x_ind_ptr,
48                    int *nnz, {{c_type}} *y, {{c_type}} *sample_weight) noexcept nogil
49
50
51cdef class ArrayDataset{{name_suffix}}(SequentialDataset{{name_suffix}}):
52    cdef const {{c_type}}[:, ::1] X
53    cdef const {{c_type}}[::1] Y
54    cdef const {{c_type}}[::1] sample_weights
55    cdef Py_ssize_t n_features
56    cdef intp_t X_stride
57    cdef {{c_type}} *X_data_ptr
58    cdef {{c_type}} *Y_data_ptr
59    cdef const int[::1] feature_indices
60    cdef int *feature_indices_ptr
61    cdef {{c_type}} *sample_weight_data
62
63
64cdef class CSRDataset{{name_suffix}}(SequentialDataset{{name_suffix}}):
65    cdef const {{c_type}}[::1] X_data
66    cdef const int[::1] X_indptr
67    cdef const int[::1] X_indices
68    cdef const {{c_type}}[::1] Y
69    cdef const {{c_type}}[::1] sample_weights
70    cdef {{c_type}} *X_data_ptr
71    cdef int *X_indptr_ptr
72    cdef int *X_indices_ptr
73    cdef {{c_type}} *Y_data_ptr
74    cdef {{c_type}} *sample_weight_data
75
76{{endfor}}
77 
Aluode/PerceptionLabPortable · CoolFace