From 4301a210128f7612b2be1ed52bb23ef5b5803b2a Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Tue, 1 Dec 2026 01:35:09 -0700 Subject: [PATCH 1/3] Fix exact singularity checks in fallback LU pivot search The non-LAPACK pivot search rejected a nonzero maximum at or below machine epsilon. Scaling an invertible matrix down therefore made the fallback report singularity while the native CPU panel path accepted it. Use an exact zero check and preserve the existing first-global-zero index. Integrate the numerical repair from PRs #631 and #634 into current master without restoring their historical per-row LU implementation. Direct fallback controls cover four BLAS types, diagonal and off-diagonal tiny pivots, true zeros, later panels, and an already-recorded singular index. The exact-master control failed 16 tiny-pivot assertions; the candidate passes all 32 tiny-pivot and 20 zero-index assertions on Julia 1.10.11 and 1.13.4. GPU execution itself was not tested. After ten 1000-call warmups and five GC-separated 1000-call samples on Julia 1.13.4, all allocation vectors match exact master for all four BLAS types. Minima are 123808 bytes / 5041 allocations for Float32/ComplexF32 and 155808 bytes / 5041 allocations for Float64/ComplexF64, unchanged. These direct-helper counts do not claim whole-LU performance. Written by an AI agent on jpsamaroo's review feedback. --- AGENTS.md | 9 +++++++++ src/array/lu.jl | 3 +-- test/array/linalg/lu.jl | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ad8c5740e..4d3915a19 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1217,3 +1217,12 @@ this section verbatim). Each entry is one bullet starting with `- `. the protocol alone is not enough for them. Test with a remote reader *and* a remote writer, in both orders: in one process every slot is the argument itself, so none of this is visible. + +109. **LU singularity is an exact zero-pivot condition, not an epsilon test.** + The fallback pivot search marked a nonzero column maximum at or below + `eps(T)` as singular, rejecting an invertible matrix merely because it + was scaled down. The CPU LAPACK panel path already uses exact zeros and + therefore hides this error in ordinary CPU factorization tests. Exercise + the fallback search directly with tiny nonzero and true-zero pivots, + including off-diagonal candidates and later panels; retain the first + global zero column once it has been recorded. diff --git a/src/array/lu.jl b/src/array/lu.jl index 3c0cc0f0a..b68121112 100644 --- a/src/array/lu.jl +++ b/src/array/lu.jl @@ -88,8 +88,7 @@ function search_and_update_ipiv!(ipiv_chunk::AbstractVector{Int}, info::Ref{Int} end end - Tf = real(float(T)) - if info[] == 0 && best_mag <= eps(Tf) + if info[] == 0 && iszero(best_mag) info[] = (k-1)*mb + p end diff --git a/test/array/linalg/lu.jl b/test/array/linalg/lu.jl index 0de5bab03..b1cf93a06 100644 --- a/test/array/linalg/lu.jl +++ b/test/array/linalg/lu.jl @@ -13,6 +13,41 @@ function factorization_rtol(T, pivot) end end +@testset "Fallback LU pivot singularity" begin + for T in (Float32, Float64, ComplexF32, ComplexF64) + for tiny in (T(eps(real(T)) / 100), T(eps(real(T)))) + # Exercise the non-LAPACK search directly: a CPU compute scope + # normally selects the panel fast path and hides this fallback. + for off_diagonal in (false, true) + info = Ref(0) + ipiv = zeros(Int, 2) + diagonal = T[tiny 0; 0 1] + if off_diagonal + diagonal[1, 1] = 0 + off = T[tiny 0; 0 1] + Dagger.search_and_update_ipiv!(ipiv, info, diagonal, 1, 1, 2, 4, 1, off) + @test ipiv[1] == 3 + else + Dagger.search_and_update_ipiv!(ipiv, info, diagonal, 1, 1, 2, 2, 0) + @test ipiv[1] == 1 + end + @test info[] == 0 + end + end + + # A true zero records its global column once, including later panels. + for (k, p, initial, expected) in ((1, 1, 0, 1), (1, 2, 0, 2), + (2, 1, 0, 3), (2, 2, 0, 4), (2, 1, 1, 1)) + info = Ref(initial) + ipiv = zeros(Int, 2) + Dagger.search_and_update_ipiv!(ipiv, info, zeros(T, 2, 2), k, p, 2, 4, 0) + @test info[] == expected + end + end +end + + + function test_lu_pivot_blocks(::Type{T}, part, pivot) where T A = Matrix{T}(I, 13, 13) + rand(T, 13, 13) / 20 F = lu(distribute(A, part), pivot) From 423fa1c8ff9a824d471201725bc4cc74299ff27e Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Tue, 1 Dec 2026 01:35:09 -0700 Subject: [PATCH 2/3] Honor allowsingular in LU on Julia 1.9 and 1.10 The older-runtime success-check branch avoided the unavailable stdlib helper but always raised SingularException for a positive pivot index, even when the distributed LU caller requested allowsingular=true. Guard the positive-error check with that flag, retaining metadata and the modern-runtime check. The default still rejects singular matrices. Carry the compatibility repair from PRs #631 and #634 into the current LAPACK-panel implementation. On exact master, native Julia 1.10.11 raised on all four BLAS-type allowsingular cases; the candidate passes all 12 singularity controls, including default rejection and info=2 with check=false or allowsingular=true. Julia 1.13.4 passes the same controls. Both runtimes pass all 188 focused integration assertions, including rectangular factor storage and distributed solve/inverse equivalents. Julia 1.9 was not available; it shares the tested older-runtime branch. Written by an AI agent on jpsamaroo's review feedback. --- AGENTS.md | 7 +++++++ src/array/lu.jl | 2 +- test/array/linalg/lu.jl | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4d3915a19..36f84051a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1226,3 +1226,10 @@ this section verbatim). Each entry is one bullet starting with `- `. the fallback search directly with tiny nonzero and true-zero pivots, including off-diagonal candidates and later panels; retain the first global zero column once it has been recorded. + +110. **A version fallback must preserve Dagger's keyword contract.** + Julia 1.9/1.10 lack LinearAlgebra's `_check_lu_success`, but replacing it + with unconditional `checknonsingular` also discards `allowsingular=true`. + Honor that flag before raising a positive pivot error, and retain the + global singular-column metadata. Check the public distributed LU call + on the older runtime: modern-runtime tests only exercise the other branch. diff --git a/src/array/lu.jl b/src/array/lu.jl index b68121112..0933cb1ad 100644 --- a/src/array/lu.jl +++ b/src/array/lu.jl @@ -376,7 +376,7 @@ function LinearAlgebra.lu!(A::DMatrix{T}, ::LinearAlgebra.RowMaximum; check::Boo @static if VERSION >= v"1.11-" LinearAlgebra._check_lu_success(panel_info, allowsingular) else - LinearAlgebra.checknonsingular(panel_info) + allowsingular || LinearAlgebra.checknonsingular(panel_info) end end return panel_info diff --git a/test/array/linalg/lu.jl b/test/array/linalg/lu.jl index b1cf93a06..b0fc84925 100644 --- a/test/array/linalg/lu.jl +++ b/test/array/linalg/lu.jl @@ -46,7 +46,14 @@ end end end - +@testset "Pivoted LU allowsingular across Julia versions" begin + for T in (Float32, Float64, ComplexF32, ComplexF64) + matrix = Matrix(Diagonal(T[1, 0, 2, 0])) + @test_throws LinearAlgebra.SingularException lu(distribute(matrix, Blocks(2, 2)), RowMaximum()) + @test lu(distribute(matrix, Blocks(2, 2)), RowMaximum(); check=false).info == 2 + @test lu(distribute(matrix, Blocks(2, 2)), RowMaximum(); allowsingular=true).info == 2 + end +end function test_lu_pivot_blocks(::Type{T}, part, pivot) where T A = Matrix{T}(I, 13, 13) + rand(T, 13, 13) / 20 From 9b2217b9b373790c51966e69d32f4fc5a9d8b9f0 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Mon, 30 Nov 2026 15:39:21 -0700 Subject: [PATCH 3/3] Run custom commands on Dagger's minimum supported Julia Review finding: Custom Commands installs Julia 1.9 despite Project.toml requiring Julia 1.10. On ubuntu-latest, Julia 1.9.4 now fails its startup check because libopenlibm requests an executable stack, before Dagger loads. This affects otherwise unrelated pull requests. Select the supported 1.10 release line, already exercised by the main CPU matrix. The workflow's commands and permissions stay unchanged. Validation: git diff --check; compared with Project.toml's Julia bound and the passing Julia 1.10 jobs on master 46f6315c. Hosted verification follows on the new PR; no application tests were changed. Written by an AI agent on jpsamaroo's review feedback. --- .github/workflows/CustomCommands.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CustomCommands.yml b/.github/workflows/CustomCommands.yml index 2cb8dc54c..5c96003eb 100644 --- a/.github/workflows/CustomCommands.yml +++ b/.github/workflows/CustomCommands.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v7 - uses: julia-actions/setup-julia@v3 with: - version: '1.9' + version: '1.10' arch: 'x64' - name: Run provided commands