@@ -8,8 +8,6 @@ from scipy.sparse import csr_matrix
8
8
from numpy cimport ndarray
9
9
import numpy as np
10
10
cimport numpy as np
11
- cdef int MAX_INT32 = 2147483647
12
- # TODO: use finfo instead
13
11
14
12
np.import_array()
15
13
ctypedef fused INDEX_T:
@@ -56,7 +54,9 @@ cdef inline INDEX_T _deg3_column(INDEX_T d, INDEX_T i, INDEX_T j, INDEX_T k,
56
54
def _csr_polynomial_expansion (ndarray[DATA_T , ndim = 1 ] data,
57
55
ndarray[INDEX_T , ndim = 1 ] indices,
58
56
ndarray[INDEX_T , ndim = 1 ] indptr,
59
- INDEX_T d , INDEX_T interaction_only ,
57
+ INDEX_T d ,
58
+ INDEX_T expanded_dimensionality ,
59
+ INDEX_T interaction_only ,
60
60
INDEX_T degree ):
61
61
"""
62
62
Perform a second-degree polynomial or interaction expansion on a scipy
@@ -91,13 +91,6 @@ def _csr_polynomial_expansion(ndarray[DATA_T, ndim=1] data,
91
91
Matrices Using K-Simplex Numbers" by Andrew Nystrom and John Hughes.
92
92
"""
93
93
94
- assert degree in (2 , 3 )
95
-
96
- if degree == 2 :
97
- expanded_dimensionality = int ((d** 2 + d) / 2 - interaction_only* d)
98
- else :
99
- expanded_dimensionality = int ((d** 3 + 3 * d** 2 + 2 * d) / 6
100
- - interaction_only* d** 2 )
101
94
if expanded_dimensionality == 0 :
102
95
return None
103
96
assert expanded_dimensionality > 0
@@ -106,12 +99,7 @@ def _csr_polynomial_expansion(ndarray[DATA_T, ndim=1] data,
106
99
107
100
# Count how many nonzero elements the expanded matrix will contain.
108
101
for row_i in range (indptr.shape[0 ]- 1 ):
109
- # nnz is the number of nonzero elements in this row.
110
- # The number of nonzero elements can explode
111
- # in the expanded space, so we cast to int64
112
- # before the expansion computation to
113
- # avoid overflow:
114
- nnz = np.int64(indptr[row_i + 1 ] - indptr[row_i])
102
+ nnz = indptr[row_i + 1 ] - indptr[row_i]
115
103
# TODO: check that the casting is indeed done
116
104
if degree == 2 :
117
105
total_nnz += (nnz ** 2 + nnz) / 2 - interaction_only * nnz
@@ -128,16 +116,6 @@ def _csr_polynomial_expansion(ndarray[DATA_T, ndim=1] data,
128
116
cdef ndarray[INDEX_T, ndim= 1 ] expanded_indptr = ndarray(
129
117
shape = num_rows + 1 , dtype = indptr.dtype)
130
118
131
- # if the expanded_dimensionality is too big, we need to cast
132
- # indices to int64. If total_nnz is too big, we need to cast
133
- # expanded_indptr to int64 too.
134
- # TODO: check that the casting is indeed done
135
- if expanded_dimensionality > MAX_INT32:
136
- indices = np.array(indices, dtype = np.int64)
137
- expanded_indices = np.array(expanded_indices, dtype = np.int64)
138
- if total_nnz > MAX_INT32:
139
- expanded_indptr = np.array(expanded_indptr, dtype = np.int64)
140
-
141
119
cdef INDEX_T expanded_index = 0 , row_starts, row_ends, i, j, k, \
142
120
i_ptr, j_ptr, k_ptr, num_cols_in_row, col
143
121
0 commit comments