Polynomials.fit causing LinearAlgebra.LAPACKException error on 1 computer

A very strange problem I met that I can reproduce every time with the original code, but I am not able to create a minimal example to reproduce it. Hence I am posting here to see if anybody has seen something similar instead of submitting a bug - I’m not even sure if it’s a bug. :slight_smile:

On only 1 of my Windows 10 64-bit computers has this issue.

When I call Polynomials.fit to do a polynomial fit, some call would lead to a LinearAlgebra.LAPACKException(3) or (4) error.

If I save the data in a file, and do the same fit with the same data loaded in an REPL, or put that in a simple function inside a short script, the fit will work fine.

Not all the call to the polynomial fit function causes this problem - some number of fits can work before the problem shows up. However, it’s very consistent which call causes this problem.

In one script a 1st order fit already leads to this issue; in another 1st order fits works, but a 4th order fit leads to the error.

Again, only one machine shows this problem, but the CPU is just a common Intel i9-9900K, and another machine with the same CPU and same Julia and Polynomials versions doesn’t have this problem.

I tried completely removing and reinstalling Julia with all packages, but the problem persisted.

The versions: Julia v1.4.2, Polynomials.jl v1.1.3.

The full error message:

ERROR: LoadError: LinearAlgebra.LAPACKException(4)
 [1] chklapackerror at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\lapack.jl:38 [inlined]
 [2] gesdd!(::Char, ::Array{Float64,2}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\lapack.jl:1667
 [3] _svd! at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\svd.jl:105 [inlined]
 [4] svd!(::Array{Float64,2}; full::Bool, alg::LinearAlgebra.DivideAndConquer) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\svd.jl:98
 [5] #svd#93 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\svd.jl:158 [inlined]
 [6] pinv(::Array{Float64,2}; atol::Float64, rtol::Float64) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\dense.jl:1345
 [7] pinv at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LinearAlgebra\src\dense.jl:1324 [inlined]
 [8] fit(::Type{Polynomial}, ::Array{Float64,1}, ::SentinelArrays.ChainedVector{Float64,Array{Float64,1}}, ::Int64; weights::Nothing, var::Symbol) at C:\Users\zpan\.julia\packages\Polynomials\ZmARV\src\common.jl:83
 [9] #fit#17 at C:\Users\zpan\.julia\packages\Polynomials\ZmARV\src\common.jl:107 [inlined]
 [10] fit(::Array{Float64,1}, ::SentinelArrays.ChainedVector{Float64,Array{Float64,1}}, ::Int64) at C:\Users\zpan\.julia\packages\Polynomials\ZmARV\src\common.jl:107
 [11] main() at C:\depot\Projects\NOON\Documents\Arch\OpticalSystem_Architecture\ILS_Gen4\Controls\SupportingDocuments\Raman_Tilt_Gain\fiberIL_spectrum_CalcLossAndTilt_test.jl:211
 [12] top-level scope at .\util.jl:175
 [13] include(::String) at .\client.jl:439
 [14] top-level scope at REPL[1]:1
in expression starting at C:\depot\Projects\NOON\Documents\Arch\OpticalSystem_Architecture\ILS_Gen4\Controls\SupportingDocuments\Raman_Tilt_Gain\fiberIL_spectrum_CalcLossAndTilt_test.jl:305  

It turns out I was using PyPlot in these scripts, and somehow PyPlot.jl is interfering with LinearAlgebra.

I have found a workaround for this particular machine: install MKL.jl.

Please see this issue at PyPlot.jl for details.