Skip to content

Commit

Permalink
Deprecate conv(u, v::AbstractVector, A) to `conv(u, v::Transpose, A…
Browse files Browse the repository at this point in the history
…)` (#577)

* Deprecate `conv(u, v::AbstractVector, A)` to `conv(u, v::Transpose, A)`
* Rework offset-axes check in three-arg `conv`
  • Loading branch information
martinholters authored Nov 11, 2024
1 parent 1e30c9a commit 3c1b783
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/DSP.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions src/dspbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3c1b783

Please sign in to comment.