Skip to content

Commit 3a2418c

Browse files
committed
A chunk closer
1 parent cafa740 commit 3a2418c

File tree

8 files changed

+94
-48
lines changed

8 files changed

+94
-48
lines changed

src/CommonAccessors.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,20 @@ getTimestamp(v::DataLevel1) = v.timestamp
3838
$SIGNATURES
3939
4040
Set the timestamp of a DFGFactor object.
41+
Dev note:
42+
Since it is not mutable it has to return a new variable with the updated timestamp.
43+
Use `updateVariable!` to update it in the factor graph.
44+
TODO either this or we should make the field/variable mutable
4145
"""
42-
setTimestamp!(v::DataLevel1, ts::DateTime) = v.timestamp = ts
46+
function setTimestamp(v::DFGVariable, ts::DateTime)
47+
return DFGVariable(v.label, ts, v.tags, v.ppeDict, v.solverDataDict, v.smallData, v.bigData, v._dfgNodeParams)
48+
end
49+
50+
function setTimestamp(v::DFGVariableSummary, ts::DateTime)
51+
return DFGVariableSummary(v.label, ts, v.tags, v.estimateDict, v.softtypename, v.bigData, v._internalId)
52+
end
53+
54+
setTimestamp!(f::FactorDataLevel1, ts::DateTime) = f.timestamp = ts
4355

4456
"""
4557
$SIGNATURES

src/Deprecated.jl

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,44 @@
33
## quick deprecation handle
44
import Base: propertynames, getproperty
55

6-
Base.propertynames(x::VariableDataLevel1, private::Bool=false) = private ? (:estimateDict, :ppeDict) : (:ppeDict,)
6+
# this hides all the propertynames and makes it hard to work with.
7+
# Base.propertynames(x::VariableDataLevel1, private::Bool=false) = private ? (:estimateDict, :ppeDict) : (:ppeDict,)
78

8-
Base.getproperty(x::VariableDataLevel1,f::Symbol) = begin
9+
Base.getproperty(x::DFGVariable,f::Symbol) = begin
910
if f == :estimateDict
10-
@warn "estimateDict is deprecated, use ppeDict instead"
11-
getfield(x, :ppeDict)
11+
@warn "estimateDict is deprecated, use ppeDict instead"
12+
getfield(x, :ppeDict)
1213
elseif f == :solvable
13-
getfield(x,:_dfgNodeParams).solvable
14+
getfield(x,:_dfgNodeParams).solvable
1415
elseif f == :_internalId
15-
getfield(x,:_dfgNodeParams)._internalId
16+
getfield(x,:_dfgNodeParams)._internalId
1617
else
17-
getfield(x,f)
18+
getfield(x,f)
19+
end
20+
end
21+
22+
Base.getproperty(x::DFGVariableSummary,f::Symbol) = begin
23+
if f == :estimateDict
24+
@warn "estimateDict is deprecated, use ppeDict instead"
25+
getfield(x, :ppeDict)
26+
else
27+
getfield(x,f)
1828
end
1929
end
2030

2131

2232

