@@ -11,6 +11,7 @@ cimport numpy as np
11
11
import numpy as np
12
12
import scipy.sparse as sp
13
13
cimport cython
14
+ from cython cimport floating
14
15
15
16
np.import_array()
16
17
@@ -274,13 +275,15 @@ def incr_mean_variance_axis0(X, last_mean, last_var, unsigned long last_n):
274
275
@ cython.wraparound (False )
275
276
@ cython.cdivision (True )
276
277
def inplace_csr_row_normalize_l1 (X ):
277
- """ Inplace row normalize using the l1 norm"""
278
- cdef unsigned int n_samples = X.shape[0 ]
279
- cdef unsigned int n_features = X.shape[1 ]
278
+ _inplace_csr_row_normalize_l1(X.data, X.shape, X.indices, X.indptr)
280
279
281
- cdef np.ndarray[DOUBLE, ndim= 1 ] X_data = X.data
282
- cdef np.ndarray[int , ndim= 1 ] X_indices = X.indices
283
- cdef np.ndarray[int , ndim= 1 ] X_indptr = X.indptr
280
+
281
+ def _inplace_csr_row_normalize_l1 (np.ndarray[floating , ndim = 1 ] X_data, shape ,
282
+ np.ndarray[int , ndim = 1 ] X_indices,
283
+ np.ndarray[int , ndim = 1 ] X_indptr):
284
+ """ Inplace row normalize using the l1 norm"""
285
+ cdef unsigned int n_samples = shape[0 ]
286
+ cdef unsigned int n_features = shape[1 ]
284
287
285
288
# the column indices for row i are stored in:
286
289
# indices[indptr[i]:indices[i+1]]
@@ -309,13 +312,16 @@ def inplace_csr_row_normalize_l1(X):
309
312
@ cython.wraparound (False )
310
313
@ cython.cdivision (True )
311
314
def inplace_csr_row_normalize_l2 (X ):
312
- """ Inplace row normalize using the l2 norm"""
313
- cdef unsigned int n_samples = X.shape[0 ]
314
- cdef unsigned int n_features = X.shape[1 ]
315
+ _inplace_csr_row_normalize_l2(X.data, X.shape, X.indices, X.indptr)
315
316
316
- cdef np.ndarray[DOUBLE, ndim= 1 ] X_data = X.data
317
- cdef np.ndarray[int , ndim= 1 ] X_indices = X.indices
318
- cdef np.ndarray[int , ndi
10000
m= 1 ] X_indptr = X.indptr
317
+
318
+ 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"""
323
+ cdef unsigned int n_samples = shape[0 ]
324
+ cdef unsigned int n_features = shape[1 ]
319
325
320
326
cdef unsigned int i
321
327
cdef unsigned int j
@@ -364,7 +370,7 @@ def assign_rows_csr(X,
364
370
""" Densify selected rows of a CSR matrix into a preallocated array.
365
371
366
372
Like out[out_rows] = X[X_rows].toarray() but without copying.
367
- Only supported for dtype=np.float64.
373
+ No-copy supported for both dtype=np.float32 and dtype=np.float64.
368
374
369
375
Parameters
370
376
----------
0 commit comments