Skip to content

Commit 29b5c8f

Browse files
committed
update -> merge for Variable and Factor
1 parent 7b98ea2 commit 29b5c8f

File tree

14 files changed

+86
-93
lines changed

14 files changed

+86
-93
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
22

33
# v0.27
44
- `delete` returns number of nodes deleted and no longer the object that was deleted.
5+
- Deprecate `updateVariable!` for `mergeVariable!`, note `merege` returns number of nodes updated/added.
6+
- Deprecate `updateFactor!` for `mergeFactor!`, note `merege` returns number of nodes updated/added.
57

68
# v0.26
79
- Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`.

docs/src/BuildingGraphs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ independently using the functions as discussed in the update section below.
135135

136136
Full variables and factors can be updated using the following functions:
137137

138-
- [`updateVariable!`](@ref)
139-
- [`updateFactor!`](@ref)
138+
- [`mergeVariable!`](@ref)
139+
- [`mergeFactor!`](@ref)
140140

141141

142142
**NOTE**: Skeleton and summary variables are read-only. To perform updates you

src/Deprecated.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33
##=================================================================================
44

55
@deprecate getNeighborhood(args...; kwargs...) listNeighborhood(args...; kwargs...)
6-
@deprecate addBlob!(store::AbstractBlobStore, blobId::UUID, data, ::String) addBlob!(store, blobId, data)
7-
@deprecate addBlob!(store::AbstractBlobStore{T}, data::T, ::String) where {T} addBlob!(store, uuid4(), data)
6+
@deprecate addBlob!(store::AbstractBlobStore, blobId::UUID, data, ::String) addBlob!(
7+
store,
8+
blobId,
9+
data,
10+
)
11+
@deprecate addBlob!(store::AbstractBlobStore, data, ::String) addBlob!(
12+
store,
13+
uuid4(),
14+
data,
15+
)
16+
17+
@deprecate updateVariable!(args...) mergeVariable!(args...)
18+
@deprecate updateFactor!(args...) mergeFactor!(args...)
819

920
## ================================================================================
1021
## Deprecated in v0.25
@@ -69,4 +80,3 @@ DFGSummary(args) = error("DFGSummary is deprecated")
6980
)
7081

7182
@deprecate lsfWho(dfg::AbstractDFG, type::Symbol) lsf(dfg, getfield(Main, type))
72-

src/DistributedFactorGraphs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ export exists,
110110
addFactors!,
111111
getVariable,
112112
getFactor,
113-
updateVariable!,
114-
updateFactor!,
113+
mergeVariable!,
114+
mergeFactor!,
115115
deleteVariable!,
116116
deleteFactor!,
117117
listVariables,
@@ -145,7 +145,7 @@ export getSolvable, setSolvable!, isSolvable
145145
export getVariableLabelNumber
146146

147147
# accessors
148-
export getLabel, getTimestamp, setTimestamp, setTimestamp!, getTags, setTags!
148+
export getLabel, getTimestamp, setTimestamp, getTags, setTags!
149149

150150
export getAgentLabel, getGraphLabel
151151

src/GraphsDFG/GraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import ...DistributedFactorGraphs:
2727
exists,
2828
isVariable,
2929
isFactor,
30-
updateVariable!,
31-
updateFactor!,
30+
mergeVariable!,
31+
mergeFactor!,
3232
deleteVariable!,
3333
deleteFactor!,
3434
getVariables,

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,37 +134,29 @@ function getFactor(dfg::GraphsDFG, label::Symbol)
134134
return dfg.g.factors[label]
135135
end
136136

137-
function updateVariable!(
138-
dfg::GraphsDFG,
139-
variable::AbstractDFGVariable;
140-
warn_if_absent::Bool = true,
141-
)
137+
function mergeVariable!(dfg::GraphsDFG, variable::AbstractDFGVariable)
142138
if !haskey(dfg.g.variables, variable.label)
143-
warn_if_absent &&
144-
@warn "Variable label '$(variable.label)' does not exist in the factor graph, adding"
145-
return addVariable!(dfg, variable)
139+
addVariable!(dfg, variable)
140+
else
141+
dfg.g.variables[variable.label] = variable
146142
end
147-
dfg.g.variables[variable.label] = variable
148-
return variable
143+
return 1
149144
end
150145

151-
function updateFactor!(
152-
dfg::GraphsDFG,
153-
factor::AbstractDFGFactor;
154-
warn_if_absent::Bool = true,
155-
)
146+
function mergeFactor!(dfg::GraphsDFG, factor::AbstractDFGFactor;)
156147
if !haskey(dfg.g.factors, factor.label)
157-
warn_if_absent &&
158-
@warn "Factor label '$(factor.label)' does not exist in the factor graph, adding"
159-
return addFactor!(dfg, factor)
160-
end
161-
162-
# Confirm that we're not updating the neighbors
163-
dfg.g.factors[factor.label]._variableOrderSymbols != factor._variableOrderSymbols &&
148+
addFactor!(dfg, factor)
149+
elseif dfg.g.factors[factor.label]._variableOrderSymbols != factor._variableOrderSymbols
150+
#TODO should we allow merging the factor neighbors or error as before?
164151
error("Cannot update the factor, the neighbors are not the same.")
152+
# We need to delete the factor if we are updating the neighbors
153+
deleteFactor!(dfg, factor.label)
154+
addFactor!(dfg, factor)
155+
else
156+
dfg.g.factors[factor.label] = factor
157+
end
165158

166-
dfg.g.factors[factor.label] = factor
167-
return factor
159+
return 1
168160
end
169161

170162
function deleteVariable!(dfg::GraphsDFG, label::Symbol)#::Tuple{AbstractDFGVariable, Vector{<:AbstractDFGFactor}}

src/services/AbstractDFG.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function updateGraphMetadata!(dfg::AbstractDFG, pair::Pair{Symbol, String})
213213
return push!(dfg.graphMetadata, pair)
214214
end
215215

216-
function deleteAgentMetadata!(dfg::AbstractDFG, key::Symbol)
216+
function deleteAgentMetadata!(dfg::AbstractDFG, key::Symbol)
217217
pop!(dfg.agent.metadata, key)
218218
return 1
219219
end
@@ -392,21 +392,21 @@ end
392392

393393
"""
394394
$(SIGNATURES)
395-
Update a complete VariableCompute in the DFG.
395+
Merge a Variable to the DFG. Overwrites the existing variable if it exists or adds it if it does not.
396396
"""
397-
function updateVariable!(
397+
function mergeVariable!(
398398
dfg::G,
399399
variable::V,
400400
) where {G <: AbstractDFG, V <: AbstractDFGVariable}
401-
return error("updateVariable! not implemented for $(typeof(dfg))")
401+
return error("mergeVariable! not implemented for $(typeof(dfg))")
402402
end
403403

404404
"""
405405
$(SIGNATURES)
406-
Update a complete FactorCompute in the DFG.
406+
Merge a Factor to the DFG. Overwrites the existing factor if it exists or adds it if it does not.
407407
"""
408-
function updateFactor!(dfg::G, factor::F) where {G <: AbstractDFG, F <: AbstractDFGFactor}
409-
return error("updateFactor! not implemented for $(typeof(dfg))")
408+
function mergeFactor!(dfg::G, factor::F) where {G <: AbstractDFG, F <: AbstractDFGFactor}
409+
return error("mergeFactor! not implemented for $(typeof(dfg))")
410410
end
411411

412412
"""
@@ -1097,7 +1097,7 @@ function copyGraph!(
10971097
if !exists(destDFG, variable)
10981098
addVariable!(destDFG, variableCopy)
10991099
elseif overwriteDest
1100-
updateVariable!(destDFG, variableCopy)
1100+
mergeVariable!(destDFG, variableCopy)
11011101
else
11021102
error("Variable $(variable.label) already exists in destination graph!")
11031103
end
@@ -1119,7 +1119,7 @@ function copyGraph!(
11191119
if !exists(destDFG, factor)
11201120
addFactor!(destDFG, factorCopy)
11211121
elseif overwriteDest
1122-
updateFactor!(destDFG, factorCopy)
1122+
mergeFactor!(destDFG, factorCopy)
11231123
else
11241124
error("Factor $(factor.label) already exists in destination graph!")
11251125
end
@@ -1458,7 +1458,7 @@ function mergeVariableData!(dfg::AbstractDFG, sourceVariable::AbstractDFGVariabl
14581458

14591459
#update if its not a InMemoryDFGTypes, otherwise it was a reference
14601460
# if satelite nodes are used it can be updated separately
1461-
# !(isa(dfg, InMemoryDFGTypes)) && updateVariable!(dfg, var)
1461+
# !(isa(dfg, InMemoryDFGTypes)) && mergeVariable!(dfg, var)
14621462

14631463
return var
14641464
end

src/services/CommonAccessors.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,14 @@ getTimestamp(v::DataLevel1) = v.timestamp
5858
5959
Set the timestamp of a Variable/Factor object in a factor graph.
6060
Note:
61-
Since `timestamp` is not mutable `setTimestamp!` calls `updateVariable!` internally.
61+
Since `timestamp` is not mutable `setTimestamp!` calls `mergeVariable!` internally.
6262
See also [`setTimestamp`](@ref)
6363
"""
6464
function setTimestamp!(dfg::AbstractDFG, lbl::Symbol, ts::ZonedDateTime)
6565
if isVariable(dfg, lbl)
66-
return updateVariable!(
67-
dfg,
68-
setTimestamp(getVariable(dfg, lbl), ts; verbose = false),
69-
)
66+
return mergeVariable!(dfg, setTimestamp(getVariable(dfg, lbl), ts; verbose = false))
7067
else
71-
return updateFactor!(dfg, setTimestamp(getFactor(dfg, lbl), ts))
68+
return mergeFactor!(dfg, setTimestamp(getFactor(dfg, lbl), ts))
7269
end
7370
end
7471

src/services/DFGVariable.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ end
365365
Set the timestamp of a VariableCompute object returning a new VariableCompute.
366366
Note:
367367
Since the `timestamp` field is not mutable `setTimestamp` returns a new variable with the updated timestamp (note the absence of `!`).
368-
Use [`updateVariable!`](@ref) on the returened variable to update it in the factor graph if needed. Alternatively use [`setTimestamp!`](@ref).
368+
Use [`mergeVariable!`](@ref) on the returened variable to update it in the factor graph if needed. Alternatively use [`setTimestamp!`](@ref).
369369
See issue #315.
370370
"""
371371
function setTimestamp(v::VariableCompute, ts::ZonedDateTime; verbose::Bool = true)
@@ -541,7 +541,7 @@ function addMetadata!(dfg::AbstractDFG, label::Symbol, pair::Pair{Symbol, <:Smal
541541
v = getVariable(dfg, label)
542542
haskey(v.smallData, pair.first) && error("$(pair.first) already exists.")
543543
push!(v.smallData, pair)
544-
updateVariable!(dfg, v)
544+
mergeVariable!(dfg, v)
545545
return v.smallData #or pair TODO
546546
end
547547

@@ -560,7 +560,7 @@ function updateMetadata!(
560560
!haskey(v.smallData, pair.first) &&
561561
@warn("$(pair.first) does not exist, adding.")
562562
push!(v.smallData, pair)
563-
updateVariable!(dfg, v)
563+
mergeVariable!(dfg, v)
564564
return v.smallData #or pair TODO
565565
end
566566

@@ -571,7 +571,7 @@ Delete a Metadata entry at `key` for variable `label` in `dfg`
571571
function deleteMetadata!(dfg::AbstractDFG, label::Symbol, key::Symbol)
572572
v = getVariable(dfg, label)
573573
pop!(v.smallData, key)
574-
updateVariable!(dfg, v)
574+
mergeVariable!(dfg, v)
575575
return 1
576576
end
577577

@@ -591,7 +591,7 @@ Empty all Metadata from variable `label` in `dfg`
591591
function emptyMetadata!(dfg::AbstractDFG, label::Symbol)
592592
v = getVariable(dfg, label)
593593
empty!(v.smallData)
594-
updateVariable!(dfg, v)
594+
mergeVariable!(dfg, v)
595595
return v.smallData #or pair TODO
596596
end
597597

test/GraphsDFGSummaryTypes.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ end
121121
testTimestamp = now(localzone())
122122
v1ts = setTimestamp(v1, testTimestamp)
123123
@test getTimestamp(v1ts) == testTimestamp
124-
#follow with updateVariable!(fg, v1ts)
125-
# setTimestamp!(v1, testTimestamp) not implemented, we can do an setTimestamp() updateVariable!() for a setTimestamp!(dfg, v1, testTimestamp)
126-
@test_throws MethodError setTimestamp!(v1, testTimestamp)
124+
#follow with mergeVariable!(fg, v1ts)
125+
# setTimestamp!(v1, testTimestamp) not implemented, we can do an setTimestamp() mergeVariable!() for a setTimestamp!(dfg, v1, testTimestamp)
126+
@test_throws MethodError DFG.setTimestamp!(v1, testTimestamp)
127127

128128
f1ts = setTimestamp(f1, testTimestamp)
129129
@test !(f1ts === f1)
130130
@test getTimestamp(f1ts) == testTimestamp
131-
@test_throws MethodError setTimestamp!(v1, testTimestamp)
131+
@test_throws MethodError DFG.setTimestamp!(v1, testTimestamp)
132132
end
133133
end
134134

0 commit comments

Comments
 (0)