diff --git a/stdlib/SuiteSparse/src/umfpack.jl b/stdlib/SuiteSparse/src/umfpack.jl index 155cbe2ab53ef..259ec6208d521 100644 --- a/stdlib/SuiteSparse/src/umfpack.jl +++ b/stdlib/SuiteSparse/src/umfpack.jl @@ -190,9 +190,18 @@ function size(F::UmfpackLU, dim::Integer) end end -function show(io::IO, F::UmfpackLU) - print(io, "UMFPACK LU Factorization of a $(size(F)) sparse matrix") - F.numeric != C_NULL && print(io, '\n', F.numeric) +function show(io::IO, mime::MIME{Symbol("text/plain")}, F::UmfpackLU) + if F.numeric != C_NULL + if issuccess(F) + summary(io, F); println(io) + println(io, "L factor:") + show(io, mime, F.L) + println(io, "\nU factor:") + show(io, mime, F.U) + else + print(io, "Failed factorization of type $(typeof(F))") + end + end end function deserialize(s::AbstractSerializer, t::Type{UmfpackLU{Tv,Ti}}) where {Tv,Ti} diff --git a/stdlib/SuiteSparse/test/umfpack.jl b/stdlib/SuiteSparse/test/umfpack.jl index 356c0cf3fa4e7..e7ad0644b5d8c 100644 --- a/stdlib/SuiteSparse/test/umfpack.jl +++ b/stdlib/SuiteSparse/test/umfpack.jl @@ -190,3 +190,19 @@ using LinearAlgebra: Adjoint, Transpose, SingularException end end + +@testset "REPL printing of UmfpackLU" begin + # regular matrix + A = sparse([1, 2], [1, 2], Float64[1.0, 1.0]) + F = lu(A) + facstring = sprint((t, s) -> show(t, "text/plain", s), F) + lstring = sprint((t, s) -> show(t, "text/plain", s), F.L) + ustring = sprint((t, s) -> show(t, "text/plain", s), F.U) + @test facstring == "$(summary(F))\nL factor:\n$lstring\nU factor:\n$ustring" + + # singular matrix + B = sparse(zeros(Float64, 2, 2)) + F = lu(B; check=false) + facstring = sprint((t, s) -> show(t, "text/plain", s), F) + @test facstring == "Failed factorization of type $(summary(F))" +end