Skip to content

Commit

Permalink
Make the printing of the cache more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed May 25, 2024
1 parent e567049 commit 05fb063
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "3.12.1"
version = "3.12.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
24 changes: 14 additions & 10 deletions src/abstract_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,17 @@ Abstract Type for all NonlinearSolve.jl Caches.
abstract type AbstractNonlinearSolveCache{iip, timeit} end

function SymbolicIndexingInterface.symbolic_container(cache::AbstractNonlinearSolveCache)
cache.prob
return cache.prob
end
function SymbolicIndexingInterface.parameter_values(cache::AbstractNonlinearSolveCache)
parameter_values(symbolic_container(cache))
return parameter_values(symbolic_container(cache))
end
function SymbolicIndexingInterface.state_values(cache::AbstractNonlinearSolveCache)
state_values(symbolic_container(cache))
return state_values(symbolic_container(cache))
end

function Base.getproperty(cache::AbstractNonlinearSolveCache, sym::Symbol)
if sym == :ps
return ParameterIndexingProxy(cache)
end
sym == :ps && return ParameterIndexingProxy(cache)
return getfield(cache, sym)
end

Expand All @@ -230,10 +228,16 @@ function __show_cache(io::IO, cache::AbstractNonlinearSolveCache, indent = 0)
println(io, "$(nameof(typeof(cache)))(")
__show_algorithm(io, cache.alg,
(" "^(indent + 4)) * "alg = " * string(get_name(cache.alg)), indent + 4)
println(io, ",")
println(io, (" "^(indent + 4)) * "u = ", get_u(cache), ",")
println(io, (" "^(indent + 4)) * "residual = ", get_fu(cache), ",")
println(io, (" "^(indent + 4)) * "inf-norm(residual) = ", norm(get_fu(cache), Inf), ",")

ustr = sprint(show, get_u(cache); context=(:compact=>true, :limit=>true))
println(io, ",\n" * (" "^(indent + 4)) * "u = $(ustr),")

residstr = sprint(show, get_fu(cache); context=(:compact=>true, :limit=>true))
println(io, (" "^(indent + 4)) * "residual = $(residstr),")

normstr = sprint(show, norm(get_fu(cache), Inf); context=(:compact=>true, :limit=>true))
println(io, (" "^(indent + 4)) * "inf-norm(residual) = $(normstr),")

println(io, " "^(indent + 4) * "nsteps = ", cache.stats.nsteps, ",")
println(io, " "^(indent + 4) * "retcode = ", cache.retcode)
print(io, " "^(indent) * ")")
Expand Down

0 comments on commit 05fb063

Please sign in to comment.