diff --git a/src/DSP.jl b/src/DSP.jl index 8c7ac2aa..f92ac10d 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 728c9b67..42eb9383 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 858d1917..51858bbe 100644 --- a/src/dspbase.jl +++ b/src/dspbase.jl @@ -787,19 +787,21 @@ 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) + 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) 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 55c6938e..cf6163e6 100644 --- a/test/dsp.jl +++ b/test/dsp.jl @@ -198,13 +198,14 @@ 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 @test_deprecated(conv(fu, fv, fA)) ≈ fexp + @test conv(fu, transpose(fv), fA) ≈ fexp end