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

Fix some displays #178

Merged
merged 1 commit into from
Oct 22, 2022
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Lux"
uuid = "b2108857-7c20-44ae-9111-449ecde12c47"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "0.4.29"
version = "0.4.30"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
25 changes: 7 additions & 18 deletions src/layers/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ function _big_show(io::IO, obj, indent::Int=0, name=nothing)
for k in Base.keys(obj)
_big_show(io, obj.layers[k], indent + 4, k)
end
elseif children isa NamedTuple
for (k, c) in pairs(children)
_big_show(io, c, indent + 4, k)
end
else
if children isa NamedTuple
for (k, c) in pairs(children)
_big_show(io, c, indent + 4, k)
end
else
for c in children
_big_show(io, c, indent + 4)
end
for c in children
_big_show(io, c, indent + 4)
end
end
if indent == 0 # i.e. this is the outermost container
Expand All @@ -75,6 +73,7 @@ end
_get_children(s::SkipConnection) = (s.layers, s.connection)
_get_children(s::WeightNorm) = (s.layer,)
_get_children(::Any) = ()
_get_children(nt::NamedTuple) = nt

function Base.show(io::IO, ::MIME"text/plain", x::AbstractExplicitLayer)
if !get(io, :compact, false)
Expand Down Expand Up @@ -122,16 +121,6 @@ function underscorise(n::Integer)
return join(reverse(join.(reverse.(Iterators.partition(digits(n), 3)))), '_')
end

function _nan_show(io::IO, x)
if !isempty(x) && _all(iszero, x)
printstyled(io, " (all zero)"; color=:cyan)
elseif _any(isnan, x)
printstyled(io, " (some NaN)"; color=:red)
elseif _any(isinf, x)
printstyled(io, " (some Inf)"; color=:red)
end
end

_any(f, xs::AbstractArray{<:Number}) = any(f, xs)
_any(f, xs) = any(x -> _any(f, x), xs)
_any(f, x::Number) = f(x)
Expand Down