Skip to content
Snippets Groups Projects

jld2 readdict for nested groups, fixes #24

Merged Philip Bittihn requested to merge jld2nesteddicts into dev
1 unresolved thread
1 file
+ 17
1
Compare changes
  • Side-by-side
  • Inline
+ 17
1
@@ -23,5 +23,21 @@ Base.setindex!(g::JLD2.JLDFile, value::Dict{String, Any}, key::String) = InPartS
# more efficient readdict
readdict(g::Union{JLD2.JLDFile, JLD2.Group}; kwargs...) = JLD2.loadtodict!(Dict{String,Any}(), g)
# copied and modified from previous JLD2.loadtodict!(Dict{String,Any}(), g)
# to preserve nestedness
# is faster than generic version in generic.jl because reading via `g[k]`
# only happens once
function readdict(g::Union{JLD2.JLDFile, JLD2.Group}; kwargs...)
d = Dict{String, Any}()
for k in keys(g)
v = g[k]
if v isa JLD2.Group
d[k] = readdict(v)
else
d[k] = v
end
end
return d
end
readdict(d::Dict) = d
Loading