Skip to content

Commit 2fab1b3

Browse files
authored
[LAPACK] Update the dispatch of getrf! (#51486)
`getrf!` should take the vector `ipiv` as input the same way that `geqrf!` uses the vector `tau`.
1 parent 7b0af64 commit 2fab1b3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/lapack.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Interfaces to LAPACK subroutines.
88
using ..LinearAlgebra.BLAS: @blasfunc, chkuplo
99

1010
using ..LinearAlgebra: libblastrampoline, BlasFloat, BlasInt, LAPACKException, DimensionMismatch,
11-
SingularException, PosDefException, chkstride1, checksquare,triu, tril, dot
11+
SingularException, PosDefException, chkstride1, checksquare, triu, tril, dot
1212

1313
using Base: iszero, require_one_based_indexing
1414

@@ -554,13 +554,12 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty
554554
# * .. Array Arguments ..
555555
# INTEGER IPIV( * )
556556
# DOUBLE PRECISION A( LDA, * )
557-
function getrf!(A::AbstractMatrix{$elty}; check = true)
557+
function getrf!(A::AbstractMatrix{$elty}, ipiv::AbstractVector{BlasInt}; check::Bool=true)
558558
require_one_based_indexing(A)
559559
check && chkfinite(A)
560560
chkstride1(A)
561561
m, n = size(A)
562562
lda = max(1,stride(A, 2))
563-
ipiv = similar(A, BlasInt, min(m,n))
564563
info = Ref{BlasInt}()
565564
ccall((@blasfunc($getrf), libblastrampoline), Cvoid,
566565
(Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty},
@@ -679,15 +678,13 @@ Returns `A` and `tau` modified in-place.
679678
gerqf!(A::AbstractMatrix, tau::AbstractVector)
680679

681680
"""
682-
getrf!(A) -> (A, ipiv, info)
683-
684-
Compute the pivoted `LU` factorization of `A`, `A = LU`.
681+
getrf!(A, ipiv) -> (A, ipiv, info)
685682
686-
Returns `A`, modified in-place, `ipiv`, the pivoting information, and an `info`
687-
code which indicates success (`info = 0`), a singular value in `U`
688-
(`info = i`, in which case `U[i,i]` is singular), or an error code (`info < 0`).
683+
Compute the pivoted `LU` factorization of `A`, `A = LU`. `ipiv` contains the pivoting
684+
information and `info` a code which indicates success (`info = 0`), a singular value
685+
in `U` (`info = i`, in which case `U[i,i]` is singular), or an error code (`info < 0`).
689686
"""
690-
getrf!(A::AbstractMatrix, tau::AbstractVector)
687+
getrf!(A::AbstractMatrix, ipiv::AbstractVector; check::Bool=true)
691688

692689
"""
693690
gelqf!(A) -> (A, tau)
@@ -751,6 +748,17 @@ which parameterize the elementary reflectors of the factorization.
751748
"""
752749
gerqf!(A::AbstractMatrix{<:BlasFloat}) = ((m,n) = size(A); gerqf!(A, similar(A, min(m, n))))
753750

751+
"""
752+
getrf!(A) -> (A, ipiv, info)
753+
754+
Compute the pivoted `LU` factorization of `A`, `A = LU`.
755+
756+
Returns `A`, modified in-place, `ipiv`, the pivoting information, and an `info`
757+
code which indicates success (`info = 0`), a singular value in `U`
758+
(`info = i`, in which case `U[i,i]` is singular), or an error code (`info < 0`).
759+
"""
760+
getrf!(A::AbstractMatrix{T}; check::Bool=true) where {T <: BlasFloat} = ((m,n) = size(A); getrf!(A, similar(A, BlasInt, min(m, n)); check))
761+
754762
## Tools to compute and apply elementary reflectors
755763
for (larfg, elty) in
756764
((:dlarfg_, Float64),

test/lapack.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,16 @@ end
231231
@testset for elty in (Float32, Float64, ComplexF32, ComplexF64)
232232
A = rand(elty,10,10)
233233
iA = inv(A)
234-
A, ipiv = LAPACK.getrf!(A)
234+
A, ipiv, info = LAPACK.getrf!(A)
235235
A = LAPACK.getri!(A, ipiv)
236236
@test A iA
237+
238+
B = rand(elty,10,10)
239+
iB = inv(B)
240+
ipiv = rand(BlasInt,10)
241+
B, ipiv, info = LAPACK.getrf!(B, ipiv)
242+
B = LAPACK.getri!(B, ipiv)
243+
@test B iB
237244
end
238245
end
239246

0 commit comments

Comments
 (0)