7
7
def C (spm ):
8
8
return dict (shape = spm .shape ,
9
9
indices = (len (spm .indices ),
10
- ffi .cast ( " int32_t *" , spm .indices . ctypes . data )),
10
+ ffi .from_buffer ( ' int32_t *' , spm .indices )),
11
11
indptr = (len (spm .indptr ),
12
- ffi .cast ( " int32_t *" , spm .indptr . ctypes . data )))
12
+ ffi .from_buffer ( ' int32_t *' , spm .indptr )))
13
13
14
14
15
15
def Py (c ):
16
16
return sparse .csr_matrix (
17
- (np .ones (c .indices .len ,
18
- dtype = np . bool ), ffi .unpack (c .indices .vec , c .indices .len ),
17
+ (np .ones (c .indices .len , dtype = np . bool ), \
18
+ ffi .unpack (c .indices .vec , c .indices .len ),
19
19
ffi .unpack (c .indptr .vec , c .indptr .len )),
20
20
shape = (c .shape .rows , c .shape .cols ))
21
21
@@ -31,17 +31,17 @@ def sparsify(mat):
31
31
return sparse .csr_matrix (np .array (mat , dtype = np .int8 ))
32
32
33
33
34
- def map_features (spm , im ):
34
+ def _v (spm , im ):
35
35
spm = C (sparsify (spm ))
36
36
im = C (sparsify (im ))
37
37
assert spm ['shape' ][1 ] == im ['shape' ][1 ],\
38
38
"Number of columns of in-feature and mapping matrices must match."
39
- return Py (lib .remap_rows (spm , im ))
39
+ return spm , im
40
+
41
+
42
+ def map_features (spm , im ):
43
+ return Py (lib .remap_rows (* _v (spm , im )))
40
44
41
45
42
46
def map_features_smin (spm , im , smin ):
43
- spm = C (sparsify (spm ))
44
- im = C (sparsify (im ))
45
- assert spm ['shape' ][1 ] == im ['shape' ][1 ],\
46
- "Number of columns of in-feature and mapping matrices must match."
47
- return Py (lib .remap_rows_smin (spm , im , smin ))
47
+ return Py (lib .remap_rows_smin (* _v (spm , im ), smin ))
0 commit comments