Repository navigation
Description
Summary
PartialACA can silently lose accuracy, or throw a BoundsError, on kernels that vanish identically on parts of an admissible block. A common case is the double-layer kernel ∂G(x,y)/∂ν(y) on polyhedral or partly flat surfaces: it is exactly zero whenever x and y lie on the same flat face. The reproducer below uses only HMatrices.jl, with points on the six faces of a cube and the Laplace double-layer kernel.
Reproducer
using HMatrices, LinearAlgebra, StaticArrays, Random
const Pt = SVector{3,Float64}
# Points (and unit normals) on a uniform grid of each face of the cube [-1,1]^3.
function cube_points(n)
X, N = Pt[], Pt[]
g = range(-1, 1; length = n + 2)[2:end-1]
for axis in 1:3, s in (-1.0, 1.0), a in g, b in g
p, q = zeros(3), zeros(3)
p[axis] = q[axis] = s
p[mod1(axis + 1, 3)] = a
p[mod1(axis + 2, 3)] = b
push!(X, Pt(p)); push!(N, Pt(q))
end
return X, N
end
# Laplace double-layer kernel ∂G(x,y)/∂ν(y); it vanishes exactly when x and y
# lie on the same face (x - y ⟂ ν(y)).
struct DoubleLayer <: AbstractMatrix{Float64}
X::Vector{Pt}
N::Vector{Pt}
end
Base.size(K::DoubleLayer) = (length(K.X), length(K.X))
function Base.getindex(K::DoubleLayer, i::Int, j::Int)
d = K.X[i] - K.X[j]
r = norm(d)
return r == 0 ? 0.0 : dot(d, K.N[j]) / (4π * r^3)
end
function check(n, nmax, rtol)
Random.seed!(1)
X, N = cube_points(n)
K = DoubleLayer(X, N)
tree = ClusterTree(X, HMatrices.CardinalitySplitter(; nmax))
x = randn(length(X))
y = Matrix(K) * x
try
H = assemble_hmatrix(K, tree, tree; comp = PartialACA(; rtol), threads = false)
println("n=$n, nmax=$nmax, rtol=$rtol: relative error ", norm(H * x - y) / norm(y))
catch e
println("n=$n, nmax=$nmax, rtol=$rtol: ", sprint(showerror, e; context = :limit => true)[1:min(end, 80)])
end
end
check(30, 32, 1e-6) # silent loss of accuracy
check(30, 32, 1e-10) # same points, tighter rtol: BoundsError
check(20, 16, 1e-8) # BoundsError: index -1 into a BitVectorOutput with HMatrices v0.2.13 on Julia v1.12.5 (macOS, aarch64):
n=30, nmax=32, rtol=1.0e-6: relative error 0.025752978839732852
n=30, nmax=32, rtol=1.0e-10: BoundsError: attempt to access 40-element BitVector at index [-1]
n=20, nmax=16, rtol=1.0e-8: BoundsError: attempt to access 21-element BitVector at index [-1]
The first case also prints aca possibly failed on ... for some blocks. Tightening rtol does not recover the accuracy. Smooth geometries (e.g. a sphere) do not show the problem, and the same blocks compress correctly with a dense TSVD. The BoundsError stack trace points to _aca_partial in src/compressor.jl:
BoundsError: attempt to access 21-element BitVector at index [-1]
[1] throw_boundserror
[2] checkbounds
[3] setindex! # I[i] = false with i == -1
[4] _aca_partial(K, irange, jrange, atol, rmax, rtol, istart, buffer_)
[5] PartialACA
[6] _assemble_sparse_block!
...
What seems to happen
In _aca_partial (src/compressor.jl):
- Zero rows consume candidates without increasing the rank. When the residual row
bis zero, the zero-pivot branch removes that row fromIand moves tofindfirst(I), without adding a cross. On blocks with many exactly zero rows, the candidate rows can run out whiler < rmaxand while the stopping test has not been met. - The pivot search can return
-1. After a successful cross, the next row isi = _aca_partial_pivot(a, I). This returns-1when no index is both unused and selectable, for instance when all rows ofIwere consumed as in (1). The next iteration then executesI[i] = falsewithi == -1, which gives theBoundsError. - Early stopping on block-structured residuals. Because the next row is chosen from the current column, rows that are zero in that column are never visited, even if their residual is large in other columns. The stopping test
norm(a)*norm(b) ≤ rtol*‖R‖then accepts an approximation that misses whole sub-blocks. This is the classical failure of partial-pivoting ACA on matrices with zero sub-blocks, and it explains the silent loss of accuracy.
Possible fix
What fixed it for us was a small change to the same algorithm:
- treat a pivot of
-1(or an exhaustedI) as "no candidate left" and stop, instead of indexing; - before accepting the stopping criterion, check the residual on a few randomly sampled unvisited rows and columns, and continue from a failing sample if any is not small (as in ACA+-type safeguards).
With these changes, the compressed double-layer operators match the dense ones to better than 1e-7 (relative) at rtol = 1e-9 on flat-faced meshes, with negligible extra cost. Happy to share the implementation or open a PR if that would help.
Context
We hit this while compressing the Helmholtz double-layer and adjoint double-layer operators of a Galerkin BEM on polyhedral surfaces (cubes, L-shaped prisms, and rounded cubes with flat faces). There, ACA quietly introduced an error of about 1% in the double-layer operators.
Activity
maltezfaria commentedon Nov 2, 2026
Thanks for the detailed issue! There is a recent branch,
compressor, which possibly already contains a fix. I will merge that branch this week and see if it fixes the problem.