33+
Base.getproperty(x::DFGFactor,f::Symbol) = begin
34+
if f == :solvable
35+
getfield(x,:_dfgNodeParams).solvable
36+
elseif f == :_internalId
37+
getfield(x,:_dfgNodeParams)._internalId
38+
else
39+
getfield(x,f)
40+
end
41+
end
42+
43+
2344
"""
2445
$SIGNATURES
2546

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export DFGNode, DFGVariable, DFGFactor, AbstractDFGVariable, AbstractDFGFactor
3434
export DFGNodeParams
3535
export SkeletonDFGVariable, SkeletonDFGFactor
3636
export timestamp # DEPRECATED
37-
export label, getTimestamp, setTimestamp!, tags, setTags!, data, softtype, solverData, getData, solverDataDict, setSolverData, setSolverData!, internalId, smallData, setSmallData!, bigData
37+
export label, getTimestamp, setTimestamp!, setTimestamp, tags, setTags!, data, softtype, solverData, getData, solverDataDict, setSolverData, setSolverData!, internalId, smallData, setSmallData!, bigData
3838
export getSolvedCount, isSolved, setSolvedCount!
3939
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
4040
export getNeighborhood, getSubgraph, getSubgraphAroundNode

src/entities/DFGVariable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct DFGVariable{T<:InferenceVariable} <: AbstractDFGVariable
2020
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
2121
Accessors: `getTags`, `addTags!`, and `deleteTags!`"""
2222
tags::Set{Symbol}
23-
"""Dictionary of estimates keyed by solverDataDict keys
24-
Accessors: `addEstimate!`, `updateEstimate!`, and `deleteEstimate!`"""
23+
"""Dictionary of parametric point estimates keyed by solverDataDict keys
24+
Accessors: `addPPE!`, `updatePPE!`, and `deletePPE!`"""
2525
ppeDict::Dict{Symbol, <: AbstractPointParametricEst}
2626
"""Dictionary of solver data. May be a subset of all solutions if a solver key was specified in the get call.
2727
Accessors: `addVariableSolverData!`, `updateVariableSolverData!`, and `deleteVariableSolverData!`"""

src/entities/DFGVariableSummary.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ struct DFGVariableSummary <: AbstractDFGVariable
1616
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
1717
Accessors: `getTags`, `addTags!`, and `deleteTags!`"""
1818
tags::Set{Symbol}
19-
"""Dictionary of estimates keyed by solverDataDict keys
20-
Accessors: `addEstimate!`, `updateEstimate!`, and `deleteEstimate!`"""
21-
estimateDict::Dict{Symbol, <:AbstractPointParametricEst}
19+
"""Dictionary of parametric point estimates keyed by solverDataDict keys
20+
Accessors: `addPPE!`, `updatePPE!`, and `deletePPE!`"""
21+
ppeDict::Dict{Symbol, <:AbstractPointParametricEst}
2222
"""Symbol for the softtype for the underlying variable.
2323
Accessor: `getSofttype`"""
2424
softtypename::Symbol

src/services/DFGFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Base: convert, ==
22

33
function convert(::Type{DFGFactorSummary}, f::DFGFactor)
4-
return DFGFactorSummary(f.label, f.timetamp, deepcopy(f.tags), f._internalId, deepcopy(f._variableOrderSymbols))
4+
return DFGFactorSummary(f.label, f.timestamp, deepcopy(f.tags), f._dfgNodeParams._internalId, deepcopy(f._variableOrderSymbols))
55
end
66

77
function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: AbstractDFG

src/services/DFGVariable.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ end
156156
Convert a DFGVariable to a DFGVariableSummary.
157157
"""
158158
function convert(::Type{DFGVariableSummary}, v::DFGVariable)
159-
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.ppeDict), Symbol(typeof(getSofttype(v))), v._internalId)
159+
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.ppeDict), Symbol(typeof(getSofttype(v))), v.bigData, v._internalId)
160160
end
161161

162162
"""
@@ -328,6 +328,11 @@ function getSolverData(v::DFGVariable, key::Symbol=:default)
328328
return haskey(v.solverDataDict, key) ? v.solverDataDict[key] : nothing
329329
end
330330

331+
function solverData(v::DFGVariable, key::Symbol=:default)
332+
@warn "Deprecated for 0.6 standardization. Please use getSolverData()"
333+
return getSolverData(v, key)
334+
end
335+
331336
"""
332337
$SIGNATURES
333338

test/interfaceTests.jl

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#
2-
global testDFGAPI = LightDFG
1+
# global testDFGAPI = LightDFG
32

43
dfg = testDFGAPI{NoSolverParams}()
54

@@ -19,14 +18,14 @@ union!(f1.tags, [:FACTOR])
1918
st1 = TestInferenceVariable1()
2019
st2 = TestInferenceVariable2()
2120

