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

Linear operator for Fast Welsh-Hadamard Transform #254

Open
SilentEch0 opened this issue Oct 12, 2021 · 3 comments
Open

Linear operator for Fast Welsh-Hadamard Transform #254

SilentEch0 opened this issue Oct 12, 2021 · 3 comments

Comments

@SilentEch0
Copy link

Can be implemented using SymPy

@mrava87
Copy link
Collaborator

mrava87 commented Oct 12, 2021

Interesting idea :) I wasn’t aware of this transform being available in sympy.

Just to be sure, I thought sympy works only with symbolic math, can this transform operate on numpy arrays too?

@dikwickley
Copy link
Contributor

came across this...
image

but looking at sympy's implementation of FWHT, we can implement it in pylops...

def _walsh_hadamard_transform(seq, inverse=False):
    """Utility function for the Walsh Hadamard Transform"""

    if not iterable(seq):
        raise TypeError("Expected a sequence of coefficients "
                        "for Walsh Hadamard Transform")

    a = [sympify(arg) for arg in seq]
    n = len(a)
    if n < 2:
        return a

    if n&(n - 1):
        n = 2**n.bit_length()

    a += [S.Zero]*(n - len(a))
    h = 2
    while h <= n:
        hf = h // 2
        for i in range(0, n, h):
            for j in range(hf):
                u, v = a[i + j], a[i + j + hf]
                a[i + j], a[i + j + hf] = u + v, u - v
        h *= 2

    if inverse:
        a = [x/n for x in a]

    return a

@mrava87
Copy link
Collaborator

mrava87 commented Feb 1, 2023

I wasn’t really sure what @SilentEch0 meant and he never replied. I wouldn’t give priority to this issue unless it’s clear what is its value

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

No branches or pull requests

3 participants