Skip to content

Commit f8e0d9e

Browse files
committed
ls Types
1 parent 7add0af commit f8e0d9e

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/Common.jl

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export isPrior, lsfPriors
44
export getData
55
export getVariableType, getSofttype
66
export getFactorType, getfnctype
7+
export lsTypes, lsfTypes
78

89

910
"""
@@ -180,7 +181,52 @@ end
180181
181182
Return the DFGVariable softtype in factor graph `dfg<:AbstractDFG` and label `::Symbol`.
182183
"""
183-
getVariableType(var::DFGVariable; solveKey::Symbol=:default) = getSofttype(var, solvekey=solveKey)
184+
getVariableType(var::DFGVariable; solveKey::Symbol=:default) = getSofttype(var, solveKey=solveKey)
184185
function getVariableType(dfg::G, lbl::Symbol; solveKey::Symbol=:default) where G <: AbstractDFG
185186
getVariableType(getVariable(dfg, lbl), solveKey=solveKey)
186187
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

0 commit comments

Comments
 (0)