Skip to content

Commit

Permalink
prevent stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wheeheee authored and martinholters committed Dec 3, 2024
1 parent 5880dc3 commit 5bfcfb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Filters/filt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ filt(f::DF2TFilter{<:FilterCoefficients{:z},<:Array{T}}, x::AbstractArray{V}) wh
filt!(similar(x, promote_type(T, V)), f, x)

# Fall back to SecondOrderSections
DF2TFilter(coef::FilterCoefficients{:z}, args...) = DF2TFilter(convert(SecondOrderSections, coef), args...)
DF2TFilter(coef::FilterCoefficients{:z}, coldims::Tuple{Vararg{Integer}}=()) =
DF2TFilter(convert(SecondOrderSections, coef), coldims)
DF2TFilter(coef::FilterCoefficients{:z}, ::Type{V}, coldims::Tuple{Vararg{Integer}}=()) where {V} =
DF2TFilter(convert(SecondOrderSections, coef), V, coldims)

#
# filtfilt
Expand Down
3 changes: 3 additions & 0 deletions test/filt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ using DSP, Test, Random, FilterTestHelpers
df = digitalfilter(Lowpass(0.25), Butterworth(4))
f = @test_nowarn DF2TFilter(df, ComplexF64)
@test_nowarn filt(f, s)

# DF2TFilter{ZPG/SOS} stackoverflow error
@test_throws MethodError DF2TFilter(ZeroPoleGain([1], [2], 3), :D, 'x', Ref(1))
end

@testset "multi-column filt $D-D" for D in 1:4
Expand Down

0 comments on commit 5bfcfb0

Please sign in to comment.