Use gather_scatter as default method so library works without numba#12
Conversation
There was a problem hiding this comment.
💡 Codex Review
https://github.com/RichieHakim/sparse_convolution/blob/95e67bcb4257b49ffc29889a88a796c1060a3c17/sparse_convolution.py#L148
Avoid defaulting complex sparse inputs into the numba COO path
When numba is installed, this new default selects gather_scatter with backend='numba'; for sufficiently sparse/large outputs that route uses _coo_numba, which allocates out_data as float64 in sparse_convolution/_gather_scatter.py and cannot preserve complex convolution values. Default construction with a complex kernel/input that previously used the direct numba path will now fail or drop the imaginary component depending on numba casting, so either the default/backend selection needs to avoid that path for complex dtypes or the numba COO builder needs to allocate using the requested dtype before making it the default.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
Motivation
directmethod, causing initialization to assert-fail in environments wherenumbais not installed.directas the explicit fastest numba-only option.Description
Toeplitz_convolution2dmethodparameter from'direct'to'gather_scatter'insparse_convolution/sparse_convolution.pyso the class no longer requires numba by default.Toeplitz_convolution2ddocstring andREADME.mdto note thatgather_scatterauto-selectsnumbawhen available and thatdirectexplicitly requiresbackend='numba'and numba to be installed.method='gather_scatter'withbackend=Noneas the safe default.test_default_method_falls_back_without_numbaintests/test_unit.pythat monkeypatchesHAS_NUMBA=Falseand verifies the default usesgather_scatter+numpyand produces the expected output.Testing
python -m pytest -q, which completed successfully (42 passed, 205 skipped).python -m pytest tests/test_unit.py -q, which completed successfully (3 passed).Toeplitz_convolution2dwith no numba available does not raise and returns outputs matchingscipy.signal.convolve2d.Codex Task