JuliaDSP / DSP.jl

Filter design, periodograms, window functions, and other digital signal processing functionality
https://docs.juliadsp.org/stable/contents/
Other
379 stars 109 forks source link

In Place Convolution? #378

Open Luapulu opened 3 years ago

Luapulu commented 3 years ago

Could we get an in place conv! function?

Looking at the code, it seems like you'd only need to add a function that compares which of the inputs is larger and calls _conv! directly.

galenlynch commented 3 years ago

Yeah, I've actually been working on a PR that improves conv quite a bit by allowing direct convolution, and adding multithreading to most of the algorithms. It would be simple to add in place convolution to that. I've been pretty busy with my research and sort of stalled out on the PR, but I'll try to pick it up soon.

rafaqz commented 3 years ago

Just came here to add this too.

It would also be good to have a no-allocation conv! where you can pre-allocate everything it needs and pass it in. I have to run the same convolutions hundreds/thousands/millions of times and the allocations mean I pretty much can't use DSP.jl for that.

By the way, if you want to improve small matrix direct conv performance, I noticed that the direct windowing method in DynamicGrids.jl seems to be ~ 3x faster than DSP.jl for 3*3 kernels - although it's not written specifically for convolutions.

It uses @generated StaticArrays and blocking, and the compiler seems to inline and vectorise it pretty well (or something). It's ok for 5*5 but gets a lot slower from there.

Window iteration is here: https://github.com/cesaraustralia/DynamicGrids.jl/blob/master/src/maprules.jl#L115-L142

@generated StaticArray buffer generation is here: https://github.com/cesaraustralia/DynamicGrids.jl/blob/master/src/maprules.jl#L339-L390