|
4 | 4 |
|
5 | 5 | import numpy as np
|
6 | 6 | import scipy.sparse as sp
|
7 |
| -from numpy.testing import assert_equal |
| 7 | +import scipy.sparse.linalg as splin |
| 8 | +from numpy.testing import assert_almost_equal, assert_equal |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def test_backend_contex_manager(backend):
|
@@ -58,10 +59,24 @@ def my_fun(tns1, tns2):
|
58 | 59 | assert_equal(result.todense(), np.sum(2 * np_eye, axis=0))
|
59 | 60 |
|
60 | 61 |
|
61 |
| -@pytest.mark.parametrize("format", ["csc", "csr", "coo"]) |
62 |
| -def test_asarray(backend, format): |
63 |
| - arr = np.eye(5) |
| 62 | +@pytest.mark.parametrize("format, order", [("csc", "F"), ("csr", "C"), ("coo", "F"), ("coo", "C")]) |
| 63 | +def test_asarray(backend, format, order): |
| 64 | + arr = np.eye(5, order=order) |
64 | 65 |
|
65 | 66 | result = sparse.asarray(arr, format=format)
|
66 | 67 |
|
67 | 68 | assert_equal(result.todense(), arr)
|
| 69 | + |
| 70 | + |
| 71 | +@pytest.mark.parametrize("format, order", [("csc", "F"), ("csr", "C"), ("coo", "F"), ("coo", "C")]) |
| 72 | +def test_scipy_sparse_dispatch(backend, format, order): |
| 73 | + x = np.eye(10, order=order) * 2 |
| 74 | + y = np.ones((10, 1), order=order) |
| 75 | + |
| 76 | + x_sp = sparse.asarray(x, format=format) |
| 77 | + y_sp = sparse.asarray(y, format="coo") |
| 78 | + |
| 79 | + actual = splin.spsolve(x_sp, y_sp) |
| 80 | + expected = np.linalg.solve(x, y.ravel()) |
| 81 | + |
| 82 | + assert_almost_equal(actual, expected) |
0 commit comments