Skip to content

Commit e17ae1f

Browse files
author
Fabian Pedregosa
committed
Test for non-contiguous input for svms
1 parent 28dcc2c commit e17ae1f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scikits/learn/svm/tests/test_svm.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,22 @@ def test_bad_input():
322322
assert_raises(ValueError, clf.fit, X, Y2)
323323

324324
# Test with arrays that are non-contiguous.
325-
Xf = np.asfortranarray(X)
326-
clf = svm.SVC()
327-
clf.fit(Xf, Y)
328-
assert_array_equal(clf.predict(T), true_result)
325+
for clf in (svm.SVC(), svm.LinearSVC(), svm.sparse.SVC(),
326+
svm.sparse.LinearSVC()):
327+
Xf = np.asfortranarray(X)
328+
assert Xf.flags['C_CONTIGUOUS'] == False
329+
yf = np.ascontiguousarray(np.tile(Y, (2,1)).T)
330+
yf = yf[:, -1]
331+
assert yf.flags['F_CONTIGUOUS'] == False
332+
assert yf.flags['C_CONTIGUOUS'] == False
333+
clf.fit(Xf, yf)
334+
assert_array_equal(clf.predict(T), true_result)
329335

330336
# error for precomputed kernelsx
331337
clf = svm.SVC(kernel='precomputed')
332338
assert_raises(ValueError, clf.fit, X, Y)
333339

334340
Xt = np.array(X).T
335-
336341
clf = svm.SVC(kernel='precomputed')
337342
clf.fit(np.dot(X, Xt), Y)
338343
assert_raises(ValueError, clf.predict, X)

0 commit comments

Comments
 (0)