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

Support sparse #14

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

danielballan
Copy link
Member

This builds on the commits from #12, demonstrating support for sparse arrays.

In this initial draft, I resort to a copy-paste of multitau.py to make some sparse-specific changes in multitau_sparse.py. Using current (and also possible future) numpy protocols, it ought to be possible to support both numpy.ndarray and sparse.COO arrays in the same codepath.

The memory usage is of the sparse implementation about 1/3 of the dense implementation for a 2048x2048 image with 1% density.

python examples/sparse_memory_usage.py 
Memory usage: 96.8MiB (baseline)
Memory usage: 1.2GiB (dense)
Memory usage: 333.7MiB (sparse)

In exchange for that memory efficiency, the sparse version runs roughly half as fast. We may see greater speed gains for choices of lags and levels that require more multiplication.

When algorithm operates by modifying the input array in place, it is
good manners to make a copy first so that the function does not mutate
user input. I am guessing that that was the motivation for the use of
`copy()` here.

However, as far as I can tell, this algorithm does not modify `signal`
(or its alias `a`) in place. It reassigns the variable `a` in a loop,
but does not actually modify the input array object.

Therefore, we can remove this copying and increase the speed. Also, note
that the call to `np.array` explicitly cast the input to a literal numpy
array. By removing that from the code, we accept dask arrays and cupy
arrays and allow them to flow through the algorithm via the NEP-18 numpy
dispatch mechanism.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant