Skip to content

Commit 3c1b783

Browse files
Deprecate conv(u, v::AbstractVector, A) to conv(u, v::Transpose, A) (#577)
* Deprecate `conv(u, v::AbstractVector, A)` to `conv(u, v::Transpose, A)` * Rework offset-axes check in three-arg `conv`
1 parent 1e30c9a commit 3c1b783

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/DSP.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module DSP
22

33
using FFTW
4-
using LinearAlgebra: mul!, rmul!
4+
using LinearAlgebra: Transpose, mul!, rmul!
55
using IterTools: subsets
66

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

src/deprecated.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import .Util.nextfastfft
33
@deprecate nextfastfft(ns...) nextfastfft.(ns) false
44

5-
# deprecations after 0.6
5+
@deprecate (conv(u::AbstractVector{T}, v::AbstractVector{T}, A::AbstractMatrix{T}) where T) conv(u, transpose(v), A)
6+
7+
# deprecations in 0.7
68
@deprecate freqz(filter::FilterCoefficients{:z}) freqresp(filter, range(0, stop=π, length=250))
79
@deprecate freqz(filter::FilterCoefficients{:z}, w) freqresp(filter, w)
810
@deprecate freqs(filter::FilterCoefficients{:s}, w) freqresp(filter, w)

src/dspbase.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,19 +787,21 @@ end
787787
conv(u,v,A)
788788
789789
2-D convolution of the matrix `A` with the 2-D separable kernel generated by
790-
the vectors `u` and `v`.
790+
the vector `u` and row-vector `v`.
791791
Uses 2-D FFT algorithm.
792792
"""
793-
function conv(u::AbstractVector{T}, v::AbstractVector{T}, A::AbstractMatrix{T}) where T
793+
function conv(u::AbstractVector{T}, v::Transpose{T,<:AbstractVector}, A::AbstractMatrix{T}) where T
794794
# Arbitrary indexing offsets not implemented
795-
@assert !Base.has_offset_axes(u, v, A)
795+
if any(conv_with_offset, (axes(u)..., axes(v)..., axes(A)...))
796+
throw(ArgumentError("offset axes not supported"))
797+
end
796798
m = length(u)+size(A,1)-1
797799
n = length(v)+size(A,2)-1
798800
B = zeros(T, m, n)
799801
B[1:size(A,1),1:size(A,2)] = A
800802
u = fft([u;zeros(T,m-length(u))])
801-
v = fft([v;zeros(T,n-length(v))])
802-
C = ifft(fft(B) .* (u * transpose(v)))
803+
v = fft([v transpose(zeros(T,n-length(v)))])
804+
C = ifft(fft(B) .* (u * v))
803805
if T <: Real
804806
return real(C)
805807
end

test/dsp.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ end
198198
624 1388 1778 2082 2190 2298 2406 1638 688 280;
199199
354 785 1001 1167 1221 1275 1329 903 379 154;
200200
132 292 371 431 449 467 485 329 138 56]
201-
@test_broken conv(u, v, A) == exp
201+
@test_broken conv(u, transpose(v), A) == exp
202202

203203
fu = convert(Array{Float64}, u)
204204
fv = convert(Array{Float64}, v)
205205
fA = convert(Array{Float64}, A)
206206
fexp = convert(Array{Float64}, exp)
207-
@test conv(fu, fv, fA) fexp
207+
@test @test_deprecated(conv(fu, fv, fA)) fexp
208+
@test conv(fu, transpose(fv), fA) fexp
208209

209210
end
210211

0 commit comments

Comments
 (0)