Open dlfivefifty opened 5 months ago
We can fix this by changing partialcholesky!
to check whether it hits the diagonal special case:
function partialcholesky!(F::AdaptiveCholeskyFactors{T,<:BandedMatrix}, n::Int) where T
if n > F.ncols
_,u = bandwidths(F.data.array)
resizedata!(F.data,n+u,n+u);
ncols = F.ncols
kr = ncols+1:n
factors = view(F.data.data,kr,kr)
banded_chol!(factors, UpperTriangular)
# multiply remaining columns
kr2 = max(n-u+1,kr[1]):n
U1 = UpperTriangular(view(F.data.data,kr2,kr2))
B = view(F.data.data,kr2,n+1:n+u)
ldiv!(U1',B)
if u > 0
muladd!(-one(T),B',B,one(T),view(F.data.data,n+1:n+u,n+1:n+u))
else # Diagonal special case
muladd!(-one(T),zeros(T,0,0),zeros(T,0,0),one(T),view(F.data.data,n+1:n+u,n+1:n+u))
end
F.ncols = n
end
F
end
The only change is the else
case of the if
statement at the bottom. A more proper fix I suppose would be to fix this upstream in ArrayLayouts. The issue is basically that it's handing an empty banded matrix with bandwidths (0,-1)
which breaks MulAdd
somewhere. (the placement of the if statement should happen sooner for efficiency and we can avoid muladd altogether in the diagonal case if we special case it but it's more clear what breaks for this comment when written this way)
Basically two options: