Invalid LAPACK call (via eigvals) in welch with large nsegments

Issue #30 resolved
Andy Nowacki created an issue

welch ends up erroring in a LAPACK call when trying to use large values for nsegments:

julia> welch(randn(100), 50)
 ** On entry to DSTEMRM parameter number  8 had an illegal value
ERROR: ArgumentError: invalid argument #8 to LAPACK call
Stacktrace:
 [1] chklapackerror at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/lapack.jl:36 [inlined]
 [2] stegr!(::Char, ::Char, ::Array{Float64,1}, ::Array{Float64,1}, ::Float64, ::Float64, ::Int64, ::Int64) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/lapack.jl:3819
 [3] eigvals! at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/tridiag.jl:295 [inlined]
 [4] eigvals(::LinearAlgebra.SymTridiagonal{Float64,Array{Float64,1}}, ::UnitRange{Int64}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/tridiag.jl:297
 [5] dpss_tapers(::Int64, ::Float64, ::Int64, ::Symbol) at /Users/nowacki/.julia/dev/Multitaper/src/Univariate.jl:48
 [6] dpss_tapers at /Users/nowacki/.julia/dev/Multitaper/src/Univariate.jl:45 [inlined]
 [7] welch(::Array{Float64,1}, ::Int64, ::Float64; NW::Float64, K::Int64, dt::Float64, ctr::Bool, pad::Float64, dpVec::Nothing, egval::Nothing, guts::Bool, a_weight::Bool, Ftest::Bool, jk::Bool, Tsq::Nothing, alph::Float64) at /Users/nowacki/.julia/dev/Multitaper/src/Univariate.jl:608
 [8] welch at /Users/nowacki/.julia/dev/Multitaper/src/Univariate.jl:599 [inlined] (repeats 2 times)
 [9] top-level scope at REPL[17]:1

I don’t know if it feasible to check for inappropriate nsegments values, but throwing an error there may be more user-friendly than the current behaviour.

[Note that this is a bug report, not part of the JOSS review.]

Comments (4)

  1. Andy Nowacki reporter

    That’s great.

    In my experience it is more usual in idiomatic Julia to throw an ArgumentError for invalid user input than an AssertionError. The latter, which is what the @assert macro does, is more for cases which should never be true by design or in prototype code.

  2. Chris Geoga

    Oof, I waffled about which one to use. Thanks for the pointer. I’ve corrected it to ArgumentError in the most recent commit.

  3. Log in to comment