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

Move convolution code to Convolutions.jl submodule #613

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
start moving to convolutions.jl
move nextfastfft to convolutions.jl
wheeheee committed Jan 17, 2025

Verified

This commit was signed with the committer’s verified signature.
commit 6b2194f79a725987a34a2ab176a35cb3eb3d5b78
2 changes: 1 addition & 1 deletion ext/OffsetArraysExt.jl
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@ module OffsetArraysExt
import DSP
import OffsetArrays

DSP.conv_axis_with_offset(::OffsetArrays.IdOffsetRange) = true
DSP.Convolutions.conv_axis_with_offset(::OffsetArrays.IdOffsetRange) = true

end
12 changes: 6 additions & 6 deletions src/DSP.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module DSP

using FFTW
using LinearAlgebra: Transpose, mul!, rmul!
using IterTools: subsets
using LinearAlgebra: mul!

export conv, conv!, deconv, filt, filt!, xcorr
export deconv, filt, filt!, xcorr

# This function has methods added in `periodograms` but is not exported,
# so we define it here so one can do `DSP.allocate_output` instead of
# `DSP.Periodograms.allocate_output`.
function allocate_output end

include("dspbase.jl")
include("convolutions.jl")

include("dspbase.jl")
include("util.jl")

include("unwrap.jl")
include("windows.jl")
include("periodograms.jl")
@@ -23,7 +23,7 @@ include("estimation.jl")
include("diric.jl")

using Reexport
@reexport using .Util, .Windows, .Periodograms, .Filters, .LPC, .Unwrap, .Estimation
@reexport using .Util, .Windows, .Periodograms, .Filters, .LPC, .Unwrap, .Estimation, .Convolutions

include("deprecated.jl")
end
3 changes: 2 additions & 1 deletion src/Filters/Filters.jl
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@ import Base: *
using LinearAlgebra: I, mul!, rmul!
using Statistics: middle
using SpecialFunctions: ellipk
using ..DSP: optimalfftfiltlength, os_fft_complexity, SMALL_FILT_CUTOFF
using ..Convolutions: optimalfftfiltlength, os_fft_complexity
using ..DSP: SMALL_FILT_CUTOFF
import ..DSP: filt, filt!
using FFTW

685 changes: 685 additions & 0 deletions src/convolutions.jl

Large diffs are not rendered by default.

648 changes: 2 additions & 646 deletions src/dspbase.jl

Large diffs are not rendered by default.

32 changes: 1 addition & 31 deletions src/util.jl
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import Base: *
using LinearAlgebra: mul!, BLAS
using FFTW
using Statistics: mean
using ..Convolutions: nextfastfft

export hilbert,
fftintype,
@@ -103,37 +104,6 @@ fftabs2type(::Type{Complex{T}}) where {T<:FFTW.fftwReal} = T
fftabs2type(::Type{T}) where {T<:FFTW.fftwReal} = T
fftabs2type(::Type{T}) where {T<:Union{Real,Complex}} = Float64

# Get next fast FFT size for a given signal length
const FAST_FFT_SIZES = (2, 3, 5, 7)

"""
nextfastfft(n::Integer)
nextfastfft(ns::Tuple)
Return an estimate for the padded size of an array that
is optimal for the performance of an n-dimensional FFT.
For `Tuple` inputs, this returns a `Tuple` that is the size
of the padded array.
For `Integer` inputs, this returns the closest product of 2, 3, 5, and 7
greater than or equal to `n`.
FFTW contains optimized kernels for these sizes and computes
Fourier transforms of inputs that are a product of these
sizes faster than for inputs of other sizes.
!!! warning
Currently, `nextfastfft(ns::Tuple)` is implemented as
`nextfastfft.(ns)`. This may change in future releases if
a better estimation model is found.
It is recommended to use `nextfastfft.(ns)` to obtain
a tuple of padded lengths for 1D FFTs.
"""
nextfastfft(n::Integer) = nextprod(FAST_FFT_SIZES, n)
nextfastfft(ns::Tuple{Vararg{Integer}}) = nextfastfft.(ns)


## COMMON DSP TOOLS

3 changes: 1 addition & 2 deletions test/dsp.jl
Original file line number Diff line number Diff line change
@@ -2,9 +2,8 @@
# TODO: parameterize conv tests
using Test, OffsetArrays
using DSP: filt, filt!, deconv, conv, xcorr,
optimalfftfiltlength, unsafe_conv_kern_os!, _conv_kern_fft!
nextfastfft

using DSP.Convolutions: optimalfftfiltlength, unsafe_conv_kern_os!, _conv_kern_fft!


@testset "filt" begin