Skip to content

Commit fb082cc

Browse files
GunnarFarnebackararslan
authored andcommitted
Bugfix for zero matrix in A_ldiv_B! for QRPivoted (#22831)
* Bugfix for zero matrix in A_ldiv_B! for QRPivoted. * Address review comments. (cherry picked from commit bf47fd9)
1 parent 46e176d commit fb082cc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

base/linalg/qr.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,13 @@ function A_ldiv_B!(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Real) where T<:B
694694
mA, nA = size(A.factors)
695695
nr = min(mA,nA)
696696
nrhs = size(B, 2)
697-
if nr == 0 return zeros(T, 0, nrhs), 0 end
697+
if nr == 0
698+
return zeros(T, 0, nrhs), 0
699+
end
698700
ar = abs(A.factors[1])
699-
if ar == 0 return zeros(T, nr, nrhs), 0 end
701+
if ar == 0
702+
return zeros(T, nA, nrhs), 0
703+
end
700704
rnk = 1
701705
xmin = ones(T, 1)
702706
xmax = ones(T, 1)

test/linalg/qr.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,11 @@ B = rand(7,2)
183183

184184
# Issue 16520
185185
@test_throws DimensionMismatch ones(3,2)\(1:5)
186+
187+
# Issue 22810
188+
let
189+
A = zeros(1, 2)
190+
B = zeros(1, 1)
191+
@test A \ B == zeros(2, 1)
192+
@test qrfact(A, Val{true}) \ B == zeros(2, 1)
193+
end

0 commit comments

Comments
 (0)