Skip to content

Commit 8acd907

Browse files
authored
feature setTimestamp!(dfg,lbl,ts) close #315 (#322)
1 parent 8aaead3 commit 8acd907

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

src/needsahome.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ Dev Notes
8080
"""
8181
function printVariable(fgl::AbstractDFG, vsym::Symbol, solveKey::Symbol=:default)
8282
vert = getVariable(fgl, vsym)
83-
vnd = solverData(vert, solveKey)
83+
vnd = getSolverData(vert, solveKey)
8484
println("label: $(vert.label)")
8585
println("tags: $(getTags(vert))")
8686
println("size marginal samples $(size(vnd.val))")
8787
println("kde bandwidths: $((vnd.bw)[:,1])")
88-
if 0 < length(getVariablePPEs(vert))
89-
println("PPE.suggested: $(round.(getVariablePPE(vert).suggested,digits=4))")
88+
if 0 < length(getPPEDict(vert))
89+
println("PPE.suggested: $(round.(getPPE(vert).suggested,digits=4))")
9090
else
9191
println("No PPEs")
9292
end

src/services/CommonAccessors.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ Get the timestamp of a DFGNode.
5454
getTimestamp(v::DataLevel1) = v.timestamp
5555

5656

57+
"""
58+
$SIGNATURES
59+
60+
Set the timestamp of a Variable/Factor object in a factor graph.
61+
Note:
62+
Since `timestamp` is not mutable `setTimestamp!` calls `updateVariable!` internally.
63+
See also [`setTimestamp`](@ref)
64+
"""
65+
function setTimestamp!(dfg::AbstractDFG, lbl::Symbol, ts::DateTime)
66+
if isVariable(dfg, lbl)
67+
return updateVariable!(dfg, setTimestamp(getVariable(dfg,lbl), ts))
68+
else
69+
return updateFactor!(dfg, setTimestamp(getFactor(dfg,lbl), ts))
70+
end
71+
end
72+
73+
5774

5875
##------------------------------------------------------------------------------
5976
## _internalId

src/services/DFGVariable.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ end
158158
159159
Set the timestamp of a DFGVariable object returning a new DFGVariable.
160160
Note:
161-
Since `timestamp` is not mutable `setTimestamp` returns a new variable with the updated timestamp.
162-
Use `updateVariable!` to update it in the factor graph.
161+
Since the `timestamp` field is not mutable `setTimestamp` returns a new variable with the updated timestamp (note the absence of `!`).
162+
Use [`updateVariable!`](@ref) on the returened variable to update it in the factor graph if needed. Alternatively use [`setTimestamp!`](@ref).
163+
See issue #315.
163164
"""
164165
function setTimestamp(v::DFGVariable, ts::DateTime)
165166
return DFGVariable(v.label, ts, v.tags, v.ppeDict, v.solverDataDict, v.smallData, v.bigData, v._dfgNodeParams)
@@ -169,8 +170,6 @@ function setTimestamp(v::DFGVariableSummary, ts::DateTime)
169170
return DFGVariableSummary(v.label, ts, v.tags, v.estimateDict, v.softtypename, v.bigData, v._internalId)
170171
end
171172

172-
#TODO something like:
173-
# setTimestamp!(dfg::AbstractDFG, var::DFGVariable, ts::DateTime) = updateVariable!(dfg, setTimestamp(var, ts))
174173

175174
##------------------------------------------------------------------------------
176175
## _dfgNodeParams [_internalId, solvable]

test/testBlocks.jl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,11 @@ function DFGVariableSCA()
200200
@test setTags!(v3, testTags) == Set(testTags)
201201
@test setTags!(v3, Set(testTags)) == Set(testTags)
202202

203-
#TODO Document
204203
#NOTE a variable's timestamp is considered similar to its label. setTimestamp! (not implemented) would create a new variable and call updateVariable!
205204
v1ts = setTimestamp(v1, testTimestamp)
206205
@test getTimestamp(v1ts) == testTimestamp
207206
#follow with updateVariable!(fg, v1ts)
208-
# setTimestamp!(v1, testTimestamp) not implemented, we can do an setTimestamp() updateVariable!() for a setTimestamp!(dfg, v1, testTimestamp)
207+
209208
@test_throws MethodError setTimestamp!(v1, testTimestamp)
210209

211210
@test setSolvable!(v1, 1) == 1
@@ -257,7 +256,7 @@ function DFGFactorSCA()
257256
f1 = DFGFactor{TestCCW{TestFunctorInferenceType1}, Symbol}(f1_lbl)
258257
f1 = DFGFactor(f1_lbl, [:a,:b], gfnd, tags = f1_tags, solvable=0)
259258

260-
f2 = DFGFactor{TestFunctorInferenceType1, Symbol}(:f2)
259+
f2 = DFGFactor{TestFunctorInferenceType1, Symbol}(:bcf1)
261260

262261
@test getLabel(f1) == f1_lbl
263262
@test getTags(f1) == f1_tags
@@ -291,7 +290,7 @@ function DFGFactorSCA()
291290
f1ts = setTimestamp(f1, testTimestamp)
292291
@test !(f1ts === f1)
293292
@test getTimestamp(f1ts) == testTimestamp
294-
#follow with updateVariable!(fg, v1ts)
293+
#follow with updateFactor!(fg, v1ts)
295294
@test setTimestamp!(f1, testTimestamp) == testTimestamp
296295
#/TODO
297296

@@ -341,11 +340,20 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
341340

342341
@test getAddHistory(fg) == [:a, :b, :c]
343342

343+
# Extra timestamp functions https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/315
344+
if !(v1 isa SkeletonDFGVariable)
345+
newtimestamp = now()
346+
@test !(setTimestamp!(fg, :c, newtimestamp) === v3)
347+
@test getVariable(fg, :c) |> getTimestamp == newtimestamp
348+
349+
@test !(setTimestamp!(fg, :bcf1, newtimestamp) === f2)
350+
@test getFactor(fg, :bcf1) |> getTimestamp == newtimestamp
351+
end
344352
#deletions
345-
@test deleteVariable!(fg, v3) == v3
353+
@test getVariable(fg, :c) === deleteVariable!(fg, v3)
346354
@test_throws ErrorException deleteVariable!(fg, v3)
347355
@test setdiff(ls(fg),[:a,:b]) == []
348-
@test deleteFactor!(fg, f2) === f2
356+
@test getFactor(fg, :bcf1) === deleteFactor!(fg, f2)
349357
@test_throws ErrorException deleteFactor!(fg, f2)
350358
@test lsf(fg) == [:abf1]
351359

@@ -365,14 +373,13 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
365373
@test getFactor(fg, :abf1) === f1
366374

367375
@test_throws ErrorException getVariable(fg, :c)
368-
@test_throws ErrorException getFactor(fg, :f2)
369-
376+
@test_throws ErrorException getFactor(fg, :bcf1)
370377

371378
# Existence
372379
@test exists(fg, :a)
373380
@test !exists(fg, :c)
374381
@test exists(fg, :abf1)
375-
@test !exists(fg, :f2)
382+
@test !exists(fg, :bcf1)
376383

377384
@test exists(fg, v1)
378385
@test !exists(fg, v3)

0 commit comments

Comments
 (0)