Skip to content

Commit 2a0f003

Browse files
authored
Merge pull request #184 from JuliaRobotics/feature/149_DFGVariableSofttype
Closes #149 DFGVariable softtype parametric type
2 parents a4464d0 + 71d26b2 commit 2a0f003

File tree

3 files changed

+62
-23
lines changed

3 files changed

+62
-23
lines changed

src/entities/DFGVariable.jl

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct SingletonInferenceVariable <: InferenceVariable end
55
"""
66
$(TYPEDEF)
77
"""
8-
mutable struct VariableNodeData #TODO v0.5.0 {T<:InferenceVariable}
8+
mutable struct VariableNodeData{T<:InferenceVariable}
99
val::Array{Float64,2}
1010
bw::Array{Float64,2}
1111
BayesNetOutVertIDs::Array{Symbol,1}
@@ -14,7 +14,7 @@ mutable struct VariableNodeData #TODO v0.5.0 {T<:InferenceVariable}
1414
eliminated::Bool
1515
BayesNetVertID::Symbol # Union{Nothing, }
1616
separator::Array{Symbol,1}
17-
softtype::InferenceVariable #TODO v0.5.0 T
17+
softtype::T
1818
initialized::Bool
1919
inferdim::Float64
2020
ismargin::Bool
@@ -24,7 +24,21 @@ mutable struct VariableNodeData #TODO v0.5.0 {T<:InferenceVariable}
2424
# A valid, packable default constructor is needed.
2525

2626
end
27-
VariableNodeData() = VariableNodeData(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false)
27+
28+
VariableNodeData(params...) = VariableNodeData{InferenceVariable}(params...)
29+
30+
function VariableNodeData()
31+
st = stacktrace()
32+
@warn "VariableNodeData() is depreciated please use VariableNodeData{T}() or VariableNodeData(softtype::T) where T <: InferenceVariable. Enable DEBUG logging for stack trace."
33+
@debug st
34+
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false)
35+
end
36+
37+
VariableNodeData{T}() where {T <:InferenceVariable} =
38+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false)
39+
40+
VariableNodeData(softtype::T) where T <: InferenceVariable =
41+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false)
2842

