@@ -146,7 +146,7 @@ function loadDFG!(
146146 end
147147
148148 # extract the factor graph from fileDFG folder
149- factors = DFGFactor []
149+ factors = FactorCompute []
150150 varFolder = " $folder /variables"
151151 factorFolder = " $folder /factors"
152152 # Folder preparations
@@ -155,45 +155,53 @@ function loadDFG!(
155155 ! isdir (factorFolder) &&
156156 error (" Can't load DFG graph - folder '$factorFolder ' doesn't exist" )
157157
158- varFiles = sort (readdir (varFolder; sort = false ); lt = natural_lt)
159- factorFiles = sort (readdir (factorFolder; sort = false ); lt = natural_lt)
158+ # varFiles = sort(readdir(varFolder; sort = false); lt = natural_lt)
159+ # factorFiles = sort(readdir(factorFolder; sort = false); lt = natural_lt)
160+ varFiles = readdir (varFolder; sort = false )
161+ factorFiles = readdir (factorFolder; sort = false )
160162
161- packedvars = @showprogress 1 " loading variables" asyncmap (varFiles) do varFile
162- jstr = read (" $varFolder /$varFile " , String)
163- return JSON3. read (jstr, PackedVariable)
164- end
165163 # FIXME , why is this treated different from VariableSkeleton, VariableSummary?
166- # FIXME , still creates type instability on `variables` as either `::Variable` or `::DFGVariable`
167- if isa (dfgLoadInto, GraphsDFG) && getTypeDFGVariables (dfgLoadInto) == Variable
168- variables = packedvars
169- else
170- variables = unpackVariable .(packedvars)
164+
165+ usePackedVariable =
166+ isa (dfgLoadInto, GraphsDFG) && getTypeDFGVariables (dfgLoadInto) == VariableDFG
167+ # type instability on `variables` as either `::Vector{Variable}` or `::Vector{VariableCompute{<:}}` (vector of abstract)
168+ variables = @showprogress 1 " loading variables" asyncmap (varFiles) do varFile
169+ jstr = read (" $varFolder /$varFile " , String)
170+ packedvar = JSON3. read (jstr, VariableDFG)
171+ if usePackedVariable
172+ return packedvar
173+ else
174+ return unpackVariable (packedvar)
175+ end
171176 end
172177
173178 @info " Loaded $(length (variables)) variables" # - $(map(v->v.label, variables))"
174179 @info " Inserting variables into graph..."
175180 # Adding variables
176181 map (v -> addVariable! (dfgLoadInto, v), variables)
177182
178- packedfacts = @showprogress 1 " loading factors" asyncmap (factorFiles) do factorFile
183+ usePackedFactor =
184+ isa (dfgLoadInto, GraphsDFG) && getTypeDFGFactors (dfgLoadInto) == FactorDFG
185+
186+ # `factors` is not type stable `::Vector{Factor}` or `::Vector{FactorCompute{<:}}` (vector of abstract)
187+ factors = @showprogress 1 " loading factors" asyncmap (factorFiles) do factorFile
179188 jstr = read (" $factorFolder /$factorFile " , String)
180- return JSON3. read (jstr, PackedFactor)
181- end
182- # FIXME , still creates type instability on `variables` as either `::Factor` or `::DFGFactor{<:}`
183- if isa (dfgLoadInto, GraphsDFG) && getTypeDFGFactors (dfgLoadInto) == PackedFactor
184- factors = packedfacts
185- else
186- factors = unpackFactor .(dfgLoadInto, packedfacts)
189+ packedfact = JSON3. read (jstr, FactorDFG)
190+ if usePackedFactor
191+ return packedfact
192+ else
193+ return unpackFactor (dfgLoadInto, packedfact)
194+ end
187195 end
188196
189197 @info " Loaded $(length (factors)) factors" # - $(map(f->f.label, factors))"
190198 @info " Inserting factors into graph..."
191199 # # Adding factors
192200 map (f -> addFactor! (dfgLoadInto, f), factors)
193201
194- if isa (dfgLoadInto, GraphsDFG) && getTypeDFGFactors (dfgLoadInto) != PackedFactor
202+ if isa (dfgLoadInto, GraphsDFG) && getTypeDFGFactors (dfgLoadInto) != FactorDFG
195203 # Finally, rebuild the CCW's for the factors to completely reinflate them
196- # NOTE CREATES A NEW DFGFactor IF CCW TYPE CHANGES
204+ # NOTE CREATES A NEW FactorCompute IF CCW TYPE CHANGES
197205 @info " Rebuilding CCW's for the factors..."
198206 @showprogress 1 " build factor operational memory" for factor in factors
199207 rebuildFactorMetadata! (dfgLoadInto, factor)
0 commit comments