From 85dc2e8ed2e7424c4753b2e2fd73f8ca99d80540 Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Fri, 19 Aug 2022 09:54:07 +0200 Subject: [PATCH] use deepcopy_internal --- src/entities/JunctionTreeTypes.jl | 34 +++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/entities/JunctionTreeTypes.jl b/src/entities/JunctionTreeTypes.jl index ddc47d8ae..7cf7f4b07 100644 --- a/src/entities/JunctionTreeTypes.jl +++ b/src/entities/JunctionTreeTypes.jl @@ -22,28 +22,36 @@ end const BayesTree = MetaBayesTree -# NOTE overwrite deepcopy on MetaBayesTree to strip out copying the channels. +# NOTE Temporary fix? Overwrite deepcopy on MetaBayesTree to strip out copying the channels. # see https://github.com/JuliaRobotics/IncrementalInference.jl/issues/1530 -function Base.deepcopy(bt::MetaBayesTree) - +# possible fix in https://github.com/JuliaLang/julia/pull/46406 +import Base.deepcopy_internal +function Base.deepcopy_internal(bt::MetaBayesTree, stackdict::IdDict) + + if haskey(stackdict, bt) + return stackdict[bt] + end + mg = bt.bt - graph = deepcopy(mg.graph) - vprops = deepcopy(mg.vprops) + graph = deepcopy_internal(mg.graph, stackdict) + vprops = deepcopy_internal(mg.vprops, stackdict) T = eltype(mg) # dropping all edge data eprops = Dict{MetaGraphs.SimpleEdge{T},MetaGraphs.PropDict}() - gprops = deepcopy(mg.gprops) - weightfield = deepcopy(mg.weightfield) - defaultweight = deepcopy(mg.defaultweight) - metaindex = deepcopy(mg.metaindex) - indices = deepcopy(mg.indices) + gprops = deepcopy_internal(mg.gprops, stackdict) + weightfield = deepcopy_internal(mg.weightfield, stackdict) + defaultweight = deepcopy_internal(mg.defaultweight, stackdict) + metaindex = deepcopy_internal(mg.metaindex, stackdict) + indices = deepcopy_internal(mg.indices, stackdict) - mg_cpy = MetaDiGraph(graph,vprops,eprops,gprops,weightfield,defaultweight,metaindex,indices) + mg_cpy = MetaDiGraph(graph, vprops, eprops, gprops, weightfield, defaultweight, metaindex, indices) - return MetaBayesTree(mg_cpy, bt.btid, deepcopy(bt.frontals), deepcopy(bt.eliminationOrder), bt.buildTime) -end + bt_cpy = MetaBayesTree(mg_cpy, bt.btid, deepcopy_internal(bt.frontals, stackdict), deepcopy_internal(bt.eliminationOrder, stackdict), bt.buildTime) + stackdict[bt] = bt_cpy + return bt_cpy +end """ $TYPEDEF