6
6
#
7
7
# Licence: BSD 3 clause
8
8
9
+ # !python
10
+ # cython: boundscheck=False, wraparound=False, cdivision=True
11
+
9
12
from libc.math cimport fabs, sqrt, pow
10
13
cimport numpy as np
11
14
import numpy as np
@@ -18,9 +21,6 @@ np.import_array()
18
21
19
22
ctypedef np.float64_t DOUBLE
20
23
21
- @ cython.boundscheck (False )
22
- @ cython.wraparound (False )
23
- @ cython.cdivision (True )
24
24
def csr_row_norms (X ):
25
25
""" L2 norm of each row in CSR matrix X."""
26
26
cdef:
@@ -46,9 +46,6 @@ def csr_row_norms(X):
46
46
return norms
47
47
48
48
49
- @ cython.boundscheck (False )
50
- @ cython.wraparound (False )
51
- @ cython.cdivision (True )
52
49
def csr_mean_variance_axis0 (X ):
53
50
""" Compute mean and variance along axis 0 on a CSR matrix
54
51
@@ -109,9 +106,6 @@ def csr_mean_variance_axis0(X):
109
106
return means, variances
110
107
111
108
112
- @ cython.boundscheck (False )
113
- @ cython.wraparound (False )
114
- @ cython.cdivision (True )
115
109
def csc_mean_variance_axis0 (X ):
116
110
""" Compute mean and variance along axis 0 on a CSC matrix
117
111
@@ -172,9 +166,6 @@ def csc_mean_variance_axis0(X):
172
166
return means, variances
173
167
174
168
175
- @ cython.boundscheck (False )
176
- @ cython.wraparound (False )
177
- @ cython.cdivision (True )
178
169
def incr_mean_variance_axis0 (X , last_mean , last_var , unsigned long last_n ):
179
170
""" Compute mean and variance along axis 0 on a CSR or CSC matrix.
180
171
@@ -271,17 +262,15 @@ def incr_mean_variance_axis0(X, last_mean, last_var, unsigned long last_n):
271
262
return updated_mean, updated_var, updated_n
272
263
273
264
274
- @ cython.boundscheck (False )
275
- @ cython.wraparound (False )
276
- @ cython.cdivision (True )
277
265
def inplace_csr_row_normalize_l1 (X ):
266
+ """ Inplace row normalize using the l1 norm"""
278
267
_inplace_csr_row_normalize_l1(X.data, X.shape, X.indices, X.indptr)
279
268
280
269
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 ,
282
272
np.ndarray[int , ndim = 1 ] X_indices,
283
273
np.ndarray[int , ndim = 1 ] X_indptr):
284
- """ Inplace row normalize using the l1 norm"""
285
274
cdef unsigned int n_samples = shape[0 ]
286
275
cdef unsigned int n_features = shape[1 ]
287
276
@@ -308,18 +297,15 @@ def _inplace_csr_row_normalize_l1(np.ndarray[floating, ndim=1] X_data, shape,
308
297
X_data[j] /= sum_
309
298
310
299
311
- @ cython.boundscheck (False )
312
- @ cython.wraparound (False )
313
- @ cython.cdivision (True )
314
300
def inplace_csr_row_normalize_l2 (X ):
301
+ """ Inplace row normalize using the l2 norm"""
315
302
_inplace_csr_row_normalize_l2(X.data, X.shape, X.indices, X.indptr)
316
303
317
304
318
305
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):
323
309
cdef unsigned int n_samples = shape[0 ]
324
310
cdef unsigned int n_features = shape[1 ]
325
311
@@ -344,8 +330,6 @@ def _inplace_csr_row_normalize_l2(np.ndarray[floating, ndim=1] X_data,
344
330
X_data[j] /= sum_
345
331
346
332
347
- @ cython.boundscheck (False )
348
- @ cython.wraparound (False )
349
333
cdef void add_row_csr(np.ndarray[np.float64_t, ndim= 1 ] data,
350
334
np.ndarray[int , ndim= 1 ] indices,
351
335
np.ndarray[int , ndim= 1 ] indptr,
@@ -361,8 +345,6 @@ cdef void add_row_csr(np.ndarray[np.float64_t, ndim=1] data,
361
345
out[j] += data[ind]
362
346
363
347
364
- @ cython.boundscheck (False )
365
- @ cython.wraparound (False )
366
348
def assign_rows_csr (X ,
367
349
np.ndarray[np.npy_intp , ndim = 1 ] X_rows,
368
350
np.ndarray[np.npy_intp , ndim = 1 ] out_rows,
0 commit comments