Skip to content

Commit 078f57c

Browse files
committed
Added test and lots of small fixes.
- Copied interface tests to test common funcionallity between summary and normal variables and factors
1 parent 2d6c327 commit 078f57c

File tree

5 files changed

+326
-15
lines changed

5 files changed

+326
-15
lines changed

src/LightDFG/entities/LightDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ An in-memory DistributedFactorGraph based on LightGraphs.jl with parameters:
77
- V: Variable type
88
- F: Factor type
99
"""
10-
mutable struct LightDFG{T <: AbstractParams, V <: DFGNode, F <:DFGNode} <: AbstractDFG
10+
mutable struct LightDFG{T <: AbstractParams, V <: AbstractDFGVariable, F <:AbstractDFGFactor} <: AbstractDFG
1111
g::FactorGraph{Int, V, F}
1212
description::String
1313
userId::String
@@ -30,7 +30,7 @@ function LightDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
3030
userId::String="User ID",
3131
robotId::String="Robot ID",
3232
sessionId::String="Session ID",
33-
params::T=NoSolverParams()) where {T <: AbstractParams, V <:DFGNode, F<:DFGNode}
33+
params::T=NoSolverParams()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
3434

3535
LightDFG{T,V,F}(g, description, userId, robotId, sessionId, Symbol[], params)
3636
end

src/LightDFG/services/LightDFG.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ end
1717
$(SIGNATURES)
1818
True if the variable or factor exists in the graph.
1919
"""
20-
function exists(dfg::LightDFG{P,V,F}, node::V) where {P <:AbstractParams, V <: DFGNode, F <: DFGNode, N <: DFGNode}
20+
function exists(dfg::LightDFG{P,V,F}, node::V) where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
2121
return haskey(dfg.g.variables, node.label)
2222
end
2323

24-
function exists(dfg::LightDFG{P,V,F}, node::F) where {P <:AbstractParams, V <: DFGNode, F <: DFGNode, N <: DFGNode}
24+
function exists(dfg::LightDFG{P,V,F}, node::F) where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
2525
return haskey(dfg.g.factors, node.label)
2626
end
2727

@@ -279,7 +279,7 @@ function getNeighbors(dfg::LightDFG, node::DFGNode; ready::Union{Nothing, Int}=n
279279
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
280280

281281
# Variable sorting (order is important)
282-
if node isa DFGFactor
282+
if typeof(node) <: AbstractDFGFactor
283283
order = intersect(node._variableOrderSymbols, neighbors_ll)#map(v->v.dfgNode.label, neighbors))
284284
return order
285285
end
@@ -292,7 +292,7 @@ end
292292
$(SIGNATURES)
293293
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
294294
"""
295-
function getNeighbors(dfg::LightDFG, label::Symbol; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
295+
function getNeighbors(dfg::LightDFG, label::Symbol; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
296296
if !exists(dfg, label)
297297
error("Variable/factor with label '$(label)' does not exist in the factor graph")
298298
end
@@ -313,9 +313,7 @@ function getNeighbors(dfg::LightDFG, label::Symbol; ready::Union{Nothing, Int}=n
313313

314314
end
315315

316-
# Aliases
317-
318-
function _copyIntoGraph!(sourceDFG::LightDFG, destDFG::LightDFG, ns::Vector{Int}, includeOrphanFactors::Bool=false)::Nothing
316+
function _copyIntoGraph!(sourceDFG::LightDFG{<:AbstractParams, V, F}, destDFG::LightDFG{<:AbstractParams, V, F}, ns::Vector{Int}, includeOrphanFactors::Bool=false)::Nothing where {V <: AbstractDFGVariable, F <: AbstractDFGFactor}
319317
#kan ek die in bulk copy, soos graph en dan nuwe map maak
320318
# Add all variables first,
321319
labels = [sourceDFG.g.labels[i] for i in ns]
@@ -334,7 +332,7 @@ function _copyIntoGraph!(sourceDFG::LightDFG, destDFG::LightDFG, ns::Vector{Int}
334332

335333
neigh_labels = [sourceDFG.g.labels[i] for i in neigh_ints]
336334
# Find the labels and associated variables in our new subgraph
337-
factVariables = DFGVariable[]
335+
factVariables = V[]
338336
for v_lab in neigh_labels
339337
if haskey(destDFG.g.variables, v_lab)
340338
push!(factVariables, getVariable(destDFG, v_lab))
@@ -359,7 +357,7 @@ Optionally provide a distance to specify the number of edges should be followed.
359357
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
360358
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
361359
"""
362-
function getSubgraphAroundNode(dfg::LightDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{AbstractParams}())::LightDFG
360+
function getSubgraphAroundNode(dfg::LightDFG{P,V,F}, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}())::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
363361
if !exists(dfg,node.label)
364362
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
365363
end
@@ -372,17 +370,18 @@ function getSubgraphAroundNode(dfg::LightDFG, node::DFGNode, distance::Int64=1,
372370
return addToDFG
373371

374372
end
375-
373+
# dfg::LightDFG{P,V,F}
374+
# where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
376375

377376
"""
378377
$(SIGNATURES)
379378
Get a deep subgraph copy from the DFG given a list of variables and factors.
380379
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
381380
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
382381
"""
383-
function getSubgraph(dfg::LightDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{AbstractParams}())::LightDFG
384-
for label in variableFactorLabels
385-
if !exists(dfg, label)
382+
function getSubgraph(dfg::LightDFG{P,V,F}, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}())::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
383+
for label in variableFactorLabels
384+
if !exists(dfg, label)
386385
error("Variable/factor with label '$(label)' does not exist in the factor graph")
387386
end
388387
end

src/entities/DFGVariable.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@ label(v::DFGVariableSummary) = v.label
146146
timestamp(v::DFGVariableSummary) = v.timestamp
147147
tags(v::DFGVariableSummary) = v.tags
148148
estimates(v::DFGVariableSummary) = v.estimateDict
149+
estimate(v::DFGVariableSummary, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
149150
internalId(v::DFGVariableSummary) = v._internalId

0 commit comments

Comments
 (0)