"Fossies" - the Fresh Open Source Software Archive

Member "julia-1.1.1/share/julia/stdlib/v1.1/LinearAlgebra/test/lapack.jl" (16 May 2019, 25743 Bytes) of package /linux/misc/julia-1.1.1-linux-i686.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Julia source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is a part of Julia. License is MIT: https://julialang.org/license
    2 
    3 module TestLAPACK
    4 
    5 using Test, LinearAlgebra, Random
    6 using LinearAlgebra: BlasInt
    7 
    8 @test_throws ArgumentError LinearAlgebra.LAPACK.chkuplo('Z')
    9 @test_throws ArgumentError LinearAlgebra.LAPACK.chkside('Z')
   10 @test_throws ArgumentError LinearAlgebra.LAPACK.chkdiag('Z')
   11 @test_throws ArgumentError LinearAlgebra.LAPACK.chktrans('Z')
   12 
   13 @testset "syevr" begin
   14     Random.seed!(123)
   15     Ainit = randn(5,5)
   16     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
   17         if elty == ComplexF32 || elty == ComplexF64
   18             A = complex.(Ainit, Ainit)
   19         else
   20             A = Ainit
   21         end
   22         A = convert(Array{elty, 2}, A)
   23         Asym = A'A
   24         vals, Z = LAPACK.syevr!('V', copy(Asym))
   25         @test Z*(Diagonal(vals)*Z') ≈ Asym
   26         @test all(vals .> 0.0)
   27         @test LAPACK.syevr!('N','V','U',copy(Asym),0.0,1.0,4,5,-1.0)[1] ≈ vals[vals .< 1.0]
   28         @test LAPACK.syevr!('N','I','U',copy(Asym),0.0,1.0,4,5,-1.0)[1] ≈ vals[4:5]
   29         @test vals ≈ LAPACK.syev!('N','U',copy(Asym))
   30         @test_throws DimensionMismatch LAPACK.sygvd!(1,'V','U',copy(Asym),Matrix{elty}(undef,6,6))
   31     end
   32 end
   33 
   34 @testset "gglse" begin
   35     let
   36         @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
   37             A = convert(Array{elty, 2}, [1 1 1 1; 1 3 1 1; 1 -1 3 1; 1 1 1 3; 1 1 1 -1])
   38             c = convert(Array{elty, 1}, [2, 1, 6, 3, 1])
   39             B = convert(Array{elty, 2}, [1 1 1 -1; 1 -1 1 1; 1 1 -1 1])
   40             d = convert(Array{elty, 1}, [1, 3, -1])
   41             @test LAPACK.gglse!(A, c, B, d)[1]convert(Array{elty}, [0.5, -0.5, 1.5, 0.5])
   42         end
   43     end
   44 end
   45 
   46 @testset "gebrd, bdsqr, throw for bdsdc" begin
   47     let
   48         n = 10
   49         @testset for elty in (Float32, Float64)
   50             d, e = convert(Vector{elty}, randn(n)), convert(Vector{elty}, randn(n - 1))
   51             U, Vt, C = Matrix{elty}(I, n, n), Matrix{elty}(I, n, n), Matrix{elty}(I, n, n)
   52             s, _ = LAPACK.bdsqr!('U', copy(d), copy(e), Vt, U, C)
   53             @test Array(Bidiagonal(d, e, :U)) ≈ U*Diagonal(s)*Vt
   54 
   55             @test_throws ArgumentError LAPACK.bdsqr!('A', d, e, Vt, U, C)
   56             @test_throws DimensionMismatch LAPACK.bdsqr!('U', d, [e; 1], Vt, U, C)
   57             @test_throws DimensionMismatch LAPACK.bdsqr!('U', d, e, Vt[1:end - 1, :], U, C)
   58             @test_throws DimensionMismatch LAPACK.bdsqr!('U', d, e, Vt, U[:,1:end - 1], C)
   59             @test_throws DimensionMismatch LAPACK.bdsqr!('U', d, e, Vt, U, C[1:end - 1, :])
   60 
   61             @test_throws ArgumentError LAPACK.bdsdc!('U','Z',d,e)
   62 
   63             A = rand(elty,n,n)
   64             B = copy(A)
   65             B, d, e, tauq, taup = LAPACK.gebrd!(B)
   66             U, Vt, C = Matrix{elty}(I, n, n), Matrix{elty}(I, n, n), Matrix{elty}(I, n, n)
   67             s, _ = LAPACK.bdsqr!('U',d,e[1:n-1],Vt, U, C)
   68             @test s ≈ svdvals(A)
   69         end
   70     end
   71 end
   72 
   73 @testset "Issue #7886" begin
   74     let
   75         x, r = LAPACK.gelsy!([0 1; 0 2; 0 3.], [2, 4, 6.])
   76         @test x ≈ [0,2]
   77         @test r == 1
   78     end
   79 end
   80 
   81 @testset "geqrt(3)" begin
   82     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
   83         A = rand(elty,10,10)
   84         B = copy(A)
   85         C,T = LAPACK.geqrt!(A,zeros(elty,10,10))
   86         D,S = LAPACK.geqrt3!(A,zeros(elty,10,10))
   87         @test C ≈ D
   88     end
   89 end
   90 
   91 @testset "gbtrf and gbtrs" begin
   92     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
   93         d = rand(elty,6)
   94         dl = rand(elty,5)
   95         du = rand(elty,5)
   96         dl2 = rand(elty,4)
   97         AB = zeros(elty,6,6)
   98         AB[6,1:4] = dl2
   99         AB[5,1:5] = dl
  100         AB[4,:] = d
  101         AB[3,2:6] = du
  102         AB,ipiv = LAPACK.gbtrf!(2,1,6,AB)
  103         C = rand(elty,6,6)
  104         D = copy(C)
  105         D = LAPACK.gbtrs!('N',2,1,6,AB,ipiv,D)
  106         A = diagm(-2 => dl2, -1 => dl, 0 => d, 1 => du)
  107         @test A\C ≈ D
  108         @test_throws DimensionMismatch LAPACK.gbtrs!('N',2,1,6,AB,ipiv,Matrix{elty}(undef,7,6))
  109         @test_throws LinearAlgebra.LAPACKException LAPACK.gbtrf!(2,1,6,zeros(elty,6,6))
  110     end
  111 end
  112 
  113 
  114 @testset "geqp3, geqrt error handling" begin
  115     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  116         x10, x11 = Vector{elty}.(undef, (10, 11))
  117         y10, y11 = Vector{LinearAlgebra.BlasInt}.(undef, (10, 11))
  118         A10x10, A11x10, A10x11, A11x11 = Matrix{elty}.(undef, ((10,10), (11,10), (10,11), (11,11)))
  119         @test_throws DimensionMismatch LAPACK.geqlf!(A10x10, x11)
  120         @test_throws DimensionMismatch LAPACK.gelqf!(A10x10, x11)
  121         @test_throws DimensionMismatch LAPACK.geqp3!(A10x10, y11, x10)
  122         @test_throws DimensionMismatch LAPACK.geqp3!(A10x10, y10, x11)
  123         @test_throws ArgumentError LAPACK.geqrt!(A10x10, A11x10)
  124         @test_throws DimensionMismatch LAPACK.geqrt3!(A10x10, A11x10)
  125         @test_throws DimensionMismatch LAPACK.geqrt3!(A10x11, A11x11)
  126         @test_throws DimensionMismatch LAPACK.geqrf!(A10x10, x11)
  127         @test_throws DimensionMismatch LAPACK.gerqf!(A10x10, x11)
  128     end
  129 end
  130 
  131 @testset "gels, gesv, getrs, getri error handling" begin
  132     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  133         A10x10, B11x11 = Matrix{elty}.(undef, ((10,10), (11,11)))
  134         x10, x11 = Vector{LinearAlgebra.BlasInt}.(undef, (10, 11))
  135         @test_throws DimensionMismatch LAPACK.gels!('N',A10x10,B11x11)
  136         @test_throws DimensionMismatch LAPACK.gels!('T',A10x10,B11x11)
  137         @test_throws DimensionMismatch LAPACK.gesv!(A10x10,B11x11)
  138         @test_throws DimensionMismatch LAPACK.getrs!('N',A10x10,x10,B11x11)
  139         @test_throws DimensionMismatch LAPACK.getrs!('T',A10x10,x10,B11x11)
  140         @test_throws DimensionMismatch LAPACK.getri!(A10x10,x11)
  141     end
  142 end
  143 
  144 @testset "gelsy, gelsd" begin
  145     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  146         A = rand(elty, 10, 10)
  147         B = rand(elty, 10, 10)
  148         C, j = LAPACK.gelsd!(copy(A),copy(B))
  149         D, k = LAPACK.gelsy!(copy(A),copy(B))
  150         @test C ≈ D rtol=4*eps(cond(A))
  151         @test_throws DimensionMismatch LAPACK.gelsd!(A,rand(elty,12,10))
  152         @test_throws DimensionMismatch LAPACK.gelsy!(A,rand(elty,12,10))
  153     end
  154 end
  155 
  156 @testset "gglse errors" begin
  157     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  158         A = rand(elty,10,10)
  159         @test_throws DimensionMismatch LAPACK.gglse!(A,zeros(elty,10),rand(elty,12,11),zeros(elty,12))
  160         @test_throws DimensionMismatch LAPACK.gglse!(A,zeros(elty,11),rand(elty,10,10),zeros(elty,10))
  161         @test_throws DimensionMismatch LAPACK.gglse!(A,zeros(elty,10),rand(elty,10,10),zeros(elty,11))
  162     end
  163 end
  164 
  165 @testset "gesvd, ggsvd" begin
  166     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  167         A = rand(elty,10,5)
  168         U,S,V = svd(A)
  169         lU,lS,lVt = LAPACK.gesvd!('S','S',A)
  170         @test U ≈ lU
  171         @test S ≈ lS
  172         @test V' ≈ lVt
  173         B = rand(elty,10,10)
  174         # xggsvd3 replaced xggsvd in LAPACK 3.6.0
  175         if LAPACK.version() < v"3.6.0"
  176             @test_throws DimensionMismatch LAPACK.ggsvd!('S','S','S',A,B)
  177         else
  178             @test_throws DimensionMismatch LAPACK.ggsvd3!('S','S','S',A,B)
  179         end
  180     end
  181 end
  182 
  183 @testset "geevx, ggev errors" begin
  184     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  185         A = rand(elty,10,10)
  186         B = rand(elty,10,10)
  187         @test_throws ArgumentError LAPACK.geevx!('M','N','N','N',A)
  188         @test_throws ArgumentError LAPACK.geevx!('N','Z','N','N',A)
  189         @test_throws ArgumentError LAPACK.geevx!('N','N','Z','N',A)
  190         @test_throws ArgumentError LAPACK.geevx!('N','N','N','Z',A)
  191         @test_throws ArgumentError LAPACK.ggev!('N','B',A,B)
  192         @test_throws ArgumentError LAPACK.ggev!('B','N',A,B)
  193         @test_throws DimensionMismatch LAPACK.ggev!('N','N',A,zeros(elty,12,12))
  194     end
  195 end
  196 
  197 @testset "gebal/gebak" begin
  198     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  199         A = rand(elty,10,10) * Diagonal(exp10.(range(-10, stop=10, length=10)))
  200         B = copy(A)
  201         ilo, ihi, scale = LAPACK.gebal!('S',B)
  202         Bvs = eigvecs(B)
  203         Avs = eigvecs(A)
  204         Bvs = LAPACK.gebak!('S','R',ilo,ihi,scale,Bvs)
  205         @test norm(diff(Avs ./ Bvs, dims=1)) < 100 * eps(abs(float(one(elty))))
  206     end
  207 end
  208 
  209 @testset "gels" begin
  210     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  211         Random.seed!(913)
  212         A = rand(elty,10,10)
  213         X = rand(elty,10)
  214         B,Y,z = LAPACK.gels!('N',copy(A),copy(X))
  215         @test A\X ≈ Y
  216     end
  217 end
  218 
  219 @testset "getrf/getri" begin
  220     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  221         A = rand(elty,10,10)
  222         iA = inv(A)
  223         A, ipiv = LAPACK.getrf!(A)
  224         A = LAPACK.getri!(A, ipiv)
  225         @test A ≈ iA
  226     end
  227 end
  228 
  229 @testset "geev" begin
  230     # complex is easier for now
  231     @testset for elty in (ComplexF32, ComplexF64)
  232         A = rand(elty,10,10)
  233         Aw, Avl, Avr = LAPACK.geev!('N','V',copy(A))
  234         fA = eigen(A)
  235         @test fA.values  ≈ Aw
  236         @test fA.vectors ≈ Avr
  237     end
  238 end
  239 
  240 @testset "gtsv" begin
  241     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  242         du = rand(elty,9)
  243         d  = rand(elty,10)
  244         dl = rand(elty,9)
  245         b  = rand(elty,10)
  246         c = Tridiagonal(dl,d,du) \ b
  247         b = LAPACK.gtsv!(dl,d,du,b)
  248         @test b ≈ c
  249         @test_throws DimensionMismatch LAPACK.gtsv!(zeros(elty,11),d,du,b)
  250         @test_throws DimensionMismatch LAPACK.gtsv!(dl,d,zeros(elty,11),b)
  251         @test_throws DimensionMismatch LAPACK.gtsv!(dl,d,du,zeros(elty,11))
  252         @test LAPACK.gtsv!(elty[],elty[],elty[],elty[]) == elty[]
  253     end
  254 end
  255 
  256 @testset "gttrs,gttrf errors" begin
  257     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  258         du = rand(elty,9)
  259         d  = rand(elty,10)
  260         dl = rand(elty,9)
  261         b  = rand(elty,10)
  262         y10 = Vector{BlasInt}(undef, 10)
  263         x9, x11 = Vector{elty}.(undef, (9, 11))
  264         @test_throws DimensionMismatch LAPACK.gttrf!(x11, d, du)
  265         @test_throws DimensionMismatch LAPACK.gttrf!(dl, d, x11)
  266         @test_throws DimensionMismatch LAPACK.gttrs!('N', x11, d, du, x9, y10, b)
  267         @test_throws DimensionMismatch LAPACK.gttrs!('N', dl, d, x11, x9, y10, b)
  268         @test_throws DimensionMismatch LAPACK.gttrs!('N', dl, d, du, x9, y10, x11)
  269         A = lu(Tridiagonal(dl,d,du))
  270         b  = rand(elty,10,5)
  271         c = copy(b)
  272         dl,d,du,du2,ipiv = LAPACK.gttrf!(dl,d,du)
  273         c = LAPACK.gttrs!('N',dl,d,du,du2,ipiv,c)
  274         @test A\b ≈ c
  275     end
  276 end
  277 
  278 @testset "orglq and friends errors" begin
  279     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  280         A = rand(elty,10,10)
  281         A,tau = LAPACK.gelqf!(A)
  282         @test_throws DimensionMismatch LAPACK.orglq!(A,tau,11)
  283         @test_throws DimensionMismatch LAPACK.ormlq!('R','N',A,tau,rand(elty,11,11))
  284         @test_throws DimensionMismatch LAPACK.ormlq!('L','N',A,tau,rand(elty,11,11))
  285         @test_throws DimensionMismatch LAPACK.ormlq!('R','N',A,zeros(elty,11),rand(elty,10,10))
  286         @test_throws DimensionMismatch LAPACK.ormlq!('L','N',A,zeros(elty,11),rand(elty,10,10))
  287 
  288         B = copy(A)
  289         C = LAPACK.orglq!(B,tau)
  290         @test LAPACK.ormlq!('R','N',A,tau, Matrix{elty}(I, 10, 10)) ≈ C
  291 
  292         A = rand(elty,10,10)
  293         A,tau = LAPACK.geqrf!(A)
  294         @test_throws DimensionMismatch LAPACK.orgqr!(A,tau,11)
  295         B = copy(A)
  296         @test LAPACK.orgqr!(B,tau) ≈ LAPACK.ormqr!('R','N',A,tau,Matrix{elty}(I, 10, 10))
  297         @test_throws DimensionMismatch LAPACK.ormqr!('R','N',A,tau,rand(elty,11,11))
  298         @test_throws DimensionMismatch LAPACK.ormqr!('L','N',A,tau,rand(elty,11,11))
  299         @test_throws DimensionMismatch LAPACK.ormqr!('R','N',A,zeros(elty,11),rand(elty,10,10))
  300         @test_throws DimensionMismatch LAPACK.ormqr!('L','N',A,zeros(elty,11),rand(elty,10,10))
  301 
  302         A = rand(elty,10,10)
  303         A,tau = LAPACK.geqlf!(A)
  304         @test_throws DimensionMismatch LAPACK.orgql!(A,tau,11)
  305         B = copy(A)
  306         @test LAPACK.orgql!(B,tau) ≈ LAPACK.ormql!('R','N',A,tau,Matrix{elty}(I, 10, 10))
  307         @test_throws DimensionMismatch LAPACK.ormql!('R','N',A,tau,rand(elty,11,11))
  308         @test_throws DimensionMismatch LAPACK.ormql!('L','N',A,tau,rand(elty,11,11))
  309         @test_throws DimensionMismatch LAPACK.ormql!('R','N',A,zeros(elty,11),rand(elty,10,10))
  310         @test_throws DimensionMismatch LAPACK.ormql!('L','N',A,zeros(elty,11),rand(elty,10,10))
  311 
  312         A = rand(elty,10,10)
  313         A,tau = LAPACK.gerqf!(A)
  314         @test_throws DimensionMismatch LAPACK.orgrq!(A,tau,11)
  315         B = copy(A)
  316         @test LAPACK.orgrq!(B,tau) ≈ LAPACK.ormrq!('R','N',A,tau,Matrix{elty}(I, 10, 10))
  317         @test_throws DimensionMismatch LAPACK.ormrq!('R','N',A,tau,rand(elty,11,11))
  318         @test_throws DimensionMismatch LAPACK.ormrq!('L','N',A,tau,rand(elty,11,11))
  319         @test_throws DimensionMismatch LAPACK.ormrq!('R','N',A,zeros(elty,11),rand(elty,10,10))
  320         @test_throws DimensionMismatch LAPACK.ormrq!('L','N',A,zeros(elty,11),rand(elty,10,10))
  321 
  322         A = rand(elty,10,11)
  323         Q = copy(A)
  324         Q,tau = LAPACK.gerqf!(Q)
  325         R = triu(Q[:,2:11])
  326         LAPACK.orgrq!(Q,tau)
  327         @test Q*Q' ≈ Matrix(I, 10, 10)
  328         @test R*Q ≈ A
  329         @test_throws DimensionMismatch LAPACK.orgrq!(zeros(elty,11,10),zeros(elty,10))
  330 
  331         C = rand(elty,10,10)
  332         V = rand(elty,10,10)
  333         T = zeros(elty,10,11)
  334         @test_throws DimensionMismatch LAPACK.gemqrt!('L','N',V,T,C)
  335         @test_throws DimensionMismatch LAPACK.gemqrt!('R','N',V,T,C)
  336 
  337         C = rand(elty,10,10)
  338         V = rand(elty,11,10)
  339         T = zeros(elty,10,10)
  340         @test_throws DimensionMismatch LAPACK.gemqrt!('R','N',V,T,C)
  341         @test_throws DimensionMismatch LAPACK.gemqrt!('L','N',V,T,C)
  342 
  343         # test size(T) = (nb,k) ensures 1 <= nb <= k
  344         T = zeros(elty,10,10)
  345         V = rand(elty,5,10)
  346         @test_throws DimensionMismatch LAPACK.gemqrt!('L','N',V,T,C)
  347         C = rand(elty,10,10)
  348         V = rand(elty,10,10)
  349         T = zeros(elty,11,10)
  350         @test_throws DimensionMismatch LAPACK.gemqrt!('R','N',V,T,C)
  351 
  352         @test_throws DimensionMismatch LAPACK.orghr!(1, 10, C, zeros(elty,11))
  353     end
  354 end
  355 
  356 @testset "sytri, sytrs, and sytrf" begin
  357     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  358         A = rand(elty,10,10)
  359         A = A + transpose(A) #symmetric!
  360         B = copy(A)
  361         B,ipiv = LAPACK.sytrf!('U',B)
  362         @test triu(inv(A))triu(LAPACK.sytri!('U',B,ipiv)) rtol=eps(cond(A))
  363         @test_throws DimensionMismatch LAPACK.sytrs!('U',B,ipiv,rand(elty,11,5))
  364         @test LAPACK.sytrf!('U',zeros(elty,0,0)) == (zeros(elty,0,0),zeros(BlasInt,0),zero(BlasInt))
  365     end
  366 
  367     # Rook-pivoting variants
  368     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  369         A = rand(elty, 10, 10)
  370         A = A + transpose(A) #symmetric!
  371         B = copy(A)
  372         B,ipiv = LAPACK.sytrf_rook!('U', B)
  373         @test triu(inv(A))triu(LAPACK.sytri_rook!('U', B, ipiv)) rtol=eps(cond(A))
  374         @test_throws DimensionMismatch LAPACK.sytrs_rook!('U', B, ipiv, rand(elty, 11, 5))
  375         @test LAPACK.sytrf_rook!('U',zeros(elty, 0, 0)) == (zeros(elty, 0, 0),zeros(BlasInt, 0),zero(BlasInt))
  376         A = rand(elty, 10, 10)
  377         A = A + transpose(A) #symmetric!
  378         b = rand(elty, 10)
  379         c = A \ b
  380         cnd = cond(A)
  381         b,A = LAPACK.sysv_rook!('U', A, b)
  382         @test b ≈ c rtol=eps(cnd)
  383         @test_throws DimensionMismatch LAPACK.sysv_rook!('U',A,rand(elty,11))
  384 
  385         # syconvf_rook error handling
  386         # way argument is wrong
  387         @test_throws ArgumentError LAPACK.syconvf_rook!('U', 'U', A, rand(BlasInt, 10))
  388         # ipiv has wrong length
  389         @test_throws ArgumentError LAPACK.syconvf_rook!('U', 'R', A, rand(BlasInt, 9))
  390         # e has wrong length
  391         @test_throws ArgumentError LAPACK.syconvf_rook!('U', 'R', A, rand(BlasInt, 10), rand(elty, 9))
  392     end
  393 end
  394 
  395 @testset "hetrf, hetrs" begin
  396     @testset for elty in (ComplexF32, ComplexF64)
  397         A = rand(elty,10,10)
  398         A = A + A' #hermitian!
  399         B = copy(A)
  400         B,ipiv = LAPACK.hetrf!('U',B)
  401         @test_throws DimensionMismatch LAPACK.hetrs!('U',B,ipiv,rand(elty,11,5))
  402         @test_throws DimensionMismatch LAPACK.hetrs_rook!('U',B,ipiv,rand(elty,11,5))
  403     end
  404 end
  405 
  406 @testset "stev, stebz, stein, stegr" begin
  407     @testset for elty in (Float32, Float64)
  408         d = rand(elty,10)
  409         e = rand(elty,9)
  410         @test_throws DimensionMismatch LAPACK.stev!('U',d,rand(elty,10))
  411         @test_throws DimensionMismatch LAPACK.stebz!('A','B',zero(elty),zero(elty),0,0,-1.,d,rand(elty,10))
  412         @test_throws DimensionMismatch LAPACK.stegr!('N','A',d,rand(elty,10),zero(elty),zero(elty),0,0)
  413         @test_throws DimensionMismatch LAPACK.stein!(d,zeros(elty,10),zeros(elty,10),zeros(BlasInt,10),zeros(BlasInt,10))
  414         @test_throws DimensionMismatch LAPACK.stein!(d,e,zeros(elty,11),zeros(BlasInt,10),zeros(BlasInt,10))
  415     end
  416 end
  417 
  418 @testset "trtri & trtrs" begin
  419     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  420         A = rand(elty,10,10)
  421         A = triu(A)
  422         B = copy(A)
  423         @test inv(A) ≈ LAPACK.trtri!('U','N',B)
  424         @test_throws DimensionMismatch LAPACK.trtrs!('U','N','N',B,zeros(elty,11,10))
  425     end
  426 end
  427 
  428 @testset "tgsen, tzrzf, & trsyl" begin
  429     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  430         Z = zeros(elty,10,10)
  431         @test_throws DimensionMismatch LAPACK.tgsen!(zeros(BlasInt,10),Z,zeros(elty,11,11),Z,Z)
  432         @test_throws DimensionMismatch LAPACK.tgsen!(zeros(BlasInt,10),Z,Z,zeros(elty,11,11),Z)
  433         @test_throws DimensionMismatch LAPACK.tgsen!(zeros(BlasInt,10),Z,Z,Z,zeros(elty,11,11))
  434         @test_throws DimensionMismatch LAPACK.trsyl!('N','N',Z,Z,zeros(elty,11,11))
  435         @test_throws DimensionMismatch LAPACK.tzrzf!(zeros(elty,10,5))
  436 
  437         A = triu(rand(elty,4,4))
  438         V = view(A, 1:2, :)
  439         M = Matrix(V)
  440         @test LAPACK.tzrzf!(V) == LAPACK.tzrzf!(M)
  441     end
  442 end
  443 
  444 @testset "sysv" begin
  445     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  446         Random.seed!(123)
  447         A = rand(elty,10,10)
  448         A = A + transpose(A) #symmetric!
  449         b = rand(elty,10)
  450         c = A \ b
  451         b,A = LAPACK.sysv!('U',A,b)
  452         @test b ≈ c
  453         @test_throws DimensionMismatch LAPACK.sysv!('U',A,rand(elty,11))
  454     end
  455 end
  456 
  457 @testset "hesv" begin
  458     @testset for elty in (ComplexF32, ComplexF64)
  459         Random.seed!(935)
  460         A = rand(elty,10,10)
  461         A = A + A' #hermitian!
  462         b = rand(elty,10)
  463         c = A \ b
  464         b,A = LAPACK.hesv!('U',A,b)
  465         @test b ≈ c
  466         @test_throws DimensionMismatch LAPACK.hesv!('U',A,rand(elty,11))
  467         A = rand(elty,10,10)
  468         A = A + A' #hermitian!
  469         b = rand(elty,10)
  470         c = A \ b
  471         b,A = LAPACK.hesv_rook!('U',A,b)
  472         @test b ≈ c
  473         @test_throws DimensionMismatch LAPACK.hesv_rook!('U',A,rand(elty,11))
  474     end
  475 end
  476 
  477 @testset "ptsv" begin
  478     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  479         dv = fill(elty(1),10)
  480         ev = zeros(elty,9)
  481         rdv = real(dv)
  482         A = SymTridiagonal(dv,ev)
  483         if elty <: Complex
  484             A = Tridiagonal(conj(ev),dv,ev)
  485         end
  486         B = rand(elty,10,10)
  487         C = copy(B)
  488         @test A\B ≈ LAPACK.ptsv!(rdv,ev,C)
  489         @test_throws DimensionMismatch LAPACK.ptsv!(rdv,Vector{elty}(undef,10),C)
  490         @test_throws DimensionMismatch LAPACK.ptsv!(rdv,ev,Matrix{elty}(undef,11,11))
  491     end
  492 end
  493 
  494 @testset "pttrf and pttrs" begin
  495     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  496         dv = fill(elty(1),10)
  497         ev = zeros(elty,9)
  498         rdv = real(dv)
  499         A = SymTridiagonal(dv,ev)
  500         if elty <: Complex
  501             A = Tridiagonal(conj(ev),dv,ev)
  502         end
  503         rdv,ev = LAPACK.pttrf!(rdv,ev)
  504         @test_throws DimensionMismatch LAPACK.pttrf!(rdv,dv)
  505         B = rand(elty,10,10)
  506         C = copy(B)
  507         if elty <: Complex
  508             @test A\B ≈ LAPACK.pttrs!('U',rdv,ev,C)
  509             @test_throws DimensionMismatch LAPACK.pttrs!('U',rdv,Vector{elty}(undef,10),C)
  510             @test_throws DimensionMismatch LAPACK.pttrs!('U',rdv,ev,Matrix{elty}(undef,11,11))
  511         else
  512             @test A\B ≈ LAPACK.pttrs!(rdv,ev,C)
  513             @test_throws DimensionMismatch LAPACK.pttrs!(rdv,Vector{elty}(undef,10),C)
  514             @test_throws DimensionMismatch LAPACK.pttrs!(rdv,ev,Matrix{elty}(undef,11,11))
  515         end
  516     end
  517 end
  518 
  519 @testset "posv and some errors for friends" begin
  520     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  521         local n = 10
  522         A = rand(elty,n,n)/100
  523         A += real(diagm(0 => n*real(rand(elty,n))))
  524         if elty <: Complex
  525             A = A + A'
  526         else
  527             A = A + transpose(A)
  528         end
  529         B = rand(elty,n,n)
  530         D = copy(A)
  531         C = copy(B)
  532         D,C = LAPACK.posv!('U',D,C)
  533         @test A\B ≈ C
  534         offsizemat = Matrix{elty}(undef, n+1, n+1)
  535         @test_throws DimensionMismatch LAPACK.posv!('U', D, offsizemat)
  536         @test_throws DimensionMismatch LAPACK.potrs!('U', D, offsizemat)
  537 
  538         @test LAPACK.potrs!('U',Matrix{elty}(undef,0,0),elty[]) == elty[]
  539     end
  540 end
  541 
  542 @testset "gesvx" begin
  543     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  544         A = rand(elty,10,10)
  545         B = rand(elty,10,5)
  546         C = copy(A)
  547         D = copy(B)
  548         X, rcond, f, b, r = LAPACK.gesvx!(C,D)
  549         @test X ≈ A\B rtol=inv(rcond)*eps(real(elty))
  550     end
  551 end
  552 
  553 @testset "gees, gges error throwing" begin
  554     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  555         A = rand(elty,10,10)
  556         B = rand(elty,11,11)
  557         @test_throws DimensionMismatch LAPACK.gges!('V','V',A,B)
  558     end
  559 end
  560 
  561 @testset "trrfs & trevc" begin
  562     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  563         T = triu(rand(elty,10,10))
  564         S = copy(T)
  565         select = zeros(LinearAlgebra.BlasInt,10)
  566         select[1] = 1
  567         select,Vr = LAPACK.trevc!('R','S',select,copy(T))
  568         @test Vr ≈ eigvecs(S)[:,1]
  569         select = zeros(LinearAlgebra.BlasInt,10)
  570         select[1] = 1
  571         select,Vl = LAPACK.trevc!('L','S',select,copy(T))
  572         select = zeros(LinearAlgebra.BlasInt,10)
  573         select[1] = 1
  574         select,Vln,Vrn = LAPACK.trevc!('B','S',select,copy(T))
  575         @test Vrn ≈ eigvecs(S)[:,1]
  576         @test Vln ≈ Vl
  577         @test_throws ArgumentError LAPACK.trevc!('V','S',select,copy(T))
  578         @test_throws DimensionMismatch LAPACK.trrfs!('U','N','N',T,rand(elty,10,10),rand(elty,10,11))
  579     end
  580 end
  581 
  582 @testset "laic1" begin
  583     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  584         @test_throws DimensionMismatch LAPACK.laic1!(1,rand(elty,10),real(rand(elty)),rand(elty,11),rand(elty))
  585     end
  586 end
  587 
  588 @testset "trsen" begin
  589     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  590         for job in ('N', 'E', 'V', 'B')
  591             for c in ('V', 'N')
  592                 A = convert(Matrix{elty}, [7 2 2 1; 1 5 2 0; 0 3 9 4; 1 1 1 4])
  593                 T,Q,d = schur(A)
  594                 s, sep = LinearAlgebra.LAPACK.trsen!(job,c,Array{LinearAlgebra.BlasInt}([0,1,0,0]),T,Q)[4:5]
  595                 @test d[1] ≈ T[2,2]
  596                 @test d[2] ≈ T[1,1]
  597                 if c == 'V'
  598                     @test  Q*T*Q' ≈ A
  599                 end
  600                 if job == 'N' || job == 'V'
  601                     @test iszero(s)
  602                 else
  603                     @test s ≈ 0.8080423 atol=1e-6
  604                 end
  605                 if job == 'N' || job == 'E'
  606                     @test iszero(sep)
  607                 else
  608                     @test sep ≈ 2. atol=3e-1
  609                 end
  610             end
  611         end
  612     end
  613 end
  614 
  615 @testset "trexc" begin
  616     @testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
  617         for c in ('V', 'N')
  618             A = convert(Matrix{elty}, [7 2 2 1; 1 5 2 0; 0 3 9 4; 1 1 1 4])
  619             T,Q,d = schur(A)
  620             LinearAlgebra.LAPACK.trexc!(c,LinearAlgebra.BlasInt(1),LinearAlgebra.BlasInt(2),T,Q)
  621             @test d[1] ≈ T[2,2]
  622             @test d[2] ≈ T[1,1]
  623             if c == 'V'
  624                 @test Q*T*Q' ≈ A
  625             end
  626         end
  627     end
  628 end
  629 
  630 @testset "Julia vs LAPACK" begin
  631     # Test our own linear algebra functionality against LAPACK
  632     @testset for elty in (Float32, Float64, Complex{Float32}, Complex{Float64})
  633         for nn in (5,10,15)
  634             if elty <: Real
  635                 A = convert(Matrix{elty}, randn(10,nn))
  636             else
  637                 A = convert(Matrix{elty}, complex.(randn(10,nn),randn(10,nn)))
  638             end    ## LU (only equal for real because LAPACK uses different absolute value when choosing permutations)
  639             if elty <: Real
  640                 FJulia  = LinearAlgebra.generic_lufact!(copy(A))
  641                 FLAPACK = LinearAlgebra.LAPACK.getrf!(copy(A))
  642                 @test FJulia.factors ≈ FLAPACK[1]
  643                 @test FJulia.ipiv ≈ FLAPACK[2]
  644                 @test FJulia.info ≈ FLAPACK[3]
  645             end
  646 
  647             ## QR
  648             FJulia  = LinearAlgebra.qrfactUnblocked!(copy(A))
  649             FLAPACK = LinearAlgebra.LAPACK.geqrf!(copy(A))
  650             @test FJulia.factors ≈ FLAPACK[1]
  651             @test FJulia.τ ≈ FLAPACK[2]
  652         end
  653     end
  654 end
  655 
  656 # Issue 13976
  657 let A = [NaN 0.0 NaN; 0 0 0; NaN 0 NaN]
  658     @test_throws ArgumentError exp(A)
  659 end
  660 
  661 # Issue 14065 (and 14220)
  662 let A = [NaN NaN; NaN NaN]
  663     @test_throws ArgumentError eigen(A)
  664 end
  665 
  666 end # module TestLAPACK