Skip to content

Commit 38be1d7

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

File tree

10 files changed

+182
-162
lines changed

10 files changed

+182
-162
lines changed

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: 4 additions & 4 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!(
@@ -270,7 +270,7 @@ function updateData!(
270270
_version = string(_getDFGVersion()),
271271
)
272272

273-
de = updateBlobEntry!(dfg, label, newEntry)
273+
de = mergeBlobentry!(dfg, label, newEntry)
274274
db = updateBlob!(blobstore, de, blob)
275275
return de => db
276276
end

src/Deprecated.jl

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

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: 3 additions & 3 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.
306+
"""Dictionary of solver data. May be a subset of all solutions if a solver label was specified in the get call.
307307
Accessors: [`addVariableSolverData!`](@ref), [`updateVariableSolverData!`](@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: 2 additions & 2 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

0 commit comments

Comments
 (0)