Skip to content

Commit f13cbaf

Browse files
committed
general improvements
1 parent 4bd25b1 commit f13cbaf

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/services/DFGVariable.jl

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,23 @@ getLastUpdatedTimestamp(est::AbstractPointParametricEst) = est.lastUpdatedTimest
3838
3939
Variable nodes `variableType` information holding a variety of meta data associated with the type of variable stored in that node of the factor graph.
4040
41+
DevWork
42+
- TODO, see IncrementalInference.jl 1228
43+
4144
Related
4245
4346
getVariableType
4447
"""
48+
getVariableType(v::DFGVariable{T}) where T <: InferenceVariable = T()
49+
4550
function getVariableType(vnd::VariableNodeData)
51+
# @warn "getVariableType(::VariableNodeData) is being deprecated, use getVariableType(::DFGVariable) instead."
4652
return vnd.variableType
4753
end
4854

4955

5056
# TODO: Confirm that we can switch this out, instead of retrieving the complete variable.
51-
# getVariableType(v::DFGVariable{T}) where T <: InferenceVariable = T()
52-
getVariableType(v::DFGVariable) = getVariableType(getSolverData(v))
57+
# getVariableType(v::DFGVariable) = getVariableType(getSolverData(v))
5358

5459
# Optimized in CGDFG
5560
getVariableType(dfg::AbstractDFG, lbl::Symbol) = getVariableType(getVariable(dfg,lbl))
@@ -326,7 +331,10 @@ end
326331
$SIGNATURES
327332
Set solver data structure stored in a variable.
328333
"""
329-
setSolverData!(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = v.solverDataDict[key] = data
334+
function setSolverData!(v::DFGVariable, data::VariableNodeData, key::Symbol=:default)
335+
@assert key == data.solveKey "VariableNodeData.solveKey=:$(data.solveKey) does not match requested :$(key)"
336+
v.solverDataDict[key] = data
337+
end
330338

331339
##------------------------------------------------------------------------------
332340
## smallData
@@ -520,7 +528,9 @@ function updateVariableSolverData!(dfg::AbstractDFG,
520528
# for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update.
521529
usevnd = useCopy ? deepcopy(vnd) : vnd
522530
# should just one, or many pointers be updated?
523-
if haskey(var.solverDataDict, vnd.solveKey) && isa(var.solverDataDict[vnd.solveKey], VariableNodeData) && length(fields) != 0
531+
useExisting = haskey(var.solverDataDict, vnd.solveKey) && isa(var.solverDataDict[vnd.solveKey], VariableNodeData) && length(fields) != 0
532+
# @error useExisting vnd.solveKey
533+
if useExisting
524534
# change multiple pointers inside the VND var.solverDataDict[solvekey]
525535
for field in fields
526536
destField = getfield(var.solverDataDict[vnd.solveKey], field)
@@ -561,13 +571,20 @@ function updateVariableSolverData!(dfg::AbstractDFG,
561571
end
562572

563573

564-
updateVariableSolverData!(dfg::AbstractDFG,
565-
sourceVariable::DFGVariable,
566-
solveKey::Symbol=:default,
567-
useCopy::Bool=true,
568-
fields::Vector{Symbol}=Symbol[];
569-
warn_if_absent::Bool=true ) =
570-
updateVariableSolverData!(dfg, sourceVariable.label, getSolverData(sourceVariable, solveKey), useCopy, fields; warn_if_absent=warn_if_absent)
574+
function updateVariableSolverData!( dfg::AbstractDFG,
575+
sourceVariable::DFGVariable,
576+
solveKey::Symbol=:default,
577+
useCopy::Bool=true,
578+
fields::Vector{Symbol}=Symbol[];
579+
warn_if_absent::Bool=true )
580+
#
581+
vnd = getSolverData(sourceVariable, solveKey)
582+
# toshow = listSolveKeys(sourceVariable) |> collect
583+
# @info "update DFGVar solveKey" solveKey vnd.solveKey
584+
# @show toshow
585+
@assert solveKey == vnd.solveKey "VariableNodeData's solveKey=:$(vnd.solveKey) does not match requested :$solveKey"
586+
updateVariableSolverData!(dfg, sourceVariable.label, vnd, useCopy, fields; warn_if_absent=warn_if_absent)
587+
end
571588

572589
function updateVariableSolverData!(dfg::AbstractDFG,
573590
sourceVariables::Vector{<:DFGVariable},
@@ -674,13 +691,13 @@ function getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default)
674691
end
675692

676693
# Not the most efficient call but it at least reuses above (in memory it's probably ok)
677-
getPPE(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=default)::AbstractPointParametricEst = getPPE(dfg, sourceVariable.label, ppekey)
694+
getPPE(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=:default) = getPPE(dfg, sourceVariable.label, ppekey)
678695

679696
"""
680697
$(SIGNATURES)
681698
Add variable PPE, errors if it already exists.
682699
"""
683-
function addPPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::P)::AbstractPointParametricEst where {P <: AbstractPointParametricEst}
700+
function addPPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::P) where {P <: AbstractPointParametricEst}
684701
var = getVariable(dfg, variablekey)
685702
if haskey(var.ppeDict, ppe.solveKey)
686703
error("PPE '$(ppe.solveKey)' already exists")

0 commit comments

Comments
 (0)