Skip to content

Commit 31d438e

Browse files
committed
COSMIT: Replaced ptr1/2 with start/stop
1 parent 924db9b commit 31d438e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

sklearn/utils/sparsefuncs.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,30 @@ def swap_row_csr(X, m, n):
9797
m, n = n, m
9898

9999
indptr = X.indptr
100-
m_ptr1 = indptr[m]
101-
m_ptr2 = indptr[m + 1]
102-
n_ptr1 = indptr[n]
103-
n_ptr2 = indptr[n + 1]
104-
nz_m = m_ptr2 - m_ptr1
105-
nz_n = n_ptr2 - n_ptr1
100+
m_start = indptr[m]
101+
m_stop = indptr[m + 1]
102+
n_start = indptr[n]
103+
n_stop = indptr[n + 1]
104+
nz_m = m_stop - m_start
105+
nz_n = n_stop - n_start
106106

107107

108108
if nz_m != nz_n:
109109
# Modify indptr first
110110
X.indptr[m + 2:n] += nz_n - nz_m
111-
X.indptr[m + 1] = X.indptr[m] + nz_n
112-
X.indptr[n] = X.indptr[n + 1] - nz_m
113-
114-
X.indices = np.concatenate([X.indices[:m_ptr1], X.indices[n_ptr1:n_ptr2],
115-
X.indices[m_ptr2:n_ptr1],
116-
X.indices[m_ptr1:m_ptr2],
117-
X.indices[n_ptr2:]])
118-
X.data = np.concatenate([X.data[:m_ptr1], X.data[n_ptr1:n_ptr2],
119-
X.data[m_ptr2:n_ptr1], X.data[m_ptr1:m_ptr2],
120-
X.data[n_ptr2:]])
111+
X.indptr[m + 1] = m_start + nz_n
112+
X.indptr[n] = n_stop - nz_m
113+
114+
X.indices = np.concatenate([X.indices[:m_start],
115+
X.indices[n_start:n_stop],
116+
X.indices[m_stop:n_start],
117+
X.indices[m_start:m_stop],
118+
X.indices[n_stop:]])
119+
X.data = np.concatenate([X.data[:m_start],
120+
X.data[n_start:n_stop],
121+
X.data[m_stop:n_start],
122+
X.data[m_start:m_stop],
123+
X.data[n_stop:]])
121124

122125

123126
def swap_row(X, m, n):

0 commit comments

Comments
 (0)