Skip to content

Commit 2c3cf00

Browse files
authored
Fixing check_zero_fill_value (#886)
1 parent a5d11a2 commit 2c3cf00

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sparse/numba_backend/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ def check_zero_fill_value(*args, loose=True):
588588
ValueError: This operation requires zero fill values, but argument 1 had a fill value of 0.5.
589589
"""
590590
for i, arg in enumerate(args):
591+
if arg.size == 0:
592+
continue
591593
if hasattr(arg, "fill_value") and not equivalent(arg.fill_value, _zero_of_dtype(arg.dtype), loose=loose):
592594
raise ValueError(
593595
f"This operation requires zero fill values, but argument {i:d} had a fill value of {arg.fill_value!s}."

sparse/numba_backend/tests/test_coo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sparse
77
from sparse import COO, DOK
88
from sparse.numba_backend._settings import NEP18_ENABLED
9-
from sparse.numba_backend._utils import assert_eq, html_table, random_value_array
9+
from sparse.numba_backend._utils import assert_eq, check_zero_fill_value, html_table, random_value_array
1010

1111
import pytest
1212

@@ -1918,6 +1918,16 @@ def test_to_invalid_device():
19181918
s.to_device("invalid_device")
19191919

19201920

1921+
# regression test for gh-877
1922+
def test_check_zero_fill_value():
1923+
a = sparse.zeros((1, 0))
1924+
b = a - sparse.mean(a, axis=1)
1925+
b @ b.T # should not raise an error
1926+
with pytest.raises(ValueError, match="This operation requires zero fill values"):
1927+
s1 = sparse.random((10,), density=0.5, fill_value=1.0)
1928+
check_zero_fill_value(s1)
1929+
1930+
19211931
# regression test for gh-869
19221932
def test_xH_x():
19231933
Y = np.array([[0, -1j], [+1j, 0]])

0 commit comments

Comments
 (0)