@@ -226,7 +226,7 @@ def test_dump():
226
226
for X in (X_sparse , X_dense , X_sliced ):
227
227
for y in (y_sparse , y_dense , y_sliced ):
228
228
for zero_based in (True , False ):
229
- for dtype in [np .float32 , np .float64 , np .int32 ]:
229
+ for dtype in [np .float32 , np .float64 , np .int32 , np . int64 ]:
230
230
f = BytesIO ()
231
231
# we need to pass a comment to get the version info in;
232
232
# LibSVM doesn't grok comments so they're not put in by
@@ -237,7 +237,13 @@ def test_dump():
237
237
# when it is sparse
238
238
y = y .T
239
239
240
- dump_svmlight_file (X .astype (dtype ), y , f , comment = "test" ,
240
+ # Note: with dtype=np.int32 we are performing unsafe casts,
241
+ # where X.astype(dtype) overflows. The result is
242
+ # then platform dependent and X_dense.astype(dtype) may be
243
+ # different from X_sparse.astype(dtype).asarray().
244
+ X_input = X .astype (dtype )
245
+
246
+ dump_svmlight_file (X_input , y , f , comment = "test" ,
241
247
zero_based = zero_based )
242
248
f .seek (0 )
243
249
@@ -257,17 +263,21 @@ def test_dump():
257
263
assert_array_equal (X2 .sorted_indices ().indices , X2 .indices )
258
264
259
265
X2_dense = X2 .toarray ()
266
+ if sp .issparse (X_input ):
267
+ X_input_dense = X_input .toarray ()
268
+ else :
269
+ X_input_dense = X_input
260
270
261
271
if dtype == np .float32 :
262
272
# allow a rounding error at the last decimal place
263
273
assert_array_almost_equal (
264
- X_dense . astype ( dtype ) , X2_dense , 4 )
274
+ X_input_dense , X2_dense , 4 )
265
275
assert_array_almost_equal (
266
276
y_dense .astype (dtype ), y2 , 4 )
267
277
else :
268
278
# allow a rounding error at the last decimal place
269
279
assert_array_almost_equal (
270
- X_dense . astype ( dtype ) , X2_dense , 15 )
280
+ X_input_dense , X2_dense , 15 )
271
281
assert_array_almost_equal (
272
282
y_dense .astype (dtype ), y2 , 15 )
273
283
0 commit comments