Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions sparse/numba_backend/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ def check_zero_fill_value(*args, loose=True):
ValueError: This operation requires zero fill values, but argument 1 had a fill value of 0.5.
"""
for i, arg in enumerate(args):
if arg.size == 0:
continue
if hasattr(arg, "fill_value") and not equivalent(arg.fill_value, _zero_of_dtype(arg.dtype), loose=loose):
raise ValueError(
f"This operation requires zero fill values, but argument {i:d} had a fill value of {arg.fill_value!s}."
Expand Down
10 changes: 9 additions & 1 deletion sparse/numba_backend/tests/test_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sparse
from sparse import COO, DOK
from sparse.numba_backend._settings import NEP18_ENABLED
from sparse.numba_backend._utils import assert_eq, html_table, random_value_array
from sparse.numba_backend._utils import assert_eq, check_zero_fill_value, html_table, random_value_array

import pytest

Expand Down Expand Up @@ -1918,6 +1918,14 @@ def test_to_invalid_device():
s.to_device("invalid_device")


def test_check_zero_fill_value():
a = sparse.COO(coords=np.empty((2, 0), dtype=int), data=np.array([]), shape=(1, 0), fill_value=1)
check_zero_fill_value(a) # This should not raise an error
with pytest.raises(ValueError, match="This operation requires zero fill values"):
s1 = sparse.random((10,), density=0.5, fill_value=1.0)
check_zero_fill_value(s1)


# regression test for gh-869
def test_xH_x():
Y = np.array([[0, -1j], [+1j, 0]])
Expand Down
Loading