Skip to content

Commit 5111288

Browse files
committed
make subfunction private
1 parent 14175c7 commit 5111288

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

sklearn/utils/sparsefuncs_fast.pyx

+10-28
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#
77
# Licence: BSD 3 clause
88

9+
#!python
10+
#cython: boundscheck=False, wraparound=False, cdivision=True
11+
912
from libc.math cimport fabs, sqrt, pow
1013
cimport numpy as np
1114
import numpy as np
@@ -18,9 +21,6 @@ np.import_array()
1821

1922
ctypedef np.float64_t DOUBLE
2023

21-
@cython.boundscheck(False)
22-
@cython.wraparound(False)
23-
@cython.cdivision(True)
2424
def csr_row_norms(X):
2525
"""L2 norm of each row in CSR matrix X."""
2626
cdef:
@@ -46,9 +46,6 @@ def csr_row_norms(X):
4646
return norms
4747

4848

49-
@cython.boundscheck(False)
50-
@cython.wraparound(False)
51-
@cython.cdivision(True)
5249
def csr_mean_variance_axis0(X):
5350
"""Compute mean and variance along axis 0 on a CSR matrix
5451
@@ -109,9 +106,6 @@ def csr_mean_variance_axis0(X):
109106
return means, variances
110107

111108

112-
@cython.boundscheck(False)
113-
@cython.wraparound(False)
114-
@cython.cdivision(True)
115109
def csc_mean_variance_axis0(X):
116110
"""Compute mean and variance along axis 0 on a CSC matrix
117111
@@ -172,9 +166,6 @@ def csc_mean_variance_axis0(X):
172166
return means, variances
173167

174168

175-
@cython.boundscheck(False)
176-
@cython.wraparound(False)
177-
@cython.cdivision(True)
178169
def incr_mean_variance_axis0(X, last_mean, last_var, unsigned long last_n):
179170
"""Compute mean and variance along axis 0 on a CSR or CSC matrix.
180171
@@ -271,17 +262,15 @@ def incr_mean_variance_axis0(X, last_mean, last_var, unsigned long last_n):
271262
return updated_mean, updated_var, updated_n
272263

273264

274-
@cython.boundscheck(False)
275-
@cython.wraparound(False)
276-
@cython.cdivision(True)
277265
def inplace_csr_row_normalize_l1(X):
266+
"""Inplace row normalize using the l1 norm"""
278267
_inplace_csr_row_normalize_l1(X.data, X.shape, X.indices, X.indptr)
279268

280269

281-
def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data, shape,
270+
def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data,
271+
shape,
282272
np.ndarray[int, ndim=1] X_indices,
283273
np.ndarray[int, ndim=1] X_indptr):
284-
"""Inplace row normalize using the l1 norm"""
285274
cdef unsigned int n_samples = shape[0]
286275
cdef unsigned int n_features = shape[1]
287276

@@ -308,18 +297,15 @@ def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data, shape,
308297
X_data[j] /= sum_
309298

310299

311-
@cython.boundscheck(False)
312-
@cython.wraparound(False)
313-
@cython.cdivision(True)
314300
def inplace_csr_row_normalize_l2(X):
301+
"""Inplace row normalize using the l2 norm"""
315302
_inplace_csr_row_normalize_l2(X.data, X.shape, X.indices, X.indptr)
316303

317304

318305
def _inplace_csr_row_normalize_l2(np.ndarray[floating, ndim=1] X_data,
319-
shape,
320-
np.ndarray[int, ndim=1] X_indices,
321-
np.ndarray[int, ndim=1] X_indptr):
322-
"""Inplace row normalize using the l2 norm"""
306+
shape,
307+
np.ndarray[int, ndim=1] X_indices,
308+
np.ndarray[int, ndim=1] X_indptr):
323309
cdef unsigned int n_samples = shape[0]
324310
cdef unsigned int n_features = shape[1]
325311

@@ -344,8 +330,6 @@ def _inplace_csr_row_normalize_l2(np.ndarray[floating, ndim=1] X_data,
344330
X_data[j] /= sum_
345331

346332

347-
@cython.boundscheck(False)
348-
@cython.wraparound(False)
349333
cdef void add_row_csr(np.ndarray[np.float64_t, ndim=1] data,
350334
np.ndarray[int, ndim=1] indices,
351335
np.ndarray[int, ndim=1] indptr,
@@ -361,8 +345,6 @@ cdef void add_row_csr(np.ndarray[np.float64_t, ndim=1] data,
361345
out[j] += data[ind]
362346

363347

364-
@cython.boundscheck(False)
365-
@cython.wraparound(False)
366348
def assign_rows_csr(X,
367349
np.ndarray[np.npy_intp, ndim=1] X_rows,
368350
np.ndarray[np.npy_intp, ndim=1] out_rows,

0 commit comments

Comments
 (0)