Skip to content

Commit 51799f3

Browse files
authored
Merge pull request #832 from JuliaRobotics/22Q4/refacc/unpackFactor
switch to reconstFactorData
2 parents 9c58dc1 + af5c5f0 commit 51799f3

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ export mergeVariableData!, mergeGraphVariableData!
218218
# Serialization type conversion
219219
export convertPackedType, convertStructType
220220

221+
export reconstFactorData
222+
221223
##------------------------------------------------------------------------------
222224
## Other utility functions
223225
##------------------------------------------------------------------------------

src/services/Serialization.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,22 @@ function packFactor(dfg::AbstractDFG, f::DFGFactor)
332332
return props
333333
end
334334

335-
function decodePackedType(::Type{T}, packeddata::GenericFunctionNodeData{PT}) where {T<:FactorOperationalMemory, PT}
336-
# usrtyp = convert(FunctorInferenceType, packeddata.fnc)
335+
function reconstFactorData() end
336+
337+
function decodePackedType(dfg::AbstractDFG, varOrder::AbstractVector{Symbol}, ::Type{T}, packeddata::GenericFunctionNodeData{PT}) where {T<:FactorOperationalMemory, PT}
338+
#
339+
# TODO, to solve IIF 1424
340+
# variables = map(lb->getVariable(dfg, lb), varOrder)
341+
337342
# Also look at parentmodule
338343
usrtyp = convertStructType(PT)
339344
fulltype = DFG.FunctionNodeData{T{usrtyp}}
340-
factordata = convert(fulltype, packeddata)
345+
factordata = reconstFactorData(dfg, varOrder, fulltype, packeddata)
341346
return factordata
342347
end
343348

344-
345-
function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G <: AbstractDFG
349+
# Returns `::DFGFactor`
350+
function unpackFactor(dfg::G, packedProps::Dict{String, Any}) where G <: AbstractDFG
346351
# Version checking.
347352
_versionCheck(packedProps)
348353

@@ -369,10 +374,18 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G
369374
# FIXME type instability from nothing to T
370375
packed = nothing
371376
fullFactorData = nothing
377+
378+
# Get the stored variable order
379+
_variableOrderSymbols = if packedProps["_variableOrderSymbols"] isa String
380+
JSON2.read(packedProps["_variableOrderSymbols"], Vector{Symbol})
381+
else
382+
Symbol.(packedProps["_variableOrderSymbols"])
383+
end
384+
372385
try
373386
packed = JSON2.read(data, GenericFunctionNodeData{packtype})
374387
decodeType = getFactorOperationalMemoryType(dfg)
375-
fullFactorData = decodePackedType(decodeType, packed)
388+
fullFactorData = decodePackedType(dfg, _variableOrderSymbols, decodeType, packed)
376389
catch ex
377390
io = IOBuffer()
378391
showerror(io, ex, catch_backtrace())
@@ -381,12 +394,6 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G
381394
error(msg)
382395
end
383396

384-
# Include the type
385-
if packedProps["_variableOrderSymbols"] isa String
386-
_variableOrderSymbols = JSON2.read(packedProps["_variableOrderSymbols"], Vector{Symbol})
387-
else
388-
_variableOrderSymbols = Symbol.(packedProps["_variableOrderSymbols"])
389-
end
390397
solvable = packedProps["solvable"]
391398

392399
# Rebuild DFGFactor

test/testBlocks.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Dates
44
using Manifolds
55

66
import Base: convert
7+
import DistributedFactorGraphs: reconstFactorData
78

89
# Test InferenceVariable Types
910
# struct TestVariableType1 <: InferenceVariable
@@ -43,11 +44,17 @@ function Base.convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInf
4344
PackedTestFunctorInferenceType1()
4445
end
4546

46-
function Base.convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)
47+
function reconstFactorData(dfg::AbstractDFG, vo::AbstractVector, ::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1, ::String)
48+
TestFunctorInferenceType1()
49+
end
50+
51+
# overly simplified test requires both reconstitute and convert
52+
function Base.convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1 )
4753
# @info "convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)"
4854
TestFunctorInferenceType1()
4955
end
5056

57+
5158
struct PackedTestAbstractPrior <: PackedInferenceType
5259
s::String
5360
end
@@ -74,13 +81,15 @@ Base.:(==)(a::TestCCW, b::TestCCW) = a.usrfnc! == b.usrfnc!
7481
DFG.getFactorOperationalMemoryType(par::NoSolverParams) = TestCCW
7582
DFG.rebuildFactorMetadata!(dfg::AbstractDFG{NoSolverParams}, fac::DFGFactor) = fac
7683

77-
function Base.convert(::Type{DFG.FunctionNodeData{TestCCW{F}}},
78-
d::DFG.PackedFunctionNodeData{<:AbstractPackedFactor}) where {F <: DFG.AbstractFactor}
79-
84+
function reconstFactorData(dfg::AbstractDFG,
85+
vo::AbstractVector,
86+
::Type{<:DFG.FunctionNodeData{TestCCW{F}}},
87+
d::DFG.PackedFunctionNodeData{<:AbstractPackedFactor} ) where {F <: DFG.AbstractFactor}
88+
nF = convert(F, d.fnc)
8089
return DFG.FunctionNodeData(d.eliminated,
8190
d.potentialused,
8291
d.edgeIDs,
83-
TestCCW(convert(F, d.fnc)),
92+
TestCCW(nF),
8493
d.multihypo,
8594
d.certainhypo,
8695
d.nullhypo,

0 commit comments

Comments
 (0)