Skip to content

Commit 1778ab4

Browse files
authored
Merge pull request #57 from JuliaRobotics/hotfix/isinit
starting migration of IIF low level functions to DFG, and fixes
2 parents 113d2a7 + f8e0d9e commit 1778ab4

File tree

4 files changed

+162
-3
lines changed

4 files changed

+162
-3
lines changed

src/Common.jl

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11

22
export sortVarNested
3+
export isPrior, lsfPriors
4+
export getData
5+
export getVariableType, getSofttype
6+
export getFactorType, getfnctype
7+
export lsTypes, lsfTypes
8+
39

410
"""
511
$(SIGNATURES)
@@ -75,3 +81,152 @@ function sortVarNested(vars::Vector{Symbol})::Vector{Symbol}
7581
end
7682
return retvars
7783
end
84+
85+
"""
86+
$SIGNATURES
87+
88+
Retrieve data structure stored in a node.
89+
"""
90+
getData(v::DFGFactor)::GenericFunctionNodeData = v.data
91+
getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData = v.solverDataDict[solveKey]
92+
93+
"""
94+
$SIGNATURES
95+
96+
Return the factor type used in a `::DFGFactor`.
97+
98+
Notes:
99+
- OBSOLETE, use newer getFactorType instead.
100+
101+
Related
102+
103+
getFactorType
104+
"""
105+
function getfnctype(data::GenericFunctionNodeData)
106+
# TODO what is this?
107+
if typeof(data).name.name == :VariableNodeData
108+
return VariableNodeData
109+
end
110+
111+
# this looks right
112+
return data.fnc.usrfnc!
113+
end
114+
function getfnctype(fact::DFGFactor; solveKey::Symbol=:default)
115+
data = getData(fact) # TODO , solveKey=solveKey)
116+
return getfnctype(data)
117+
end
118+
function getfnctype(dfg::T, lbl::Symbol; solveKey::Symbol=:default) where T <: AbstractDFG
119+
getfnctype(getFactor(dfg, exvertid))
120+
end
121+
122+
"""
123+
$SIGNATURES
124+
125+
Return user factor type from factor graph identified by label `::Symbol`.
126+
127+
Notes
128+
- Replaces older `getfnctype`.
129+
"""
130+
getFactorType(data::GenericFunctionNodeData) = data.fnc.usrfnc!
131+
getFactorType(fct::DFGFactor) = getFactorType(getData(fct))
132+
function getFactorType(dfg::G, lbl::Symbol) where G <: AbstractDFG
133+
getFactorType(getFactor(dfg, lbl))
134+
end
135+
136+
137+
"""
138+
$SIGNATURES
139+
140+
Return `::Bool` on whether given factor `fc::Symbol` is a prior in factor graph `dfg`.
141+
"""
142+
function isPrior(dfg::G, fc::Symbol)::Bool where G <: AbstractDFG
143+
fco = getFactor(dfg, fc)
144+
getfnctype(fco) isa FunctorSingleton
145+
end
146+
147+
"""
148+
$SIGNATURES
149+
150+
Return vector of prior factor symbol labels in factor graph `dfg`.
151+
"""
152+
function lsfPriors(dfg::G)::Vector{Symbol} where G <: AbstractDFG
153+
priors = Symbol[]
154+
fcts = lsf(dfg)
155+
for fc in fcts
156+
if isPrior(dfg, fc)
157+
push!(priors, fc)
158+
end
159+
end
160+
return priors
161+
end
162+
163+
"""
164+
$(SIGNATURES)
165+
166+
Variable nodes softtype information holding a variety of meta data associated with the type of variable stored in that node of the factor graph.
167+
168+
Related
169+
170+
getVariableType
171+
"""
172+
function getSofttype(vnd::VariableNodeData)
173+
return vnd.softtype
174+
end
175+
function getSofttype(v::DFGVariable; solveKey::Symbol=:default)
176+
return getSofttype(getData(v, solveKey=solveKey))
177+
end
178+
179+
"""
180+
$SIGNATURES
181+
182+
Return the DFGVariable softtype in factor graph `dfg<:AbstractDFG` and label `::Symbol`.
183+
"""
184+
getVariableType(var::DFGVariable; solveKey::Symbol=:default) = getSofttype(var, solveKey=solveKey)
185+
function getVariableType(dfg::G, lbl::Symbol; solveKey::Symbol=:default) where G <: AbstractDFG
186+
getVariableType(getVariable(dfg, lbl), solveKey=solveKey)
187+
end
188+
189+
190+
"""
191+
$SIGNATURES
192+
193+
Return `::Dict{Symbol, Vector{String}}` of all unique factor types in factor graph.
194+
"""
195+
function lsfTypes(dfg::G)::Dict{Symbol, Vector{String}} where G <: AbstractDFG
196+
alltypes = Dict{Symbol,Vector{String}}()
197+
for fc in lsf(dfg)
198+
Tt = typeof(getFactorType(dfg, fc))
199+
sTt = string(Tt)
200+
name = Symbol(Tt.name)
201+
if !haskey(alltypes, name)
202+
alltypes[name] = String[string(Tt)]
203+
else
204+
if sum(alltypes[name] .== sTt) == 0
205+
push!(alltypes[name], sTt)
206+
end
207+
end
208+
end
209+
return alltypes
210+
end
211+
212+
"""
213+
$SIGNATURES
214+
215+
Return `::Dict{Symbol, Vector{String}}` of all unique variable types in factor graph.
216+
"""
217+
function lsTypes(dfg::G)::Dict{Symbol, Vector{String}} where G <: AbstractDFG
218+
alltypes = Dict{Symbol,Vector{String}}()
219+
for fc in ls(dfg)
220+
Tt = typeof(getVariableType(dfg, fc))
221+
sTt = string(Tt)
222+
name = Symbol(Tt.name)
223+
if !haskey(alltypes, name)
224+
alltypes[name] = String[string(Tt)]
225+
else
226+
if sum(alltypes[name] .== sTt) == 0
227+
push!(alltypes[name], sTt)
228+
end
229+
end
230+
end
231+
return alltypes
232+
end

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export DFGNode
2020
export DFGFactor
2121
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
2222

23+
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
24+
2325
export DFGVariable
2426
export label, timestamp, tags, estimates, estimate, solverData, solverDataDict, id, smallData, bigData
2527
export setSolverData

src/NeedsAHome.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ function isInitialized(fct::DFGFactor; key::Symbol=:default)::Bool
3636
return fct.solverDataDict[key].initialized
3737
end
3838
function isInitialized(dfg::G, label::Symbol; key::Symbol=:default)::Bool where G <: AbstractDFG
39-
# nothing to do for factors
40-
# return dfg.g.vertices[dfg.labelDict[label]].dfgNode.solverDataDict[key].initialized
41-
return true
39+
return isInitialized(getVariable(dfg, label), key=key)
4240
end

src/entities/DFGFactor.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ abstract type FunctorInferenceType <: Function end
99
abstract type InferenceVariable end
1010
abstract type ConvolutionObject <: Function end
1111

12+
abstract type FunctorSingleton <: FunctorInferenceType end
13+
abstract type FunctorPairwise <: FunctorInferenceType end
14+
abstract type FunctorPairwiseMinimize <: FunctorInferenceType end
15+
1216
"""
1317
$(TYPEDEF)
1418
"""

0 commit comments

Comments
 (0)