Skip to content

Commit

Permalink
Rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stanmart committed Jul 17, 2023
1 parent f97eb34 commit c92eb1c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
32 changes: 16 additions & 16 deletions src/tabmat/categorical_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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)
Expand Down Expand Up @@ -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],
Expand All @@ -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
)

Expand Down Expand Up @@ -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]
)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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],
Expand Down
12 changes: 6 additions & 6 deletions src/tabmat/ext/cat_split_helpers-tmpl.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <vector>


<%def name="transpose_matvec(dropfirst)">
<%def name="transpose_matvec(type)">
template <typename Int, typename F>
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
) {
Expand All @@ -18,7 +18,7 @@ void _transpose_matvec_${dropfirst}(
std::vector<F> 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];
Expand Down Expand Up @@ -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')}
24 changes: 12 additions & 12 deletions src/tabmat/ext/categorical.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -146,7 +146,7 @@ def matvec(
return


def matvec_drop_first(
def matvec_complex(
const int[:] indices,
floating[:] other,
int n_rows,
Expand Down Expand Up @@ -175,7 +175,7 @@ def matvec_drop_first(
return


def sandwich_categorical(
def sandwich_categorical_fast(
const int[:] indices,
floating[:] d,
int[:] rows,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c92eb1c

Please sign in to comment.