From a28138e92bfa159275857d2548fdf018dc4f2298 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Tue, 5 Nov 2024 10:01:30 +0100 Subject: [PATCH 1/3] Deprecate `conv(u, v::AbstractVector, A)` to `conv(u, v::Transpose, A)` --- src/DSP.jl | 2 +- src/deprecated.jl | 4 +++- src/dspbase.jl | 8 ++++---- test/dsp.jl | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/DSP.jl b/src/DSP.jl index 8c7ac2aa9..f92ac10d4 100644 --- a/src/DSP.jl +++ b/src/DSP.jl @@ -1,7 +1,7 @@ module DSP using FFTW -using LinearAlgebra: mul!, rmul! +using LinearAlgebra: Transpose, mul!, rmul! using IterTools: subsets export conv, conv!, deconv, filt, filt!, xcorr diff --git a/src/deprecated.jl b/src/deprecated.jl index 728c9b67a..42eb9383f 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -2,7 +2,9 @@ import .Util.nextfastfft @deprecate nextfastfft(ns...) nextfastfft.(ns) false -# deprecations after 0.6 +@deprecate (conv(u::AbstractVector{T}, v::AbstractVector{T}, A::AbstractMatrix{T}) where T) conv(u, transpose(v), A) + +# deprecations in 0.7 @deprecate freqz(filter::FilterCoefficients{:z}) freqresp(filter, range(0, stop=π, length=250)) @deprecate freqz(filter::FilterCoefficients{:z}, w) freqresp(filter, w) @deprecate freqs(filter::FilterCoefficients{:s}, w) freqresp(filter, w) diff --git a/src/dspbase.jl b/src/dspbase.jl index 858d19170..98f63ddc2 100644 --- a/src/dspbase.jl +++ b/src/dspbase.jl @@ -787,10 +787,10 @@ end conv(u,v,A) 2-D convolution of the matrix `A` with the 2-D separable kernel generated by -the vectors `u` and `v`. +the vector `u` and row-vector `v`. Uses 2-D FFT algorithm. """ -function conv(u::AbstractVector{T}, v::AbstractVector{T}, A::AbstractMatrix{T}) where T +function conv(u::AbstractVector{T}, v::Transpose{T,<:AbstractVector}, A::AbstractMatrix{T}) where T # Arbitrary indexing offsets not implemented @assert !Base.has_offset_axes(u, v, A) m = length(u)+size(A,1)-1 @@ -798,8 +798,8 @@ function conv(u::AbstractVector{T}, v::AbstractVector{T}, A::AbstractMatrix{T}) B = zeros(T, m, n) B[1:size(A,1),1:size(A,2)] = A u = fft([u;zeros(T,m-length(u))]) - v = fft([v;zeros(T,n-length(v))]) - C = ifft(fft(B) .* (u * transpose(v))) + v = fft([v transpose(zeros(T,n-length(v)))]) + C = ifft(fft(B) .* (u * v)) if T <: Real return real(C) end diff --git a/test/dsp.jl b/test/dsp.jl index 55c6938ed..94d838d4b 100644 --- a/test/dsp.jl +++ b/test/dsp.jl @@ -198,13 +198,13 @@ end 624 1388 1778 2082 2190 2298 2406 1638 688 280; 354 785 1001 1167 1221 1275 1329 903 379 154; 132 292 371 431 449 467 485 329 138 56] - @test_broken conv(u, v, A) == exp + @test_broken conv(u, transpose(v), A) == exp fu = convert(Array{Float64}, u) fv = convert(Array{Float64}, v) fA = convert(Array{Float64}, A) fexp = convert(Array{Float64}, exp) - @test conv(fu, fv, fA) ≈ fexp + @test conv(fu, transpose(fv), fA) ≈ fexp end From 249155fa90c979958611bc395049554c491e76c5 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Thu, 7 Nov 2024 11:27:05 +0100 Subject: [PATCH 2/3] Test deprecated `conv` method --- test/dsp.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/dsp.jl b/test/dsp.jl index 94d838d4b..cf6163e6c 100644 --- a/test/dsp.jl +++ b/test/dsp.jl @@ -204,6 +204,7 @@ end fv = convert(Array{Float64}, v) fA = convert(Array{Float64}, A) fexp = convert(Array{Float64}, exp) + @test @test_deprecated(conv(fu, fv, fA)) ≈ fexp @test conv(fu, transpose(fv), fA) ≈ fexp end From bf14a3cbff13477e74ab3b4c72f1f53790d09a48 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Tue, 5 Nov 2024 11:58:22 +0100 Subject: [PATCH 3/3] Rework offset-axes check in three-arg `conv` --- src/dspbase.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dspbase.jl b/src/dspbase.jl index 98f63ddc2..51858bbe8 100644 --- a/src/dspbase.jl +++ b/src/dspbase.jl @@ -792,7 +792,9 @@ Uses 2-D FFT algorithm. """ function conv(u::AbstractVector{T}, v::Transpose{T,<:AbstractVector}, A::AbstractMatrix{T}) where T # Arbitrary indexing offsets not implemented - @assert !Base.has_offset_axes(u, v, A) + if any(conv_with_offset, (axes(u)..., axes(v)..., axes(A)...)) + throw(ArgumentError("offset axes not supported")) + end m = length(u)+size(A,1)-1 n = length(v)+size(A,2)-1 B = zeros(T, m, n)