Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty
end
lda = max(1, stride(A,2))
work = Vector{$elty}(undef, nb*n)
if n > 0
if minmn > 0
info = Ref{BlasInt}()
ccall((@blasfunc($geqrt), libblastrampoline), Cvoid,
(Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty},
Expand All @@ -496,7 +496,7 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty
if p != n || q != n
throw(DimensionMismatch("block reflector T has dimensions ($p,$q), but should have dimensions ($n,$n)"))
end
if n > 0
if n > 0 # this implies `m > 0` because of `m >= n`
info = Ref{BlasInt}()
ccall((@blasfunc($geqrt3), libblastrampoline), Cvoid,
(Ref{BlasInt}, Ref{BlasInt}, Ptr{$elty}, Ref{BlasInt},
Expand Down
24 changes: 24 additions & 0 deletions stdlib/LinearAlgebra/test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,28 @@ end
@test x ≈ xf
end

@testset "issue #53451" begin
# in the issue it was noted that QR factorizations of zero-column matrices
# were possible, but zero row-matrices errored, because LAPACK does not
# accept these empty matrices. now, the `geqrt!` call should be forwarded only
# if both matrix dimensions are positive.

for dimA in (0, 1, 2, 4)
for F in (Float32, Float64, ComplexF32, ComplexF64, BigFloat)
# this should have worked before, Q is square, and R is 0 × 0:
A_zero_cols = rand(F, dimA, 0)
qr_zero_cols = qr(A_zero_cols)
@test size(qr_zero_cols.Q) == (dimA, dimA)
@test size(qr_zero_cols.R) == (0, 0)
@test qr_zero_cols.Q == LinearAlgebra.I(dimA)

# this should work now, Q is 0 × 0, and R has `dimA` columns:
A_zero_rows = rand(F, 0, dimA)
qr_zero_rows = qr(A_zero_rows)
@test size(qr_zero_rows.Q) == (0, 0)
@test size(qr_zero_rows.R) == (0, dimA)
end
end
end

end # module TestQR