10000 Take over #16831 · wdevazelhes/scikit-learn@c60a3e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c60a3e9

Browse files
committed
2 parents e3e4a77 + a92b8a7 commit c60a3e9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

sklearn/preprocessing/_csr_polynomial_expansion.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ from numpy cimport ndarray
99
cimport numpy as np
1010

1111
np.import_array()
12-
ctypedef np.int32_t INDEX_T
12+
ctypedef fused INDEX_T:
13+
np.int32_t
14+
np.int64_t
1315

1416
ctypedef fused DATA_T:
1517
np.float32_t
@@ -120,7 +122,7 @@ def _csr_polynomial_expansion(ndarray[DATA_T, ndim=1] data,
120122

121123
cdef INDEX_T expanded_index = 0, row_starts, row_ends, i, j, k, \
122124
i_ptr, j_ptr, k_ptr, num_cols_in_row, \
123-
expanded_column
125+
expanded_column, col
124126

125127
with nogil:
126128
expanded_indptr[0] = indptr[0]

sklearn/preprocessing/_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,8 +1774,12 @@ def transform(self, X):
17741774
to_stack.append(np.ones(shape=(n_samples, 1), dtype=X.dtype))
17751775
to_stack.append(X)
17761776
for deg in range(2, self.degree+1):
1777-
Xp_next = _csr_polynomial_expansion(X.data, X.indices,
1778-
X.indptr, X.shape[1],
1777+
# use np.int64 for index datatype to prevent overflow
1778+
# in case X has a large dimension
1779+
Xp_next = _csr_polynomial_expansion(X.data,
1780+
X.indices.astype(np.int64),
1781+
X.indptr.astype(np.int64),
1782+
np.int64(X.shape[1]),
17791783
self.interaction_only,
17801784
deg)
17811785
if Xp_next is None:

0 commit comments

Comments
 (0)
0