dask / dask/dask

Sparse COO divide by zero is zero

Open
#5,110 9 comments 0 reactions 0 assignees View on GitHub
array
Dominant language
Python
Stars
13.9k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

Thanks so much for creating this great library!

There seems to be an inconsistency when dividing by zero with sparse matrices:

```python
import dask
import dask.array as da
import sparse
print(f"dask version {dask.__version__}")
print(f"sparse version {sparse.__version__}")

coo = da.zeros(10).map_blocks(sparse.COO)

print((1 / coo).compute().todense())
# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
# should be: [inf inf inf inf inf inf inf inf inf inf] ?

print((1 / coo.compute()).todense())
# [inf inf inf inf inf inf inf inf inf inf]
```
output:
```
dask version 2.1.0
sparse version 0.7.0
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[inf inf inf inf inf inf inf inf inf inf]
```

Am I missing something here?

Contributor guide

Open the contributing guide

Research direction

Start by running the reproducer in the issue with the shown Dask and sparse versions, then compare the lazy map_blocks path with direct sparse.COO computation. Done means division by zero through the Dask path matches the direct path and returns the expected infinity values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.