Description
As was pointed out recently on discourse, the lu
function suffers from numerical instability for non-floating-point matrices, where it tries to do the factorization without pivoting first.
(The example on the mailing list was det([1 1 0 0 1 0 0 0; 1 0 1 0 0 1 0 0; 1 0 0 1 0 0 1 0; 0 1 1 1 0 0 0 0; 0 1 0 0 0 0 1 1; 0 0 1 0 1 0 0 1; 0 0 0 1 1 1 0 0; 0 0 0 0 1 1 0 1])
.)
The problem seems to stem from PR JuliaLang/julia#10215 by @andreasnoack, and indeed the abovementioned determinant started being wrong in Julia 0.4.
As @tpapp suggested, we should default to pivoting at least whenever lutype(T) <: AbstractFloat
, but we also want to handle cases like lutype(Complex{Int}) == Complex{Float64}
. Perhaps the right criterion is to pivot whenever abs(zero(lutype(T))) isa AbstractFloat
since pivoting is based on the abs
function.
(Not sure whether we should try to support types that don't have abs
via try-catch?)