Skip to content

Bug in xGEQRF Julia wrapper for matrices with zero columns #882

@andreasvarga

Description

@andreasvarga

The following linear algebra wrapper fails on matrices with zero number of columns:

LinearAlgebra.LAPACK.geqrf!(rand(2,0),zeros(0))
 ** On entry to DGEQRF parameter number  7 had an illegal value
ERROR: ArgumentError: invalid argument JuliaLang/julia#7 to LAPACK call
Stacktrace:
 [1] chklapackerror(ret::Int64)
   @ LinearAlgebra.LAPACK C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\lapack.jl:36
 [2] geqrf!(A::Matrix{Float64}, tau::Vector{Float64})
   @ LinearAlgebra.LAPACK C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\lapack.jl:519
 [3] top-level scope
   @ REPL[89]:1

The 7-th argument of the LAPACK subroutine DGEQRF is LWORK (the length of work array WORK) and it must satisfy LWORK >= max( 1, N ), where N is the column dimension of the matrix (in our case N = 0). In the Julia function geqrf!, a first call is performed with LWORK = -1, which is used to determine the optimal length of the work array, which is returned in WORK(1). I suspect that the returned value is 0 and therefore, at the second call LWORK = 0 is used, which leads to the above error. This error can be easily fixed in Julia, by replacing in geqrf!
lwork = BlasInt(real(work[1]))
by
lwork = max(1,BlasInt(real(work[1])))
at the second call.

Similar fix is necessary also for gerqf!, because

LinearAlgebra.LAPACK.gerqf!(rand(2,0),zeros(0))
 ** On entry to DGERQF parameter number  7 had an illegal value
ERROR: ArgumentError: invalid argument JuliaLang/julia#7 to LAPACK call
Stacktrace:
 [1] chklapackerror(ret::Int64)
   @ LinearAlgebra.LAPACK C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\lapack.jl:36
 [2] gerqf!(A::Matrix{Float64}, tau::Vector{Float64})
   @ LinearAlgebra.LAPACK C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\lapack.jl:548
 [3] top-level scope
   @ REPL[91]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions