Skip to content

Commit a1981f6

Browse files
committed
update -> merge for Blobentry and State
1 parent 3408423 commit a1981f6

File tree

11 files changed

+185
-184
lines changed

11 files changed

+185
-184
lines changed

docs/src/GraphData.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Labels are the principle identifier of a variable or factor.
4747
Each variable or factor can have a timestamp associated with it.
4848

4949
- [`getTimestamp`](@ref)
50-
- [`setTimestamp!`](@ref)
5150

5251

5352
#### Tags
@@ -129,7 +128,7 @@ Related functions:
129128
- [`listVariableSolverData`](@ref)
130129
- [`getVariableSolverData`](@ref)
131130
- [`addVariableSolverData!`](@ref)
132-
- [`updateVariableSolverData!`](@ref)
131+
- [`mergeVariableState!`](@ref)
133132
- [`deleteVariableSolverData!`](@ref)
134133
- [`mergeVariableSolverData!`](@ref)
135134

src/DataBlobs/services/BlobEntry.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,21 @@ end
181181

182182
"""
183183
$(SIGNATURES)
184-
Update data entry
185-
186-
DevNote
187-
- DF, unclear if `update` verb is applicable in this case, see #404
184+
Update a Blobentry in the factor graph.
185+
If the Blobentry does not exist, it will be added.
186+
Notes:
188187
"""
189-
function updateBlobEntry!(var::AbstractDFGVariable, bde::BlobEntry)
190-
!haskey(var.dataDict, bde.label) &&
191-
(@warn "$(bde.label) does not exist in variable $(getLabel(var)), adding")
192-
var.dataDict[bde.label] = bde
193-
return bde
188+
function mergeBlobentry!(var::AbstractDFGVariable, bde::BlobEntry)
189+
if !haskey(var.dataDict, bde.label)
190+
addBlobEntry!(var, bde)
191+
else
192+
var.dataDict[bde.label] = bde
193+
end
194+
return 1
194195
end
195-
function updateBlobEntry!(dfg::AbstractDFG, label::Symbol, bde::BlobEntry)
196+
function mergeBlobentry!(dfg::AbstractDFG, label::Symbol, bde::BlobEntry)
196197
# !isVariable(dfg, label) && return nothing
197-
return updateBlobEntry!(getVariable(dfg, label), bde)
198+
return mergeBlobentry!(getVariable(dfg, label), bde)
198199
end
199200

200201
"""

src/DataBlobs/services/BlobStores.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function addBlob! end
2525
"""
2626
Update a blob to the blob store or dfg with the given entry.
2727
Related
28-
[`updateBlobEntry!`](@ref)
28+
[`mergeBlobentry!`](@ref)
2929
3030
$(METHODLIST)
3131

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function addData! end
2525
"""
2626
Update a blob entry or blob to the blob store or dfg.
2727
Related
28-
[`updateBlobEntry!`](@ref)
28+
[`mergeBlobentry!`](@ref)
2929
3030
$(METHODLIST)
3131
"""
@@ -247,9 +247,9 @@ function updateData!(
247247
)
248248
checkhash && assertHash(entry, blob; hashfunction)
249249
# order of ops with unknown new blobId not tested
250-
de = updateBlobEntry!(dfg, label, entry)
250+
mergeBlobentry!(dfg, label, entry)
251251
db = updateBlob!(dfg, de, blob)
252-
return de => db
252+
return 2
253253
end
254254

255255
function updateData!(
@@ -269,10 +269,9 @@ function updateData!(
269269
origin = buildSourceString(dfg, label),
270270
_version = string(_getDFGVersion()),
271271
)
272-
273-
de = updateBlobEntry!(dfg, label, newEntry)
274-
db = updateBlob!(blobstore, de, blob)
275-
return de => db
272+
mergeBlobentry!(dfg, label, newEntry)
273+
updateBlob!(blobstore, newEntry, blob)
274+
return 2
276275
end
277276

278277
function deleteData!(dfg::AbstractDFG, vLbl::Symbol, bLbl::Symbol)

src/Deprecated.jl

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,138 @@
1717
@deprecate updateVariable!(args...) mergeVariable!(args...)
1818
@deprecate updateFactor!(args...) mergeFactor!(args...)
1919

20+
@deprecate updateBlobEntry!(args...) mergeBlobentry!(args...)
21+
@deprecate updateGraphBlobEntry!(args...) mergeGraphBlobentry!(args...)
22+
@deprecate updateAgentBlobEntry!(args...) mergeAgentBlobentry!(args...)
23+
24+
export updateVariableSolverData!
25+
26+
#TODO possibly completely deprecated or not exported until update verb is standardized
27+
function updateVariableSolverData!(
28+
dfg::AbstractDFG,
29+
variablekey::Symbol,
30+
vnd::VariableNodeData,
31+
useCopy::Bool = false,
32+
fields::Vector{Symbol} = Symbol[];
33+
warn_if_absent::Bool = true,
34+
)
35+
#This is basically just setSolverData
36+
var = getVariable(dfg, variablekey)
37+
warn_if_absent &&
38+
!haskey(var.solverDataDict, vnd.solveKey) &&
39+
@warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding"
40+
41+
# for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update.
42+
usevnd = vnd # useCopy ? deepcopy(vnd) : vnd
43+
# should just one, or many pointers be updated?
44+
useExisting =
45+
haskey(var.solverDataDict, vnd.solveKey) &&
46+
isa(var.solverDataDict[vnd.solveKey], VariableNodeData) &&
47+
length(fields) != 0
48+
# @error useExisting vnd.solveKey
49+
if useExisting
50+
# change multiple pointers inside the VND var.solverDataDict[solvekey]
51+
for field in fields
52+
destField = getfield(var.solverDataDict[vnd.solveKey], field)
53+
srcField = getfield(usevnd, field)
54+
if isa(destField, Array) && size(destField) == size(srcField)
55+
# use broadcast (in-place operation)
56+
destField .= srcField
57+
else
58+
# change pointer of destination VND object member
59+
setfield!(var.solverDataDict[vnd.solveKey], field, srcField)
60+
end
61+
end
62+
else
63+
# change a single pointer in var.solverDataDict
64+
var.solverDataDict[vnd.solveKey] = usevnd
65+
end
66+
67+
return var.solverDataDict[vnd.solveKey]
68+
end
69+
70+
function updateVariableSolverData!(
71+
dfg::AbstractDFG,
72+
variablekey::Symbol,
73+
vnd::VariableNodeData,
74+
solveKey::Symbol,
75+
useCopy::Bool = false,
76+
fields::Vector{Symbol} = Symbol[];
77+
warn_if_absent::Bool = true,
78+
)
79+
# TODO not very clean
80+
if vnd.solveKey != solveKey
81+
@warn(
82+
"updateVariableSolverData with solveKey parameter might change in the future, see DFG #565. Future warnings are suppressed",
83+
maxlog = 1
84+
)
85+
usevnd = useCopy ? deepcopy(vnd) : vnd
86+
usevnd.solveKey = solveKey
87+
return updateVariableSolverData!(
88+
dfg,
89+
variablekey,
90+
usevnd,
91+
useCopy,
92+
fields;
93+
warn_if_absent = warn_if_absent,
94+
)
95+
else
96+
return updateVariableSolverData!(
97+
dfg,
98+
variablekey,
99+
vnd,
100+
useCopy,
101+
fields;
102+
warn_if_absent = warn_if_absent,
103+
)
104+
end
105+
end
106+
107+
function updateVariableSolverData!(
108+
dfg::AbstractDFG,
109+
sourceVariable::VariableCompute,
110+
solveKey::Symbol = :default,
111+
useCopy::Bool = false,
112+
fields::Vector{Symbol} = Symbol[];
113+
warn_if_absent::Bool = true,
114+
)
115+
#
116+
vnd = getSolverData(sourceVariable, solveKey)
117+
# toshow = listSolveKeys(sourceVariable) |> collect
118+
# @info "update DFGVar solveKey" solveKey vnd.solveKey
119+
# @show toshow
120+
@assert solveKey == vnd.solveKey "VariableNodeData's solveKey=:$(vnd.solveKey) does not match requested :$solveKey"
121+
return updateVariableSolverData!(
122+
dfg,
123+
sourceVariable.label,
124+
vnd,
125+
useCopy,
126+
fields;
127+
warn_if_absent = warn_if_absent,
128+
)
129+
end
130+
131+
function updateVariableSolverData!(
132+
dfg::AbstractDFG,
133+
sourceVariables::Vector{<:VariableCompute},
134+
solveKey::Symbol = :default,
135+
useCopy::Bool = false,
136+
fields::Vector{Symbol} = Symbol[];
137+
warn_if_absent::Bool = true,
138+
)
139+
#I think cloud would do this in bulk for speed
140+
for var in sourceVariables
141+
updateVariableSolverData!(
142+
dfg,
143+
var.label,
144+
getSolverData(var, solveKey),
145+
useCopy,
146+
fields;
147+
warn_if_absent = warn_if_absent,
148+
)
149+
end
150+
end
151+
20152
## ================================================================================
21153
## Deprecated in v0.25
22154
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ export getGraphBlobEntry,
7979
getGraphBlobEntries,
8080
addGraphBlobEntry!,
8181
addGraphBlobEntries!,
82-
updateGraphBlobEntry!,
82+
mergeGraphBlobentry!,
8383
deleteGraphBlobEntry!,
8484
getAgentBlobEntry,
8585
getAgentBlobEntries,
8686
addAgentBlobEntry!,
8787
addAgentBlobEntries!,
88-
updateAgentBlobEntry!,
88+
mergeAgentBlobentry!,
8989
deleteAgentBlobEntry!,
9090
listGraphBlobEntries,
9191
listAgentBlobEntries
@@ -186,7 +186,7 @@ export getMetadata,
186186
# CRUD & SET
187187
export getVariableSolverData,
188188
addVariableSolverData!,
189-
updateVariableSolverData!,
189+
mergeVariableState!,
190190
deleteVariableSolverData!,
191191
listVariableSolverData,
192192
mergeVariableSolverData!,
@@ -228,7 +228,7 @@ export hasBlobEntry,
228228
getBlobEntryFirst,
229229
addBlobEntry!,
230230
addBlobEntries!,
231-
updateBlobEntry!,
231+
mergeBlobentry!,
232232
deleteBlobEntry!,
233233
listBlobEntrySequence,
234234
mergeBlobEntries!

src/entities/DFGVariable.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ Base.@kwdef struct VariableCompute{T <: InferenceVariable, P, N} <: AbstractDFGV
303303
Accessors: [`addPPE!`](@ref), [`updatePPE!`](@ref), and [`deletePPE!`](@ref)"""
304304
ppeDict::Dict{Symbol, AbstractPointParametricEst} =
305305
Dict{Symbol, AbstractPointParametricEst}()
306-
"""Dictionary of solver data. May be a subset of all solutions if a solver key was specified in the get call.
307-
Accessors: [`addVariableSolverData!`](@ref), [`updateVariableSolverData!`](@ref), and [`deleteVariableSolverData!`](@ref)"""
306+
"""Dictionary of solver data. May be a subset of all solutions if a solver label was specified in the get call.
307+
Accessors: [`addVariableSolverData!`](@ref), [`mergeVariableState!`](@ref), and [`deleteVariableSolverData!`](@ref)"""
308308
solverDataDict::Dict{Symbol, VariableNodeData{T, P, N}} =
309309
Dict{Symbol, VariableNodeData{T, P, N}}()
310310
"""Dictionary of small data associated with this variable.
311311
Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)"""
312312
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
313313
"""Dictionary of large data associated with this variable.
314-
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`updateBlobEntry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
314+
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`mergeBlobentry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
315315
dataDict::Dict{Symbol, BlobEntry} = Dict{Symbol, BlobEntry}()
316316
"""Solvable flag for the variable.
317317
Accessors: [`getSolvable`](@ref), [`setSolvable!`](@ref)"""
@@ -405,7 +405,7 @@ Base.@kwdef struct VariableSummary <: AbstractDFGVariable
405405
Accessor: [`getVariableType`](@ref)"""
406406
variableTypeName::Symbol
407407
"""Dictionary of large data associated with this variable.
408-
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`updateBlobEntry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
408+
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`mergeBlobentry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
409409
dataDict::Dict{Symbol, BlobEntry}
410410
end
411411

