Skip to content

Commit 1ff104f

Browse files
authored
Merge branch 'main' into binsparse-dlpack
2 parents 148d1aa + 0fede67 commit 1ff104f

18 files changed

+143
-256
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Build and install Sparse
6969
run: |
7070
pip install -U setuptools wheel
71-
pip install '.[finch]' scipy
71+
pip install '.[finch]' scipy dask networkx graphblas-algorithms
7272
- name: Run examples
7373
run: ci/test_examples.sh
7474

@@ -84,7 +84,8 @@ jobs:
8484
cache: 'pip'
8585
- name: Build and install Sparse
8686
run: |
87-
pip install -e '.[notebooks]'
87+
pip install -U setuptools wheel
88+
pip install '.[notebooks]'
8889
- name: Run notebooks
8990
run: ci/test_notebooks.sh
9091

@@ -111,6 +112,7 @@ jobs:
111112
pip install pytest-xdist -r "$ARRAY_API_TESTS_DIR/requirements.txt"
112113
- name: Build and install Sparse
113114
run: |
115+
pip install -U setuptools wheel
114116
pip install '.[finch]'
115117
- name: Run the test suite
116118
env:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
exclude: ".ipynb"
1919

2020
- repo: https://github.com/astral-sh/ruff-pre-commit
21-
rev: v0.9.6
21+
rev: v0.11.2
2222
hooks:
2323
- id: ruff
2424
args: ["--fix"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
- 🙌 [Contributing](https://github.com/pydata/sparse/blob/main/docs/contributing.md)
1717

1818
- 🪲 [Bug Reports/Feature Requests](https://github.com/pydata/sparse/issues)
19+
20+
- 💬 [Discord Server](https://discord.gg/vur45CbwMz) [Channel](https://discord.com/channels/786703927705862175/1301155724646289420)

ci/Finch-array-api-skips.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ array_api_tests/test_searching_functions.py::test_nonzero_zerodim_error
44
array_api_tests/test_special_cases.py::test_unary[sign((x_i is -0 or x_i == +0)) -> 0]
55
# `broadcast_to` is not defined in Finch, hangs as xfail
66
array_api_tests/test_searching_functions.py::test_where
7+
# `test_solve` is not defined in Finch, hangs as xfail
8+
array_api_tests/test_linalg.py::test_solve

ci/Finch-array-api-xfails.txt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ array_api_tests/test_signatures.py::test_func_signature[argmin]
3636
array_api_tests/test_signatures.py::test_func_signature[from_dlpack]
3737
array_api_tests/test_signatures.py::test_func_signature[cumulative_sum]
3838
array_api_tests/test_signatures.py::test_func_signature[searchsorted]
39-
array_api_tests/test_signatures.py::test_func_signature[moveaxis]
4039
array_api_tests/test_signatures.py::test_func_signature[repeat]
4140
array_api_tests/test_signatures.py::test_func_signature[tile]
4241
array_api_tests/test_signatures.py::test_func_signature[unstack]
@@ -59,7 +58,17 @@ array_api_tests/test_signatures.py::test_extension_func_signature[linalg.pinv]
5958
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.svdvals]
6059
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.tensordot]
6160
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.vecdot]
62-
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.vector_norm]
61+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.det]
62+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.diagonal]
63+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.eigh]
64+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.eigvalsh]
65+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.inv]
66+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.matrix_power]
67+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.qr]
68+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.slogdet]
69+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.solve]
70+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.svd]
71+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.trace]
6372
# Array object namespace
6473
array_api_tests/test_signatures.py::test_array_method_signature[__dlpack__]
6574
array_api_tests/test_signatures.py::test_array_method_signature[__dlpack_device__]
@@ -116,7 +125,6 @@ array_api_tests/test_has_names.py::test_has_names[linalg-svdvals]
116125
array_api_tests/test_has_names.py::test_has_names[linalg-tensordot]
117126
array_api_tests/test_has_names.py::test_has_names[linalg-trace]
118127
array_api_tests/test_has_names.py::test_has_names[linalg-vecdot]
119-
array_api_tests/test_has_names.py::test_has_names[linalg-vector_norm]
120128
array_api_tests/test_has_names.py::test_has_names[statistical-cumulative_sum]
121129
array_api_tests/test_has_names.py::test_has_names[statistical-mean]
122130
array_api_tests/test_has_names.py::test_has_names[statistical-std]
@@ -137,7 +145,6 @@ array_api_tests/test_has_names.py::test_has_names[manipulation-broadcast_to]
137145
array_api_tests/test_has_names.py::test_has_names[manipulation-concat]
138146
array_api_tests/test_has_names.py::test_has_names[manipulation-expand_dims]
139147
array_api_tests/test_has_names.py::test_has_names[manipulation-flip]
140-
array_api_tests/test_has_names.py::test_has_names[manipulation-moveaxis]
141148
array_api_tests/test_has_names.py::test_has_names[manipulation-repeat]
142149
array_api_tests/test_has_names.py::test_has_names[manipulation-roll]
143150
array_api_tests/test_has_names.py::test_has_names[manipulation-squeeze]
@@ -162,7 +169,6 @@ array_api_tests/test_has_names.py::test_has_names[array_method-__dlpack__]
162169
array_api_tests/test_has_names.py::test_has_names[array_method-__dlpack_device__]
163170
array_api_tests/test_has_names.py::test_has_names[array_method-__setitem__]
164171
array_api_tests/test_has_names.py::test_has_names[array_attribute-T]
165-
array_api_tests/test_has_names.py::test_has_names[array_attribute-mT]
166172

