Sparse matrix error with forward diff

The problem is that logabsdet calls lu factorization, but LU factorization for sparse matrices in Julia uses UMFPACK from SuiteSparse, which is an external library that only supports the standard hardware floating-point types. It won’t work for dual numbers, hence it won’t work with ForwardDiff.

(In particular, this line is calling float to convert the matrix to a floating-point type, but this hits a dispatch loop because the Dual numbers already are floating-point, and it overflows the stack. It really should be fixed to give a more comprehensible error message.)

In general, I find that automatic differentiation through sparse-matrix computations is almost always problematic, and one often has to write derivative rules out by hand. (See also this discussion.) Fortunately, it is quite straightforward to take the derivative of a log determinant, as explained in these notes and this lecture from our Matrix Calculus course at MIT.

3 Likes