22-
solverData(v1).softtype = deepcopy(st1)
23-
solverData(v2).softtype = deepcopy(st2)
21+
getSolverData(v1).softtype = deepcopy(st1)
22+
getSolverData(v2).softtype = deepcopy(st2)
2423

2524
# set v1 to solvable=0
2625
setSolvable!(v1, 0)
2726
# set v1 and f1 solveInProgress
28-
solverData(v1).solveInProgress = 1
29-
solverData(f1).solveInProgress = 1
27+
getSolverData(v1).solveInProgress = 1
28+
getSolverData(f1).solveInProgress = 1
3029

3130

3231
# NOTE: Just for testing
@@ -122,7 +121,9 @@ end
122121
f2 = deepcopy(f1)
123122
f2.label = :something
124123
@test f2 != f1
125-
@test getVariable(dfg, :nope) == nothing
124+
#TODO we should really finish defining error behaviour
125+
@test_throws Exception getVariable(dfg, :nope)
126+
# @test getVariable(dfg, :nope) == nothing
126127
@test_throws Exception getVariable(dfg, "nope")
127128
@test_throws Exception getFactor(dfg, :nope)
128129
@test_throws Exception getFactor(dfg, "nope")
@@ -147,8 +148,12 @@ end
147148

148149
@test getTimestamp(v1) == v1.timestamp
149150
testTimestamp = now()
150-
#TODO set timestamp immutable
151-
@test setTimestamp!(v1, testTimestamp) == testTimestamp
151+
#TODO set timestamp immutable, confirm behaviour
152+
v1ts = setTimestamp(v1, testTimestamp)
153+
updateVariable!(dfg, v1ts)
154+
@test getVariable(dfg, v1ts.label) == v1ts
155+
@test v1ts != v1
156+
v1 = getVariable(dfg, v1ts.label)
152157
@test getTimestamp(v1) == testTimestamp
153158

154159
@test getTimestamp(f1) == f1.timestamp
@@ -167,13 +172,14 @@ end
167172
#TODO: Finish
168173
# Add new VND of type ContinuousScalar to :x0
169174
# Could also do VariableNodeData(ContinuousScalar())
170-
vnd = VariableNodeData{ContinuousScalar}()
175+
vnd = VariableNodeData{TestInferenceVariable1}()
171176
addVariableSolverData!(dfg, :a, vnd, :parametric)
172-
@show listVariableSolverData(dfg, :a)
177+
@test setdiff(listVariableSolverData(dfg, :a), [:default, :parametric]) == []
173178
# Get the data back - note that this is a reference to above.
174179
vndBack = getVariableSolverData(dfg, :a, :parametric)
180+
@test vndBack == vnd
175181
# Delete it
176-
deleteVariableSolverData!(dfg, :a, :parametric)
182+
@test deleteVariableSolverData!(dfg, :a, :parametric) == vndBack
177183
# Update add it
178184
updateVariableSolverData!(dfg, :a, vnd, :parametric)
179185
# Update update it
@@ -186,20 +192,21 @@ end
186192
#TODO: Finish
187193
# Add a new PPE of type MeanMaxPPE to :x0
188194
ppe = MeanMaxPPE(:default, [0.0], [0.0], [0.0])
189-
addPPE!(dfg, :x0, ppe)
190-
@show listPPE(dfg, :x0)
195+
addPPE!(dfg, :a, ppe)
196+
@test listPPE(dfg, :a) == [:default]
191197
# Get the data back - note that this is a reference to above.
192-
v = getPPE(dfg, :x0, :default)
198+
@test getPPE(dfg, :a, :default) == ppe
199+
193200
# Delete it
194-
deletePPE!(dfg, :x0, :default)
201+
@test deletePPE!(dfg, :a, :default) == ppe
195202
# Update add it
196-
updatePPE!(dfg, :x0, ppe, :default)
203+
updatePPE!(dfg, :a, ppe, :default)
197204
# Update update it
198-
updatePPE!(dfg, :x0, ppe, :default)
205+
updatePPE!(dfg, :a, ppe, :default)
199206
# Bulk copy PPE's for x0 and x1
200-
updatePPE!(dfg, [x0], :default)
207+
updatePPE!(dfg, [v1], :default)
201208
# Delete it
202-
deletePPE!(dfg, :x0, :default)
209+
@test deletePPE!(dfg, :a, :default) == ppe
203210

