Skip to content

Commit 21054f3

Browse files
authored
Merge pull request #227 from JuliaRobotics/feature/4Q19/getsettimest
Missing accessor methods for DFGVariable and DFGFactor
2 parents e5b45ab + ba3fca0 commit 21054f3

File tree

5 files changed

+192
-83
lines changed

5 files changed

+192
-83
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export DFGNode, DFGVariable, DFGFactor, AbstractDFGVariable, AbstractDFGFactor
2222
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
2323
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
2424
export getMaxPPE, getMeanPPE, getSuggestedPPE
25-
export label, timestamp, tags, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
25+
export label, timestamp, setTimestamp!, tags, setTags!, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, setSolverData!, internalId, smallData, setSmallData!, bigData
2626
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
2727

2828
#Skeleton types

src/entities/DFGFactor.jl

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Originally from IncrementalInference
21

32
abstract type InferenceType end
43
abstract type PackedInferenceType end
@@ -46,8 +45,70 @@ mutable struct DFGFactor{T, S} <: AbstractDFGFactor
4645
DFGFactor{T, S}(label::Symbol, _internalId::Int64) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, _internalId, Symbol[])
4746
end
4847

49-
label(f::F) where F <: DFGFactor = f.label
50-
tags(f::F) where F <: DFGFactor = f.tags
48+
# Simply for convenience - don't export
49+
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
50+
PackedFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T <: PackedInferenceType, S <: AbstractString} = GenericFunctionNodeData(x1, x2, x3, x4, x5, x6, x7, x8, x9)
51+
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
52+
FunctionNodeData(x1, x2, x3, x4, x5::Symbol, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T <: Union{FunctorInferenceType, ConvolutionObject}}= GenericFunctionNodeData{T, Symbol}(x1, x2, x3, x4, x5, x6, x7, x8, x9)
53+
54+
"""
55+
$(SIGNATURES)
56+
Structure for first-class citizens of a DFGFactor.
57+
"""
58+
mutable struct DFGFactorSummary <: AbstractDFGFactor
59+
label::Symbol
60+
tags::Vector{Symbol}
61+
_internalId::Int64
62+
_variableOrderSymbols::Vector{Symbol}
63+
end
64+
65+
# SKELETON DFG
66+
"""
67+
$(TYPEDEF)
68+
Skeleton factor with essentials.
69+
"""
70+
struct SkeletonDFGFactor <: AbstractDFGFactor
71+
label::Symbol
72+
tags::Vector{Symbol}
73+
_variableOrderSymbols::Vector{Symbol}
74+
end
75+
76+
#NOTE I feel like a want to force a variableOrderSymbols
77+
SkeletonDFGFactor(label::Symbol, variableOrderSymbols::Vector{Symbol} = Symbol[]) = SkeletonDFGFactor(label, Symbol[], variableOrderSymbols)
78+
79+
# Accessors
80+
81+
const FactorDataLevel0 = Union{DFGFactor, DFGFactorSummary, SkeletonDFGFactor}
82+
const FactorDataLevel1 = Union{DFGFactor, DFGFactorSummary}
83+
84+
"""
85+
$SIGNATURES
86+
87+
Return the label for a factor.
88+
"""
89+
label(f::FactorDataLevel0) = f.label
90+
91+
"""
92+
$SIGNATURES
93+
94+
Return the tags for a variable.
95+
"""
96+
tags(f::FactorDataLevel0) = f.tags
97+
98+
"""
99+
$SIGNATURES
100+
101+
Set the tags for a factor.
102+
"""
103+
setTag!s(f::FactorDataLevel0, tags::Vector{Symbol}) = f.tags = tags
104+
105+
"""
106+
$SIGNATURES
107+
108+
Return the internal ID for a variable.
109+
"""
110+
internalId(f::FactorDataLevel1) = f._internalId
111+
51112
"""
52113
$SIGNATURES
53114
@@ -79,43 +140,3 @@ function getData(f::DFGFactor)::GenericFunctionNodeData
79140
# @warn "getData is deprecated, please use solverData()"
80141
return f.data
81142
end
82-
83-
internalId(f::F) where F <: DFGFactor = f._internalId
84-
85-
# Simply for convenience - don't export
86-
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
87-
PackedFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T <: PackedInferenceType, S <: AbstractString} = GenericFunctionNodeData(x1, x2, x3, x4, x5, x6, x7, x8, x9)
88-
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
89-
FunctionNodeData(x1, x2, x3, x4, x5::Symbol, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T <: Union{FunctorInferenceType, ConvolutionObject}}= GenericFunctionNodeData{T, Symbol}(x1, x2, x3, x4, x5, x6, x7, x8, x9)
90-
91-
"""
92-
$(SIGNATURES)
93-
Structure for first-class citizens of a DFGFactor.
94-
"""
95-
mutable struct DFGFactorSummary <: AbstractDFGFactor
96-
label::Symbol
97-
tags::Vector{Symbol}
98-
_internalId::Int64
99-
_variableOrderSymbols::Vector{Symbol}
100-
end
101-
102-
label(f::DFGFactorSummary) = f.label
103-
data(f::DFGFactorSummary) = f.data
104-
tags(f::DFGFactorSummary) = f.tags
105-
internalId(f::DFGFactorSummary) = f._internalId
106-
107-
108-
# SKELETON DFG
109-
"""
110-
$(TYPEDEF)
111-
Skeleton variable with essentials.
112-
"""
113-
struct SkeletonDFGVariable <: AbstractDFGVariable
114-
label::Symbol
115-
tags::Vector{Symbol}
116-
end
117-
118-
SkeletonDFGVariable(label::Symbol) = SkeletonDFGVariable(label, Symbol[])
119-
120-
label(v::SkeletonDFGVariable) = v.label
121-
tags(v::SkeletonDFGVariable) = v.tags

src/entities/DFGVariable.jl

Lines changed: 112 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,92 @@ DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where {T <: Infe
159159
Dict{String, String}(),
160160
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)
161161

162+
"""
163+
$(SIGNATURES)
164+
Structure for first-class citizens of a DFGVariable.
165+
"""
166+
mutable struct DFGVariableSummary <: AbstractDFGVariable
167+
label::Symbol
168+
timestamp::DateTime
169+
tags::Vector{Symbol}
170+
estimateDict::Dict{Symbol, <:AbstractPointParametricEst}
171+
softtypename::Symbol
172+
_internalId::Int64
173+
end
174+
175+
176+
# SKELETON DFG
177+
"""
178+
$(TYPEDEF)
179+
Skeleton variable with essentials.
180+
"""
181+
struct SkeletonDFGVariable <: AbstractDFGVariable
182+
label::Symbol
183+
tags::Vector{Symbol}
184+
end
185+
186+
SkeletonDFGVariable(label::Symbol) = SkeletonDFGVariable(label, Symbol[])
187+
162188
# Accessors
163-
label(v::DFGVariable) = v.label
164-
timestamp(v::DFGVariable) = v.timestamp
165-
tags(v::DFGVariable) = v.tags
166-
estimates(v::DFGVariable) = v.estimateDict
167-
estimate(v::DFGVariable, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
189+
190+
const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, SkeletonDFGVariable}
191+
const VariableDataLevel1 = Union{DFGVariable, DFGVariableSummary}
192+
193+
"""
194+
$SIGNATURES
195+
196+
Return the label for a variable.
197+
"""
198+
label(v::VariableDataLevel0) = v.label
199+
200+
"""
201+
$SIGNATURES
202+
203+
Return the tags for a variable.
204+
"""
205+
tags(v::VariableDataLevel0) = v.tags
206+
207+
"""
208+
$SIGNATURES
209+
210+
Set the tags for a variable.
211+
"""
212+
setTags!(v::VariableDataLevel0, tags::Vector{Symbol}) = v.tags = tags
213+
214+
"""
215+
$SIGNATURES
216+
217+
Return the timestamp for a variable.
218+
"""
219+
timestamp(v::VariableDataLevel1) = v.timestamp
220+
221+
"""
222+
$SIGNATURES
223+
224+
Set the timestamp for a variable.
225+
"""
226+
setTimestamp!(v::VariableDataLevel1, timestamp::DateTime) = v.timestamp = timestamp
227+
228+
"""
229+
$SIGNATURES
230+
231+
Return the estimates for a variable.
232+
"""
233+
estimates(v::VariableDataLevel1) = v.estimateDict
234+
235+
"""
236+
$SIGNATURES
237+
238+
Return a keyed estimate (default is :default) for a variable.
239+
"""
240+
estimate(v::VariableDataLevel1, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
241+
242+
"""
243+
$SIGNATURES
244+
245+
Return the softtype name for a variable.
246+
"""
247+
softtype(v::DFGVariableSummary)::Symbol = v.softtypename
168248

169249
"""
170250
$SIGNATURES
@@ -173,6 +253,13 @@ Retrieve the soft type name symbol for a DFGVariable or DFGVariableSummary. ie :
173253
"""
174254
softtype(v::DFGVariable)::Symbol = Symbol(typeof(getSofttype(v)))
175255

256+
"""
257+
$SIGNATURES
258+
259+
Return the internal ID a variable.
260+
"""
261+
internalId(v::VariableDataLevel1) = v._internalId
262+
176263
"""
177264
$SIGNATURES
178265
@@ -194,47 +281,33 @@ end
194281
Set solver data structure stored in a variable.
195282
"""
196283
setSolverData(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = v.solverDataDict[key] = data
197-
solverDataDict(v::DFGVariable) = v.solverDataDict
198-
internalId(v::DFGVariable) = v._internalId
199-
# Todo: Complete this.
200-
smallData(v::DFGVariable) = v.smallData
201-
bigData(v::DFGVariable) = v.bigData
284+
"""
285+
$SIGNATURES
202286
287+
Set solver data structure stored in a variable.
203288
"""
204-
$(SIGNATURES)
205-
Structure for first-class citizens of a DFGVariable.
289+
setSolverData!(v::DFGVariable, data::VariableNodeData, key::Symbol=:default) = setSolverData(v, data, key)
290+
206291
"""
207-
mutable struct DFGVariableSummary <: AbstractDFGVariable
208-
label::Symbol
209-
timestamp::DateTime
210-
tags::Vector{Symbol}
211-
estimateDict::Dict{Symbol, <:AbstractPointParametricEst}
212-
softtypename::Symbol
213-
_internalId::Int64
214-
end
215-
label(v::DFGVariableSummary) = v.label
216-
timestamp(v::DFGVariableSummary) = v.timestamp
217-
tags(v::DFGVariableSummary) = v.tags
218-
estimates(v::DFGVariableSummary) = v.estimateDict
219-
estimate(v::DFGVariableSummary, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
220-
softtype(v::DFGVariableSummary)::Symbol = v.softtypename
221-
internalId(v::DFGVariableSummary) = v._internalId
292+
$SIGNATURES
222293
294+
Get solver data dictionary for a variable.
295+
"""
296+
solverDataDict(v::DFGVariable) = v.solverDataDict
223297

298+
"""
299+
$SIGNATURES
224300
225-
# SKELETON DFG
301+
Get the small data for a variable.
226302
"""
227-
$(TYPEDEF)
228-
Skeleton factor with essentials.
303+
smallData(v::DFGVariable) = v.smallData
304+
229305
"""
230-
struct SkeletonDFGFactor <: AbstractDFGFactor
231-
label::Symbol
232-
tags::Vector{Symbol}
233-
_variableOrderSymbols::Vector{Symbol}
234-
end
306+
$SIGNATURES
235307
236-
#NOTE I feel like a want to force a variableOrderSymbols
237-
SkeletonDFGFactor(label::Symbol, variableOrderSymbols::Vector{Symbol} = Symbol[]) = SkeletonDFGFactor(label, Symbol[], variableOrderSymbols)
308+
Set the small data for a variable.
309+
"""
310+
setSmallData!(v::DFGVariable, smallData::String) = v.smallData = smallData
238311

239-
label(f::SkeletonDFGFactor) = f.label
240-
tags(f::SkeletonDFGFactor) = f.tags
312+
# Todo: Complete this.
313+
bigData(v::DFGVariable) = v.bigData

test/interfaceTests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,22 @@ end
127127
f1Prime = deepcopy(f1)
128128
#updateFactor! returns the factor updated, so should be equal
129129
@test updateFactor!(dfg, f1Prime) == f1
130+
# Revert
131+
v1 = getVariable(dfg, v1.label)
132+
f1 = getFactor(dfg, f1.label)
130133

131134
# Accessors
132135
@test label(v1) == v1.label
133136
@test tags(v1) == v1.tags
137+
testTags = [:ha, :ha23]
138+
@test setTags!(v1, testTags) == testTags
139+
@test tags(v1) == testTags
140+
134141
@test timestamp(v1) == v1.timestamp
142+
testTimestamp = now()
143+
@test setTimestamp!(v1, testTimestamp) == testTimestamp
144+
@test timestamp(v1) == testTimestamp
145+
135146
@test estimates(v1) == v1.estimateDict
136147
@test estimate(v1, :notfound) == nothing
137148
@test solverData(v1) === v1.solverDataDict[:default]
@@ -146,6 +157,9 @@ end
146157

147158
@test label(f1) == f1.label
148159
@test tags(f1) == f1.tags
160+
@test setTags!(v1, testTags) == testTags
161+
@test tags(v1) == testTags
162+
149163
@test solverData(f1) == f1.data
150164
# Deprecated functions
151165
@test data(f1) == f1.data

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using GraphPlot # For plotting tests
33
using Neo4j
44
using DistributedFactorGraphs
55
using Pkg
6+
using Dates
67

78
## To run the IIF tests, you need a local Neo4j with user/pass neo4j:test
89
# To run a Docker image

0 commit comments

Comments
 (0)