src/services/AbstractDFG.jl

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ function getGraphBlobEntry end
236236
function getGraphBlobEntries end
237237
function addGraphBlobEntry! end
238238
function addGraphBlobEntries! end
239-
function updateGraphBlobEntry! end
239+
function mergeGraphBlobentry! end
240240
function deleteGraphBlobEntry! end
241241

242242
function getAgentBlobEntry end
243243
function getAgentBlobEntries end
244244
function addAgentBlobEntry! end
245245
function addAgentBlobEntries! end
246-
function updateAgentBlobEntry! end
246+
function mergeAgentBlobentry! end
247247
function deleteAgentBlobEntry! end
248248

249249
function getModelBlobEntry end
@@ -392,20 +392,19 @@ end
392392

393393
"""
394394
$(SIGNATURES)
395-
Merge a Variable to the DFG. Overwrites the existing variable if it exists or adds it if it does not.
395+
Merge a variable into the DFG. If a variable with the same label exists, it will be overwritten;
396+
otherwise, the variable will be added to the graph.
396397
"""
397-
function mergeVariable!(
398-
dfg::G,
399-
variable::V,
400-
) where {G <: AbstractDFG, V <: AbstractDFGVariable}
398+
function mergeVariable!(dfg::AbstractDFG, variable::AbstractDFGVariable)
401399
return error("mergeVariable! not implemented for $(typeof(dfg))")
402400
end
403401

404402
"""
405403
$(SIGNATURES)
406-
Merge a Factor to the DFG. Overwrites the existing factor if it exists or adds it if it does not.
404+
Merge a factor into the DFG. If a factor with the same label exists, it will be overwritten;
405+
otherwise, the factor will be added to the graph.
407406
"""
408-
function mergeFactor!(dfg::G, factor::F) where {G <: AbstractDFG, F <: AbstractDFGFactor}
407+
function mergeFactor!(dfg::AbstractDFG, factor::AbstractDFGFactor)
409408
return error("mergeFactor! not implemented for $(typeof(dfg))")
410409
end
411410

@@ -420,12 +419,8 @@ end
420419
$(SIGNATURES)
421420
Delete a FactorCompute from the DFG using its label.
422421
"""
423-
function deleteFactor!(
424-
dfg::G,
425-
label::Symbol;
426-
suppressGetFactor::Bool = false,
427-
) where {G <: AbstractDFG}
428-
return error("deleteFactors not implemented for $(typeof(dfg))")
422+
function deleteFactor!(dfg::AbstractDFG, label::Symbol)
423+
return error("deleteFactor not implemented for $(typeof(dfg))")
429424
end
430425

431426
"""

0 commit comments

Comments
 (0)