Add Fast Walsh-Hadamard Transform (FWHT) for bitwise convolutions - #15084
Open
Clear20-22 wants to merge 3 commits into
Open
Add Fast Walsh-Hadamard Transform (FWHT) for bitwise convolutions#15084Clear20-22 wants to merge 3 commits into
Clear20-22 wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a Fast Walsh–Hadamard Transform (FWHT) implementation to support fast bitwise (XOR/OR/AND) convolutions in the maths module, enabling (\mathcal{O}(N \log N)) convolution for power-of-two sized inputs.
Changes:
- Added FWHT XOR/OR/AND forward and inverse transforms.
- Added XOR/OR/AND convolution helpers built on the transforms.
- Included doctest examples for core behavior and some error cases.
Suppressed comments (1)
maths/fast_walsh_hadamard_transform.py:152
fwht_andraises ValueError for empty input (length 0), but unlikefwht_xorthis edge case isn't exercised by a doctest in the docstring. Adding an explicitfwht_and([])doctest would improve coverage for error handling.
>>> fwht_and([1, 2, 3])
Traceback (most recent call last):
...
ValueError: Length of sequence must be a positive power of 2.
"""
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+84
to
+92
| >>> fwht_or([1, 2]) | ||
| [1, 3] | ||
| >>> fwht_or([1, 3], inverse=True) | ||
| [1, 2] | ||
| >>> fwht_or([1, 2, 3]) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Length of sequence must be a positive power of 2. | ||
| """ |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
maths/fast_walsh_hadamard_transform.pyimplementing the Fast Walsh-Hadamard Transform (FWHT) and inverse transforms.ValueErrorfor non-power-of-two lengths and mismatched inputs).pytest,ruff check, andmypy.References
Checklist