167173
# test_indexing_functions
168174

@@ -174,6 +180,27 @@ array_api_tests/test_indexing_functions.py::test_take
174180
# not implemented
175181
array_api_tests/test_linalg.py::test_matrix_transpose
176182
array_api_tests/test_linalg.py::test_vecdot
183+
array_api_tests/test_linalg.py::test_eigh
184+
array_api_tests/test_linalg.py::test_eigvalsh
185+
array_api_tests/test_linalg.py::test_inv
186+
array_api_tests/test_linalg.py::test_linalg_matmul
187+
array_api_tests/test_linalg.py::test_matrix_norm
188+
array_api_tests/test_linalg.py::test_matrix_power
189+
array_api_tests/test_linalg.py::test_matrix_rank
190+
array_api_tests/test_linalg.py::test_linalg_matrix_transpose
191+
array_api_tests/test_linalg.py::test_outer
192+
array_api_tests/test_linalg.py::test_pinv
193+
array_api_tests/test_linalg.py::test_qr
194+
array_api_tests/test_linalg.py::test_slogdet
195+
array_api_tests/test_linalg.py::test_cholesky
196+
array_api_tests/test_linalg.py::test_det
197+
array_api_tests/test_linalg.py::test_diagonal
198+
array_api_tests/test_linalg.py::test_vector_norm
199+
array_api_tests/test_linalg.py::test_svdvals
200+
array_api_tests/test_linalg.py::test_svd
201+
array_api_tests/test_linalg.py::test_trace
202+
array_api_tests/test_linalg.py::test_linalg_vecdot
203+
array_api_tests/test_linalg.py::test_linalg_tensordot
177204

178205
# test_manipulation_functions
179206

ci/Numba-array-api-xfails.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ array_api_tests/test_has_names.py::test_has_names[array_method-__dlpack__]
4141
array_api_tests/test_has_names.py::test_has_names[array_method-__dlpack_device__]
4242
array_api_tests/test_has_names.py::test_has_names[array_method-__setitem__]
4343
array_api_tests/test_indexing_functions.py::test_take
44-
array_api_tests/test_linalg.py::test_vecdot
4544
array_api_tests/test_set_functions.py::test_unique_all
4645
array_api_tests/test_set_functions.py::test_unique_inverse
4746
array_api_tests/test_signatures.py::test_func_signature[unique_all]

ci/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies:
66
- python
77
- pip
88
- pip:
9-
- finch-tensor>=0.2.4
9+
- finch-tensor>=0.2.10
1010
- finch-mlir>=0.0.2
1111
- pytest-codspeed
1212
- numpy

ci/test_examples.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
set -euxo pipefail
33

4-
for example in $(find ./docs/examples/ -iname *.py); do
4+
for example in $(find ./examples/ -iname '*.py'); do
55
CI_MODE=1 python $example
66
done

docs/operations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ z[:3, :2, [1, 5]]
253253

254254
**Package Configuration**
255255

256-
By default, when performing something like `np.array(COO)`, we allow the array
257-
to be converted into a dense one. To prevent this and raise a [`RuntimeError`][]
258-
instead, set the environment variable `SPARSE_AUTO_DENSIFY` to `0`.
256+
By default, when performing something like `np.array(COO)`, we do not allow the
257+
array to be converted into a dense one and it raise a [`RuntimeError`][].
258+
To prevent this, set the environment variable `SPARSE_AUTO_DENSIFY` to `1`.
259259

