File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,19 @@ def test_unsorted_indices():
111
111
# make sure dense and sparse SVM give the same result
112
112
assert_array_almost_equal (coef_dense , coef_sorted .toarray ())
113
113
114
- X_sparse_unsorted = X_sparse [np .arange (X .shape [0 ])]
115
- X_test_unsorted = X_test [np .arange (X_test .shape [0 ])]
114
+ # reverse each row's indices
115
+ def scramble_indices (X ):
116
+ new_data = []
117
+ new_indices = []
118
+ for i in range (1 , len (X .indptr )):
119
+ row_slice = slice (* X .indptr [i - 1 : i + 1 ])
120
+ new_data .extend (X .data [row_slice ][::- 1 ])
121
+ new_indices .extend (X .indices [row_slice ][::- 1 ])
122
+ return sparse .csr_matrix ((new_data , new_indices , X .indptr ),
123
+ shape = X .shape )
124
+
125
+ X_sparse_unsorted = scramble_indices (X_sparse )
126
+ X_test_unsorted = scramble_indices (X_test )
116
127
117
128
# make sure we scramble the indices
118
129
assert_false (X_sparse_unsorted .has_sorted_indices )
You can’t perform that action at this time.
0 commit comments