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

Puzzle 11: conv_spec does not implement convolution #35

Open
BrandonConder opened this issue Jun 21, 2024 · 1 comment · May be fixed by #36
Open

Puzzle 11: conv_spec does not implement convolution #35

BrandonConder opened this issue Jun 21, 2024 · 1 comment · May be fixed by #36

Comments

@BrandonConder
Copy link

BrandonConder commented Jun 21, 2024

The conv_spec function does not implement convolution:

def conv_spec(a, b):
    out = np.zeros(*a.shape)
    len = b.shape[0]
    for i in range(a.shape[0]):
        out[i] = sum([a[i + j] * b[j] for j in range(len) if i + j < a.shape[0]])
    return out

One of the inputs should be index-reversed (see wikipedia)

We can also confirm the error using numpy.convolve

np.convolve(a, b, mode='same')

Test 1 output:

array([ 0,  1,  4,  7, 10, 13])

which conflicts with the conv_spec output:

Spec : [ 5.  8. 11. 14.  5.  0.]

Test 2 output:

array([ 0,  1,  4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76])

which also conflicts with the conv_spec output:

Spec : [14. 20. 26. 32. 38. 44. 50. 56. 62. 68. 74. 80. 41. 14.  0.]
@srush
Copy link
Owner

srush commented Jun 21, 2024

meh, it's roughly a convolution up to some corner case details.

@BrandonConder BrandonConder linked a pull request Jun 22, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants