Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Enable finch backend for scipy.sparse #664

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tests = [
]
tox = ["sparse[tests]", "tox"]
all = ["sparse[docs,tox]", "matrepr"]
finch = ["finch-tensor>=0.1.9"]
finch = ["finch-tensor>=0.1.10"]

[project.urls]
Documentation = "https://sparse.pydata.org/"
Expand Down
2 changes: 2 additions & 0 deletions sparse/finch_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
raise ImportError("Finch not installed. Run `pip install sparse[finch]` to enable Finch backend") from e

from finch import (
SparseArray,
abs,
acos,
acosh,
Expand Down Expand Up @@ -56,6 +57,7 @@
)

__all__ = [
"SparseArray",
"abs",
"acos",
"acosh",
Expand Down
23 changes: 19 additions & 4 deletions sparse/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import numpy as np
import scipy.sparse as sp
from numpy.testing import assert_equal
import scipy.sparse.linalg as splin
from numpy.testing import assert_almost_equal, assert_equal


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


@pytest.mark.parametrize("format", ["csc", "csr", "coo"])
def test_asarray(backend, format):
arr = np.eye(5)
@pytest.mark.parametrize("format, order", [("csc", "F"), ("csr", "C"), ("coo", "F"), ("coo", "C")])
def test_asarray(backend, format, order):
arr = np.eye(5, order=order)

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

assert_equal(result.todense(), arr)


@pytest.mark.parametrize("format, order", [("csc", "F"), ("csr", "C"), ("coo", "F"), ("coo", "C")])
def test_scipy_sparse_dispatch(backend, format, order):
x = np.eye(10, order=order) * 2
y = np.ones((10, 1), order=order)

x_sp = sparse.asarray(x, format=format)
y_sp = sparse.asarray(y, format="coo")

actual = splin.spsolve(x_sp, y_sp)
expected = np.linalg.solve(x, y.ravel())

assert_almost_equal(actual, expected)
Loading