Sitelet https://github.com/TheAlgorithms/Python/pull/15084
Skip to content

Add Fast Walsh-Hadamard Transform (FWHT) for bitwise convolutions - #15084

Open
Clear20-22 wants to merge 3 commits into
TheAlgorithms:masterfrom
Clear20-22:add-fast-walsh-hadamard-transform
Open

Add Fast Walsh-Hadamard Transform (FWHT) for bitwise convolutions#15084
Clear20-22 wants to merge 3 commits into
TheAlgorithms:masterfrom
Clear20-22:add-fast-walsh-hadamard-transform

Conversation

@Clear20-22

Copy link
Copy Markdown

Summary of Changes

  • Added maths/fast_walsh_hadamard_transform.py implementing the Fast Walsh-Hadamard Transform (FWHT) and inverse transforms.
  • Implemented bitwise XOR, AND, and OR convolutions in $\mathcal{O}(N \log N)$ time complexity.
  • Added comprehensive type hints and doctests testing both valid inputs and error conditions (ValueError for non-power-of-two lengths and mismatched inputs).
  • All tests pass with pytest, ruff check, and mypy.

References

Checklist

  • I have read the CONTRIBUTING.md guidelines.
  • This pull request is all my own work.
  • All functions include doctests and type annotations.
  • All doctests and tests pass locally.

Copilot AI lite review requested due to automatic review settings August 25, 2026 17:53
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Aug 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_and raises ValueError for empty input (length 0), but unlike fwht_xor this edge case isn't exercised by a doctest in the docstring. Adding an explicit fwht_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 thread maths/fast_walsh_hadamard_transform.py
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>
@Clear20-22 Clear20-22 closed this Aug 25, 2026
@Clear20-22 Clear20-22 reopened this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants