Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve REPL printing of UmfpackLU #33705

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions stdlib/SuiteSparse/src/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
16 changes: 16 additions & 0 deletions stdlib/SuiteSparse/test/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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