From f0d98565957e09c6ff20446457e86daab78098a4 Mon Sep 17 00:00:00 2001 From: "Luiz M. Faria" Date: Sun, 14 Jul 2024 11:01:49 +0200 Subject: [PATCH] warn regarding possible failure of `aca` --- src/compressor.jl | 6 ++++++ test/compressor_test.jl | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/compressor.jl b/src/compressor.jl index 00629d8..46a9fd1 100644 --- a/src/compressor.jl +++ b/src/compressor.jl @@ -115,6 +115,12 @@ function _aca_partial(K, irange, jrange, atol, rmax, rtol, istart, buffer_ = not r = 0 # current rank while er > max(atol, rtol * est_norm) && r < rmax # remove index i from allowed row + if i < 1 + all(j -> iszero(K[first(irange), j]), jrange) && + all(i -> iszero(K[i, first(jrange)]), irange) || + @warn "aca possibly failed on $irange × $jrange" + break + end I[i] = false # pre-allocate row and column a = newcol!(A) diff --git a/test/compressor_test.jl b/test/compressor_test.jl index 3ebaab5..91da987 100644 --- a/test/compressor_test.jl +++ b/test/compressor_test.jl @@ -22,6 +22,20 @@ Random.seed!(1) aca = PartialACA(; atol = atol) R = aca(M, irange, jrange) @test norm(Matrix(R) - M) < atol + # test zero matrix + R = aca(zero(M), irange, jrange) + @test norm(Matrix(R)) ≈ 0.0 + # low-rank because singular values decay to zero immediately. Error + # estimator fails, and warning is thrown + tmp = 0 * M + tmp[end-20:end, :] .= rand(T, 21, n) + R = aca(tmp, irange, jrange) + @test Matrix(R) ≈ tmp + tmp = 0 * M + tmp[1:20, :] .= rand(T, 20, n) + R = aca(tmp, irange, jrange) + @test Matrix(R) ≈ tmp + rtol = 1e-5 aca = PartialACA(; rtol = rtol) R = aca(M, irange, jrange) @@ -31,10 +45,6 @@ Random.seed!(1) R = aca(M, irange, jrange) @test rank(R) == r - # test zero matrix - R = aca(zero(M), irange, jrange) - @test norm(Matrix(R)) ≈ 0.0 - # test fast update of frobenius norm m, n = 10000, 1000 r = 10