Skip to content

Use numpy Correlate2 for Convolve1d implementation #1358

Open
@ricardoV94

Description

@ricardoV94

Description

This is what numpy.convolve uses under the hood, but we can avoid the python overhead in the C-backend: https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_Correlate2

It may make sense to actually implement everything in terms of a correlate1d and have the convolve1dbe a call oncorrelate1dwith the flipped input. Since under the hood callingnp.convolve` is doing this flip anyway.

correlate1d shows up in the gradient of convolve1d (note the [::-1] inputs)

if self.mode == "full":
valid_conv = type(self)(mode="valid")
in1_bar = valid_conv(grad, in2[::-1])
in2_bar = valid_conv(grad, in1[::-1])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions