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

Implement deterministic dask tokenization. #320

Merged
merged 4 commits into from
Feb 6, 2020
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
3 changes: 2 additions & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dask[array]
pytest>=3.5
pytest-black
pytest-cov
pytest-cov
8 changes: 8 additions & 0 deletions sparse/_coo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ def __setstate__(self, state):
self.coords, self.data, self.shape, self.fill_value = state
self._cache = None

def __dask_tokenize__(self):
"Produce a deterministic, content-based hash for dask."
from dask.base import normalize_token

return normalize_token(
(type(self), self.coords, self.data, self.shape, self.fill_value)
)

def copy(self, deep=True):
"""Return a copy of the array.

Expand Down
11 changes: 11 additions & 0 deletions sparse/tests/test_dask_interop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dask.base import tokenize
import sparse


def test_deterministic_token():
a = sparse.COO(data=[1, 2, 3], coords=[10, 20, 30], shape=(40,))
b = sparse.COO(data=[1, 2, 3], coords=[10, 20, 30], shape=(40,))
assert tokenize(a) == tokenize(b)
# One of these things is not like the other....
c = sparse.COO(data=[1, 2, 4], coords=[10, 20, 30], shape=(40,))
assert tokenize(a) != tokenize(c)