# Polynomials.fit causing LinearAlgebra.LAPACKException error on 1 computer

**URL:** <https://discourse.julialang.org/t/polynomials-fit-causing-linearalgebra-lapackexception-error-on-1-computer/43594>\
**Category:** Numerics\
**Created:** [July 23, 2020, 10:58pm UTC](https://discourse.julialang.org/t/polynomials-fit-causing-linearalgebra-lapackexception-error-on-1-computer/43594 "2020-07-23T22:58:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [July 23, 2020, 10:58pm UTC](https://discourse.julialang.org/t/polynomials-fit-causing-linearalgebra-lapackexception-error-on-1-computer/43594/1 "2020-07-23T22:58:39Z")

</div>

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. 🙂

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:

```julia
ERROR: LoadError: LinearAlgebra.LAPACKException(4)
Stacktrace:
 [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  

```

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [July 24, 2020, 10:58pm UTC](https://discourse.julialang.org/t/polynomials-fit-causing-linearalgebra-lapackexception-error-on-1-computer/43594/2 "2020-07-24T22:58:56Z")

</div>

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](https://github.com/JuliaComputing/MKL.jl).

Please see [this issue at PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl/issues/477) for details.