2943
"""
3044
$(TYPEDEF)
@@ -109,11 +123,30 @@ end
109123
$SIGNATURES
110124
DFGVariable constructors.
111125
"""
112-
DFGVariable(label::Symbol, _internalId::Int64) =
113-
DFGVariable(label, now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
114-
115-
DFGVariable(label::Symbol) =
116-
DFGVariable(label, now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
126+
function DFGVariable(label::Symbol, _internalId::Int64 = 0) #where {T <:InferenceVariable}
127+
st = stacktrace()
128+
@warn "DFGVariable(label::Symbol, _internalId::Int64 = 0) is depreciated please use DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where T <: InferenceVariable. Enable DEBUG logging for the stack trace."
129+
@debug st
130+
T = InferenceVariable
131+
DFGVariable(label, now(), Symbol[],
132+
Dict{Symbol, MeanMaxPPE}(),
133+
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData()),
134+
Dict{String, String}(),
135+
Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
136+
end
137+
DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where {T <: InferenceVariable} =
138+
DFGVariable(label, now(), Symbol[],
139+
Dict{Symbol, MeanMaxPPE}(),
140+
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData{T}()),
141+
Dict{String, String}(),
142+
Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
143+
144+
# DFGVariable(label::Symbol, _internalId::Int64) =
145+
# DFGVariable(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
146+
#
147+
# DFGVariable(label::Symbol) =
148+
# DFGVariable(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
149+
#
117150

118151
# Accessors
119152
label(v::DFGVariable) = v.label

test/interfaceTests.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
dfg = testDFGAPI{NoSolverParams}()
2-
v1 = DFGVariable(:a)
3-
v2 = DFGVariable(:b)
2+
3+
#add types for softtypes
4+
struct TestInferenceVariable1 <: InferenceVariable end
5+
struct TestInferenceVariable2 <: InferenceVariable end
6+
7+
v1 = DFGVariable(:a, TestInferenceVariable1())
8+
v2 = DFGVariable(:b, TestInferenceVariable2())
49
f1 = DFGFactor{Int, :Symbol}(:f1)
510

611
#add tags for filters
712
append!(v1.tags, [:VARIABLE, :POSE])
813
append!(v2.tags, [:VARIABLE, :LANDMARK])
914
append!(f1.tags, [:FACTOR])
1015

11-
#add types for softtypes
12-
struct TestInferenceVariable1 <: InferenceVariable end
13-
struct TestInferenceVariable2 <: InferenceVariable end
14-
1516
st1 = TestInferenceVariable1()
1617
st2 = TestInferenceVariable2()
1718

@@ -39,9 +40,9 @@ addFactor!(dfg, [v1, v2], f1)
3940

4041
@testset "Adding Removing Nodes" begin
4142
dfg2 = testDFGAPI{NoSolverParams}()
42-
v1 = DFGVariable(:a)
43-
v2 = DFGVariable(:b)
44-
v3 = DFGVariable(:c)
43+
v1 = DFGVariable(:a, TestInferenceVariable1())
44+
v2 = DFGVariable(:b, TestInferenceVariable1())
45+
v3 = DFGVariable(:c, TestInferenceVariable1())
4546
f1 = DFGFactor{Int, :Symbol}(:f1)
4647
f2 = DFGFactor{Int, :Symbol}(:f2)
4748
# @testset "Creating Graphs" begin
@@ -277,14 +278,15 @@ end
277278
# Now make a complex graph for connectivity tests
278279
numNodes = 10
279280
dfg = testDFGAPI{NoSolverParams}()
280-
verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
281+
verts = map(n -> DFGVariable(Symbol("x$n"), TestInferenceVariable1()), 1:numNodes)
281282
#change ready and backendset for x7,x8 for improved tests on x7x8f1
282283
verts[7].ready = 1
283284
verts[8].backendset = 1
284285

285-
#force softytypes to first 2 vertices.
286-
verts[1].solverDataDict[:default].softtype = deepcopy(st1)
287-
verts[2].solverDataDict[:default].softtype = deepcopy(st2)
286+
# Can't change the softtypes now.
287+
# #force softytypes to first 2 vertices.
288+
# verts[1].solverDataDict[:default].softtype = deepcopy(st1)
289+
# verts[2].solverDataDict[:default].softtype = deepcopy(st2)
288290

289291
map(v -> addVariable!(dfg, v), verts)
290292
map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol("x$(n)x$(n+1)f1"))), 1:(numNodes-1))
@@ -376,8 +378,8 @@ end
376378
@testset "Producing Dot Files" begin
377379
# create a simpler graph for dot testing
378380
dotdfg = testDFGAPI{NoSolverParams}()
379-
v1 = DFGVariable(:a)
380-
v2 = DFGVariable(:b)
381+
v1 = DFGVariable(:a, TestInferenceVariable1())
382+
v2 = DFGVariable(:b, TestInferenceVariable1())
381383
f1 = DFGFactor{Int, :Symbol}(:f1)
382384
addVariable!(dotdfg, v1)
383385
addVariable!(dotdfg, v2)

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ using Pkg
1010
# Run: docker run -d --publish=7474:7474 --publish=7687:7687 --env NEO4J_AUTH=neo4j/test neo4j
1111
##
1212

13+
# If you want to enable debugging logging (very verbose!)
14+
# logger = SimpleLogger(stdout, Logging.Debug)
15+
# global_logger(logger)
16+
1317
# Test each interface
1418
# Still test LightDFG and MetaGraphsDFG for the moment until we remove in 0.4.2
1519
apis = [

0 commit comments

Comments
 (0)