Created
September 28, 2020 12:20
-
-
Save oxinabox/b560457bacd9129248aa483488dc8943 to your computer and use it in GitHub Desktop.
Decomposes til isbits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print_isbits(f) | |
seen = Set() | |
MAX_ELE = 3 | |
function print_isbits(fname, fval::FTYPE, indent) where FTYPE | |
ftext = "$fname - $FTYPE\n" | |
print(" "^indent) | |
fbits = isbitstype(FTYPE) | |
if fbits | |
printstyled("✔ $ftext"; color=:green) | |
else | |
printstyled("✘ $ftext"; color=:red) | |
if fval ∉ seen | |
push!(seen, fval) | |
print_isbits_children(fval, indent+1) | |
else | |
print(" "^indent) | |
printstyled(" ⤴⤴⤴\n"; color=:blue) | |
end | |
end | |
end | |
function print_isbits_children(fval::Vector, indent) | |
isempty(fval) && return nothing | |
if !isabstracttype(eltype(fval)) | |
# concrete eltype means don't need to break it down | |
print_isbits("elements", first(fval), indent) | |
else | |
for (ii, cval) in enumerate(fval[1:min(end, MAX_ELE)]) | |
print_isbits("$ii", cval, indent) | |
end | |
if length(fval) > MAX_ELE | |
print(" "^indent) | |
printstyled("... ...\n"; color=:blue) | |
end | |
end | |
end | |
function print_isbits_children(fval::AbstractDict, indent) | |
# redispatch to used vector display | |
print(" "^indent) | |
printstyled("keys:\n"; color=:blue) | |
print_isbits_children(collect(keys(fval)), indent) | |
print(" "^indent) | |
printstyled("values:\n"; color=:blue) | |
print_isbits_children(collect(values(fval)), indent) | |
end | |
function print_isbits_children(fval::FTYPE, indent) where FTYPE | |
isabstracttype(FTYPE) && return nothing | |
for child_name in fieldnames(FTYPE) | |
child_value = getfield(fval, child_name) | |
print_isbits(child_name, child_value, indent) | |
end | |
end | |
# Don't try and break down internals of types | |
print_isbits_children(fval::Type, indent) = nothing | |
print_isbits("🌸", f, 0) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
discussion at:
https://discourse.julialang.org/t/finding-non-isbits-fields/47402