204211
#TODO I don't know what is supposed to happen to softtype
205212
@test getSofttype(v1) == st1
@@ -208,8 +215,8 @@ end
208215

209216
@test getLabel(f1) == f1.label
210217
@test getTags(f1) == f1.tags
211-
@test setTags!(v1, testTags) == testTags
212-
@test getTags(v1) == testTags
218+
@test setTags!(v1, testTags) == Set(testTags)
219+
@test getTags(v1) == Set(testTags)
213220

214221
@test solverData(f1) == f1.solverData
215222
# Deprecated functions
@@ -226,9 +233,10 @@ end
226233
@test !isInitialized(v2)
227234
@test !isInitialized(v2, key=:second)
228235
# isSolvable and isSolveInProgress
229-
@test isSolvable(v1) == 0
230-
@test isSolvable(v2) == 1
231-
@test isSolvable(f1) == 0
236+
#TODO implement or deprecate isSolvable
237+
@test getSolvable(v1) == 0
238+
@test getSolvable(v2) == 1
239+
@test getSolvable(f1) == 0
232240
@test getSolvable(v1) == 0
233241

234242
#TODO isSolveInProgress was not deprecated
@@ -238,9 +246,9 @@ end
238246
v1 = getVariable(dfg, v1.label)
239247
f1 = getFactor(dfg, f1.label)
240248
@test setSolvable!(v1, 1) == 1
241-
@test isSolvable(v1) == 1
249+
@test getSolvable(v1) == 1
242250
@test setSolvable!(dfg, v1.label, 0) == 0
243-
@test isSolvable(v1) == 0
251+
@test getSolvable(v1) == 0
244252
@test setSolvable!(f1, 1) == 1
245253
@test getSolvable(dfg, f1.label) == 1
246254
@test setSolvable!(dfg, f1.label, 0) == 0
@@ -268,9 +276,9 @@ end
268276
smallUserData = Dict{Symbol, String}(:a => "42", :b => "Hello")
269277
smallRobotData = Dict{Symbol, String}(:a => "43", :b => "Hello")
270278
smallSessionData = Dict{Symbol, String}(:a => "44", :b => "Hello")
271-
setUserData(dfg, deepcopy(smallUserData))
272-
setRobotData(dfg, deepcopy(smallRobotData))
273-
setSessionData(dfg, deepcopy(smallSessionData))
279+
setUserData!(dfg, deepcopy(smallUserData))
280+
setRobotData!(dfg, deepcopy(smallRobotData))
281+
setSessionData!(dfg, deepcopy(smallSessionData))
274282
@test getUserData(dfg) == smallUserData
275283
@test getRobotData(dfg) == smallRobotData
276284
@test getSessionData(dfg) == smallSessionData
@@ -507,7 +515,7 @@ end
507515
for v in ls(summaryGraph)
508516
for field in variableFields
509517
if field != :softtypename
510-
@test getfield(getVariable(dfg, v), field) == getfield(getVariable(summaryGraph, v), field)
518+
@test getproperty(getVariable(dfg, v), field) == getproperty(getVariable(summaryGraph, v), field)
511519
else
512520
# Special case to check the symbol softtype is equal to the full softtype.
513521
@test Symbol(typeof(getSofttype(getVariable(dfg, v)))) == getSofttype(getVariable(summaryGraph, v))
@@ -516,7 +524,7 @@ end
516524
end
517525
for f in lsf(summaryGraph)
518526
for field in factorFields
519-
@test getfield(getFactor(dfg, f), field) == getfield(getFactor(summaryGraph, f), field)
527+
@test getproperty(getFactor(dfg, f), field) == getproperty(getFactor(summaryGraph, f), field)
520528
end
521529
end
522530
end

0 commit comments

Comments
 (0)