Skip to content

Commit 4aef0e0

Browse files
committed
Change the default QR to ColumnNorm
1 parent d050e01 commit 4aef0e0

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearSolve"
22
uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
33
authors = ["SciML"]
4-
version = "2.28.0"
4+
version = "2.29.0"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/LinearSolve.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ needs_concrete_A(alg::AbstractKrylovSubspaceMethod) = false
7070
needs_concrete_A(alg::AbstractSolveFunction) = false
7171

7272
# Util
73+
## This is a check exclusively based on the size and not on the actual rank of the matrix
7374
is_underdetermined(x) = false
7475
is_underdetermined(A::AbstractMatrix) = size(A, 1) < size(A, 2)
7576
is_underdetermined(A::AbstractSciMLOperator) = size(A, 1) < size(A, 2)

src/default.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,9 @@ function defaultalg(A, b, assump::OperatorAssumptions{Bool})
216216
elseif assump.condition === OperatorCondition.WellConditioned
217217
DefaultAlgorithmChoice.NormalCholeskyFactorization
218218
elseif assump.condition === OperatorCondition.IllConditioned
219-
if is_underdetermined(A)
220-
# Underdetermined
221-
DefaultAlgorithmChoice.QRFactorizationPivoted
222-
else
223-
DefaultAlgorithmChoice.QRFactorization
224-
end
219+
DefaultAlgorithmChoice.QRFactorizationPivoted
225220
elseif assump.condition === OperatorCondition.VeryIllConditioned
226-
if is_underdetermined(A)
227-
# Underdetermined
228-
DefaultAlgorithmChoice.QRFactorizationPivoted
229-
else
230-
DefaultAlgorithmChoice.QRFactorization
231-
end
221+
DefaultAlgorithmChoice.QRFactorizationPivoted
232222
elseif assump.condition === OperatorCondition.SuperIllConditioned
233223
DefaultAlgorithmChoice.SVDFactorization
234224
else

test/default_algs.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ solve(prob)
3333

3434
@test LinearSolve.defaultalg(nothing, zeros(5),
3535
LinearSolve.OperatorAssumptions(false)).alg ===
36-
LinearSolve.DefaultAlgorithmChoice.QRFactorization
36+
LinearSolve.DefaultAlgorithmChoice.QRFactorizationPivoted
3737

3838
A = spzeros(2, 2)
3939
# test that solving a singular problem doesn't error
@@ -112,3 +112,35 @@ prob = LinearProblem(funcop, b)
112112
sol1 = solve(prob)
113113
sol2 = solve(prob, LinearSolve.KrylovJL_CRAIGMR())
114114
@test sol1.u == sol2.u
115+
116+
# Default for Underdetermined problem but the size is a long rectangle
117+
A = [2.0 1.0
118+
0.0 0.0
119+
0.0 0.0]
120+
b = [1.0, 0.0, 0.0]
121+
prob = LinearProblem(A, b)
122+
sol = solve(prob)
123+
124+
@test sol.u [0.4, 0.2]
125+
126+
## Show that we cannot select a default alg once by checking the rank, since it might change
127+
## later in the cache
128+
## Common occurence for iterative nonlinear solvers using linear solve
129+
A = [2.0 1.0
130+
1.0 1.0
131+
0.0 0.0]
132+
b = [1.0, 1.0, 0.0]
133+
prob = LinearProblem(A, b)
134+
135+
cache = init(prob)
136+
sol = solve!(cache)
137+
138+
@test sol.u [0.0, 1.0]
139+
140+
cache.A = [2.0 1.0
141+
0.0 0.0
142+
0.0 0.0]
143+
144+
sol = solve!(cache)
145+
146+
@test sol.u [0.4, 0.2]

0 commit comments

Comments
 (0)