Skip to content

Commit 93314c7

Browse files
committed
dehann's request: verbose on orphan warn
1 parent c9edb00 commit 93314c7

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/services/AbstractDFG.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,13 @@ function getSubgraph(dfg::G,
848848
return addToDFG
849849
end
850850

851-
851+
"""
852+
$(SIGNATURES)
853+
Build a deep subgraph copy from the DFG given a list of variables and factors and an optional distance.
854+
Note: Orphaned factors (where the subgraph does not contain all the related variables) are not returned.
855+
Dev Notes
856+
- Bulk vs node for node: a list of labels are compiled and the sugraph is copied in bulk.
857+
"""
852858
function buildSubgraph(::Type{G}, dfg::AbstractDFG, variableFactorLabels::Vector{Symbol}, distance::Int=0; solvable::Int=0, kwargs...) where G <: AbstractDFG
853859

854860
# find neighbors at distance to add

src/services/copyFunctions.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ Orphaned factors are not added.
66
Set `overwriteDest` to overwrite existing variables and factors in the destination DFG.
77
NOTE: copyGraphMetadata not supported yet.
88
"""
9-
function copyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG, variableFactorLabels::Vector{Symbol}; copyGraphMetadata::Bool=false, overwriteDest::Bool=false, deepcopyNodes::Bool=false)
9+
function copyGraph!(destDFG::AbstractDFG,
10+
sourceDFG::AbstractDFG,
11+
variableFactorLabels::Vector{Symbol};
12+
copyGraphMetadata::Bool=false,
13+
overwriteDest::Bool=false,
14+
deepcopyNodes::Bool=false,
15+
verbose::Bool = true)
1016
# Split into variables and factors
1117
sourceVariables = map(vId->getVariable(sourceDFG, vId), intersect(listVariables(sourceDFG), variableFactorLabels))
1218
sourceFactors = map(fId->getFactor(sourceDFG, fId), intersect(listFactors(sourceDFG), variableFactorLabels))
1319
if length(sourceVariables) + length(sourceFactors) != length(variableFactorLabels)
14-
rem = symdiff(map(v->v.label, sourceVariables), variableFactorLabels)
15-
rem = symdiff(map(f->f.label, sourceFactors), variableFactorLabels)
16-
error("Cannot copy because cannot find the following nodes in the source graph: $rem")
20+
remv = setdiff(map(v->v.label, sourceVariables), variableFactorLabels)
21+
remf = setdiff(map(f->f.label, sourceFactors), variableFactorLabels)
22+
error("Cannot copy because cannot find the following nodes in the source graph: $remv, $remf")
1723
end
1824

1925
# Now we have to add all variables first,
@@ -48,7 +54,7 @@ function copyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG, variableFactor
4854
else
4955
error("Factor $(factor.label) already exists in destination graph!")
5056
end
51-
else
57+
elseif verbose
5258
@warn "Factor $(factor.label) will be an orphan in the destination graph, and therefore not added."
5359
end
5460
end
@@ -61,6 +67,7 @@ function copyGraph!(destDFG::AbstractDFG, sourceDFG::AbstractDFG, variableFactor
6167
return nothing
6268
end
6369

70+
6471
function deepcopyGraph!(destDFG::AbstractDFG,
6572
sourceDFG::AbstractDFG,
6673
variableFactorLabels::Vector{Symbol} = union(ls(sourceDFG), lsf(sourceDFG));

0 commit comments

Comments
 (0)