Skip to content

Commit 705699f

Browse files
authored
API: Enable finch backend for scipy.sparse (#664)
1 parent 5bd2df6 commit 705699f

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tests = [
3838
]
3939
tox = ["sparse[tests]", "tox"]
4040
all = ["sparse[docs,tox]", "matrepr"]
41-
finch = ["finch-tensor>=0.1.9"]
41+
finch = ["finch-tensor>=0.1.10"]
4242

4343
[project.urls]
4444
Documentation = "https://sparse.pydata.org/"

sparse/finch_backend/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
raise ImportError("Finch not installed. Run `pip install sparse[finch]` to enable Finch backend") from e
55

66
from finch import (
7+
SparseArray,
78
abs,
89
acos,
910
acosh,
@@ -56,6 +57,7 @@
5657
)
5758

5859
__all__ = [
60+
"SparseArray",
5961
"abs",
6062
"acos",
6163
"acosh",

sparse/tests/test_backends.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import numpy as np
66
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
89

910

1011
def test_backend_contex_manager(backend):
@@ -58,10 +59,24 @@ def my_fun(tns1, tns2):
5859
assert_equal(result.todense(), np.sum(2 * np_eye, axis=0))
5960

6061

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)
6465

6566
result = sparse.asarray(arr, format=format)
6667

6768
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

Comments
 (0)