From c92eb1caa1134834cfe7c85d861197f2a9c237b0 Mon Sep 17 00:00:00 2001 From: Martin Stancsics Date: Mon, 17 Jul 2023 18:28:34 +0200 Subject: [PATCH] Rename functions --- src/tabmat/categorical_matrix.py | 32 +++++++++++------------ src/tabmat/ext/cat_split_helpers-tmpl.cpp | 12 ++++----- src/tabmat/ext/categorical.pyx | 24 ++++++++--------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/tabmat/categorical_matrix.py b/src/tabmat/categorical_matrix.py index 0940d66a..b470aa36 100644 --- a/src/tabmat/categorical_matrix.py +++ b/src/tabmat/categorical_matrix.py @@ -168,14 +168,14 @@ def matvec(mat, vec): from scipy import sparse as sps from .ext.categorical import ( - matvec, - matvec_drop_first, - multiply_drop_first, - sandwich_categorical, - sandwich_categorical_drop_first, - subset_categorical_drop_first, - transpose_matvec, - transpose_matvec_drop_first, + matvec_complex, + matvec_fast, + multiply_complex, + sandwich_categorical_complex, + sandwich_categorical_fast, + subset_categorical_complex, + transpose_matvec_complex, + transpose_matvec_fast, ) from .ext.split import sandwich_cat_cat, sandwich_cat_dense from .matrix_base import MatrixBase @@ -330,7 +330,7 @@ def matvec( out = np.zeros(self.shape[0], dtype=other_m.dtype) if self.drop_first or self.has_missing: - matvec_drop_first( + matvec_complex( self.indices, other_m, self.shape[0], @@ -340,7 +340,7 @@ def matvec( self.drop_first, ) else: - matvec(self.indices, other_m, self.shape[0], cols, self.shape[1], out) + matvec_fast(self.indices, other_m, self.shape[0], cols, self.shape[1], out) if is_int: return out.astype(int) @@ -403,7 +403,7 @@ def transpose_matvec( cols = set_up_rows_or_cols(cols, self.shape[1]) if self.drop_first or self.has_missing: - transpose_matvec_drop_first( + transpose_matvec_complex( self.indices, vec, self.shape[1], @@ -414,7 +414,7 @@ def transpose_matvec( self.drop_first, ) else: - transpose_matvec( + transpose_matvec_fast( self.indices, vec, self.shape[1], vec.dtype, rows, cols, out ) @@ -446,11 +446,11 @@ def sandwich( d = np.asarray(d) rows = set_up_rows_or_cols(rows, self.shape[0]) if self.drop_first or self.has_missing: - res_diag = sandwich_categorical_drop_first( + res_diag = sandwich_categorical_complex( self.indices, d, rows, d.dtype, self.shape[1], self.drop_first ) else: - res_diag = sandwich_categorical( + res_diag = sandwich_categorical_fast( self.indices, d, rows, d.dtype, self.shape[1] ) @@ -490,7 +490,7 @@ def getcol(self, i: int) -> sps.csc_matrix: def tocsr(self) -> sps.csr_matrix: """Return scipy csr representation of matrix.""" if self.drop_first or self.has_missing: - nnz, indices, indptr = subset_categorical_drop_first( + nnz, indices, indptr = subset_categorical_complex( self.indices, self.shape[1], self.drop_first ) return sps.csr_matrix( @@ -633,7 +633,7 @@ def multiply(self, other) -> SparseMatrix: if self.drop_first or self.has_missing: return SparseMatrix( sps.csr_matrix( - multiply_drop_first( + multiply_complex( indices=self.indices, d=np.squeeze(other), ncols=self.shape[1], diff --git a/src/tabmat/ext/cat_split_helpers-tmpl.cpp b/src/tabmat/ext/cat_split_helpers-tmpl.cpp index bbe9aa72..77276ac1 100644 --- a/src/tabmat/ext/cat_split_helpers-tmpl.cpp +++ b/src/tabmat/ext/cat_split_helpers-tmpl.cpp @@ -1,15 +1,15 @@ #include -<%def name="transpose_matvec(dropfirst)"> +<%def name="transpose_matvec(type)"> template -void _transpose_matvec_${dropfirst}( +void _transpose_matvec_${type}( Int n_rows, Int* indices, F* other, F* res, Int res_size - % if dropfirst == 'all_rows_drop_first': + % if type == 'all_rows_complex': , bool drop_first % endif ) { @@ -18,7 +18,7 @@ void _transpose_matvec_${dropfirst}( std::vector restemp(res_size, 0.0); #pragma omp for for (Py_ssize_t i = 0; i < n_rows; i++) { - % if dropfirst == 'all_rows_drop_first': + % if type == 'all_rows_complex': Py_ssize_t col_idx = indices[i] - drop_first; if (col_idx >= 0) { restemp[col_idx] += other[i]; @@ -123,5 +123,5 @@ void _sandwich_cat_dense${order}( ${sandwich_cat_dense_tmpl('C')} ${sandwich_cat_dense_tmpl('F')} -${transpose_matvec('all_rows')} -${transpose_matvec('all_rows_drop_first')} +${transpose_matvec('all_rows_fast')} +${transpose_matvec('all_rows_complex')} diff --git a/src/tabmat/ext/categorical.pyx b/src/tabmat/ext/categorical.pyx index f28a069f..c92a0f6d 100644 --- a/src/tabmat/ext/categorical.pyx +++ b/src/tabmat/ext/categorical.pyx @@ -11,11 +11,11 @@ from libcpp cimport bool cdef extern from "cat_split_helpers.cpp": - void _transpose_matvec_all_rows[Int, F](Int, Int*, F*, F*, Int) - void _transpose_matvec_all_rows_drop_first[Int, F](Int, Int*, F*, F*, Int, bool) + void _transpose_matvec_all_rows_fast[Int, F](Int, Int*, F*, F*, Int) + void _transpose_matvec_all_rows_complex[Int, F](Int, Int*, F*, F*, Int, bool) -def transpose_matvec( +def transpose_matvec_fast( int[:] indices, floating[:] other, int n_cols, @@ -34,7 +34,7 @@ def transpose_matvec( # Case 1: No row or col restrictions if no_row_restrictions and no_col_restrictions: - _transpose_matvec_all_rows(n_rows, &indices[0], &other[0], &out[0], out_size) + _transpose_matvec_all_rows_fast(n_rows, &indices[0], &other[0], &out[0], out_size) # Case 2: row restrictions but no col restrictions elif no_col_restrictions: rows_view = rows @@ -62,7 +62,7 @@ def transpose_matvec( out[col] += other[row] -def transpose_matvec_drop_first( +def transpose_matvec_complex( int[:] indices, floating[:] other, int n_cols, @@ -82,7 +82,7 @@ def transpose_matvec_drop_first( # Case 1: No row or col restrictions if no_row_restrictions and no_col_restrictions: - _transpose_matvec_all_rows_drop_first(n_rows, &indices[0], &other[0], &out[0], out_size, drop_first) + _transpose_matvec_all_rows_complex(n_rows, &indices[0], &other[0], &out[0], out_size, drop_first) # Case 2: row restrictions but no col restrictions elif no_col_restrictions: rows_view = rows @@ -120,7 +120,7 @@ def get_col_included(int[:] cols, int n_cols): return col_included -def matvec( +def matvec_fast( const int[:] indices, floating[:] other, int n_rows, @@ -146,7 +146,7 @@ def matvec( return -def matvec_drop_first( +def matvec_complex( const int[:] indices, floating[:] other, int n_rows, @@ -175,7 +175,7 @@ def matvec_drop_first( return -def sandwich_categorical( +def sandwich_categorical_fast( const int[:] indices, floating[:] d, int[:] rows, @@ -193,7 +193,7 @@ def sandwich_categorical( return np.asarray(res) -def sandwich_categorical_drop_first( +def sandwich_categorical_complex( const int[:] indices, floating[:] d, int[:] rows, @@ -213,7 +213,7 @@ def sandwich_categorical_drop_first( return np.asarray(res) -def multiply_drop_first( +def multiply_complex( int[:] indices, numeric[:] d, int ncols, @@ -269,7 +269,7 @@ def multiply_drop_first( return new_data[:nonref_cnt], new_indices[:nonref_cnt], new_indptr -def subset_categorical_drop_first( +def subset_categorical_complex( int[:] indices, int ncols, bint drop_first