260260
If it is desired to raise a warning if creating a sparse array that takes no less
261261
memory than an equivalent desne array, set the environment variable

examples/hits_example.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
from typing import Any
3+
4+
import graphblas as gb
5+
import graphblas_algorithms as ga
6+
7+
import numpy as np
8+
import scipy.sparse as sps
9+
from numpy.testing import assert_allclose
10+
11+
os.environ["SPARSE_BACKEND"] = "Finch"
12+
import sparse
13+
14+
# select namespace
15+
xp = sparse # np jnp
16+
Array = Any
17+
18+
19+
def converged(xprev: Array, x: Array, N: int, tol: float) -> bool:
20+
err = xp.sum(xp.abs(x - xprev))
21+
return err < xp.asarray(N * tol)
22+
23+
24+
class Graph:
25+
def __init__(self, A: Array):
26+
assert A.ndim == 2 and A.shape[0] == A.shape[1]
27+
self.N = A.shape[0]
28+
self.A = A
29+
30+
31+
@sparse.compiled()
32+
def kernel(hprev: Array, A: Array, N: int, tol: float) -> tuple[Array, Array, Array]:
33+
a = hprev.mT @ A
34+
h = A @ a.mT
35+
h = h / xp.max(h)
36+
conv = converged(hprev, h, N, tol)
37+
return h, a, conv
38+
39+
40+
def hits_finch(G: Graph, max_iter: int = 100, tol: float = 1e-8, normalized: bool = True) -> tuple[Array, Array]:
41+
N = G.N
42+
if N == 0:
43+
return xp.asarray([]), xp.asarray([])
44+
45+
h = xp.full((N, 1), 1.0 / N)
46+
A = xp.asarray(G.A)
47+
48+
for _ in range(max_iter):
49+
hprev = h
50+
a = hprev.mT @ A
51+
h = A @ a.mT
52+
h = h / xp.max(h)
53+
if converged(hprev, h, N, tol):
54+
break
55+
# alternatively these lines can be compiled
56+
# h, a, conv = kernel(h, A, N, tol)
57+
else:
58+
raise Exception("Didn't converge")
59+
60+
if normalized:
61+
h = h / xp.sum(xp.abs(h))
62+
a = a / xp.sum(xp.abs(a))
63+
return h, a
64+
65+
66+
if __name__ == "__main__":
67+
coords = (np.array([0, 0, 1, 2, 2, 3]), np.array([1, 3, 0, 0, 1, 2]))
68+
data = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
69+
A = sps.coo_array((data, coords))
70+
G = Graph(A)
71+
72+
h_finch, a_finch = hits_finch(G)
73+
74+
print(h_finch, a_finch)
75+
76+
M = gb.io.from_scipy_sparse(A)
77+
G = ga.Graph(M)
78+
h_gb, a_gb = ga.hits(G)
79+
80+
assert_allclose(h_finch.todense().ravel(), h_gb.to_dense())
81+
assert_allclose(a_finch.todense().ravel(), a_gb.to_dense())

examples/triangles_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
@sparse.compiled()
2727
def count_triangles_finch(a):
28-
return sparse.sum(a @ a * a) / 6
28+
return sparse.sum(a @ a * a) / sparse.asarray(6)
2929

3030
# Compile & Benchmark
3131
result_finch = benchmark(count_triangles_finch, args=[a], info="Finch", iters=ITERS)

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ juliaup = ">=1.17.10"
5555

5656
[feature.finch.pypi-dependencies]
5757
scipy = ">=1.13"
58-
finch-tensor = ">=0.2.4"
58+
finch-tensor = ">=0.2.10"
5959

6060
[feature.finch.activation.env]
6161
SPARSE_BACKEND = "Finch"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ tests = [
5454
tox = ["sparse[tests]", "tox"]
5555
notebooks = ["sparse[tests]", "nbmake", "matplotlib"]
5656
all = ["sparse[docs,tox,notebooks,mlir]", "matrepr"]
57-
finch = ["finch-tensor>=0.2.4"]
57+
finch = ["finch-tensor>=0.2.10"]
5858
mlir = ["finch-mlir>=0.0.2"]
5959

6060
[project.urls]

0 commit comments

Comments
 (0)