Skip to content

Use gather_scatter as default method so library works without numba#12

Merged
RichieHakim merged 4 commits into
mainfrom
codex/fix-failing-tests
May 12, 2026
Merged

Use gather_scatter as default method so library works without numba#12
RichieHakim merged 4 commits into
mainfrom
codex/fix-failing-tests

Conversation

@RichieHakim

Copy link
Copy Markdown
Owner

Motivation

  • The library previously defaulted to the numba-only direct method, causing initialization to assert-fail in environments where numba is not installed.
  • The intent is to make the default construction work on minimal installs (numpy + scipy) while preserving direct as the explicit fastest numba-only option.

Description

  • Changed the default Toeplitz_convolution2d method parameter from 'direct' to 'gather_scatter' in sparse_convolution/sparse_convolution.py so the class no longer requires numba by default.
  • Clarified backend-selection text in the Toeplitz_convolution2d docstring and README.md to note that gather_scatter auto-selects numba when available and that direct explicitly requires backend='numba' and numba to be installed.
  • Updated the short README example to show method='gather_scatter' with backend=None as the safe default.
  • Added a regression test test_default_method_falls_back_without_numba in tests/test_unit.py that monkeypatches HAS_NUMBA=False and verifies the default uses gather_scatter+numpy and produces the expected output.

Testing

  • Ran the full test suite with python -m pytest -q, which completed successfully (42 passed, 205 skipped).
  • Ran the unit file tests with python -m pytest tests/test_unit.py -q, which completed successfully (3 passed).
  • The added regression test verifies that constructing Toeplitz_convolution2d with no numba available does not raise and returns outputs matching scipy.signal.convolve2d.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

https://github.com/RichieHakim/sparse_convolution/blob/95e67bcb4257b49ffc29889a88a796c1060a3c17/sparse_convolution.py#L148
P2 Badge 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".

@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

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 ☂️

@RichieHakim RichieHakim merged commit 3f36f9c into main May 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants