Skip to content

Commit 901430b

Browse files
author
Marc Ritter
committed
Merge branch '40-bug-lu-may-have-0-pivots-if-the-whole-matrix-is-abstol' into 'main'
Resolve "Bug: lu may have 0 pivots if the whole matrix is < abstol" Closes #40 and #41 See merge request tensors4fields/TensorCrossInterpolation.jl!77
2 parents c66fe0d + 776e2bf commit 901430b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
1010

1111
[compat]
1212
EllipsisNotation = "1"
13-
julia = "1.6"
1413
QuadGK = "2.9"
14+
julia = "1.6"
1515

1616
[extras]
1717
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

src/matrixlu.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ function _optimizerrlu!(
136136
k = lu.npivot + 1
137137
newpivot = submatrixargmax(abs2, A, k)
138138
lu.error = abs(A[newpivot...])
139-
if abs(lu.error) < reltol * maxerror || abs(lu.error) < abstol
139+
# Add at least 1 pivot to get a well-defined L * U
140+
if (abs(lu.error) < reltol * maxerror || abs(lu.error) < abstol) && lu.npivot > 0
140141
break
141142
end
142143
maxerror = max(maxerror, lu.error)

test/test_matrixlu.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,20 @@ using LinearAlgebra
192192
lu3 = TCI.rrlu(A, abstol=0.0)
193193
@test TCI.lastpivoterror(lu3) == 0.0
194194
end
195+
196+
@testset "LU for matrices with very small absolute values" begin
197+
A = 1e-13 * [
198+
0.585383 0.124568 0.352426 0.573507
199+
0.865875 0.600153 0.727443 0.902388
200+
0.913477 0.954081 0.116965 0.817
201+
0.985918 0.516114 0.600366 0.0200085
202+
]
203+
204+
lu = TCI.rrlu(A, abstol=1e-3)
205+
@test TCI.npivots(lu) == 1
206+
@test length(TCI.pivoterrors(lu)) > 0
207+
@test TCI.lastpivoterror(lu) > 0
208+
@test size(lu) == size(A)
209+
@test maximum(abs.(TCI.left(lu) * TCI.right(lu) .- A)) < 1e-3
210+
end
195211
end

0 commit comments

Comments
 (0)