Skip to content

Commit 47b407f

Browse files
committed
move to VND
1 parent 469c22c commit 47b407f

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

src/entities/DFGVariable.jl

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ mutable struct VariableNodeData{T<:InferenceVariable}
2222
ismargin::Bool
2323
dontmargin::Bool
2424
solveInProgress::Int
25+
solvedCount::Int
2526
VariableNodeData{T}() where {T <:InferenceVariable} =
26-
new{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0)
27+
new{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0, 0)
2728
VariableNodeData{T}(val::Array{Float64,2},
2829
bw::Array{Float64,2},
2930
BayesNetOutVertIDs::Array{Symbol,1},
@@ -36,11 +37,12 @@ mutable struct VariableNodeData{T<:InferenceVariable}
3637
inferdim::Float64,
3738
ismargin::Bool,
3839
dontmargin::Bool,
39-
solveInProgress::Int=0) where T <: InferenceVariable =
40+
solveInProgress::Int=0,
41+
solvedCount::Int=0 ) where T <: InferenceVariable =
4042
new{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,
4143
eliminated,BayesNetVertID,separator,
4244
softtype::T,initialized,inferdim,ismargin,
43-
dontmargin, solveInProgress)
45+
dontmargin, solveInProgress, solvedCount)
4446
end
4547

4648
VariableNodeData(val::Array{Float64,2},
@@ -55,20 +57,21 @@ VariableNodeData(val::Array{Float64,2},
5557
inferdim::Float64,
5658
ismargin::Bool,
5759
dontmargin::Bool,
58-
solveInProgress::Int=0) where T <: InferenceVariable =
60+
solveInProgress::Int=0,
61+
solvedCount::Int=0) where T <: InferenceVariable =
5962
VariableNodeData{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,
6063
eliminated,BayesNetVertID,separator,
6164
softtype::T,initialized,inferdim,ismargin,
62-
dontmargin, solveInProgress)
65+
dontmargin, solveInProgress, solvedCount)
6366
#
6467
VariableNodeData(softtype::T) where T <: InferenceVariable =
65-
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0)
68+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0, 0)
6669

6770
function VariableNodeData()
6871
st = stacktrace()
6972
@warn "VariableNodeData() is deprecated please use VariableNodeData{T}() or VariableNodeData(softtype::T) where T <: InferenceVariable. Enable DEBUG logging for stack trace."
7073
@debug st
71-
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false, 0)
74+
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false, 0, 0)
7275
end
7376

7477

@@ -93,6 +96,7 @@ mutable struct PackedVariableNodeData
9396
ismargin::Bool
9497
dontmargin::Bool
9598
solveInProgress::Int
99+
solvedCount::Int
96100
PackedVariableNodeData() = new()
97101
PackedVariableNodeData(x1::Vector{Float64},
98102
x2::Int,
@@ -109,7 +113,8 @@ mutable struct PackedVariableNodeData
109113
x13::Float64,
110114
x14::Bool,
111115
x15::Bool,
112-
x16::Int) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16)
116+
x16::Int,
117+
solvedCount::Int) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,solvedCount)
113118
end
114119

115120
# AbstractPointParametricEst interface
@@ -150,7 +155,6 @@ mutable struct DFGVariable <: AbstractDFGVariable
150155
smallData::Dict{String, String}
151156
bigData::Dict{Symbol, AbstractBigDataEntry}
152157
solvable::Int
153-
solveCount::Ref{Int}
154158
_internalId::Int64
155159
end
156160

@@ -167,14 +171,14 @@ function DFGVariable(label::Symbol, _internalId::Int64 = 0) #where {T <:Inferenc
167171
Dict{Symbol, MeanMaxPPE}(),
168172
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData()),
169173
Dict{String, String}(),
170-
Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
174+
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)
171175
end
172176
DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where {T <: InferenceVariable} =
173177
DFGVariable(label, now(), Symbol[],
174178
Dict{Symbol, MeanMaxPPE}(),
175179
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData{T}()),
176180
Dict{String, String}(),
177-
Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
181+
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)
178182

179183
"""
180184
$(SIGNATURES)
@@ -277,13 +281,15 @@ getSofttype(v::DFGVariableSummary)::Symbol = v.softtypename
277281
"""
278282
$SIGNATURES
279283
280-
Get the number of times a variable has been inferred -- i.e. `solveCount`.
284+
Get the number of times a variable has been inferred -- i.e. `solvedCount`.
281285
282286
Related
283287
284288
isSolved, setSolved!
285289
"""
286-
getSolved(v::VariableDataLevel2) = v.solveCount[]
290+
getSolved(v::VariableNodeData) = v.solveCount
291+
getSolved(v::VariableDataLevel2, solveKey::Symbol=:default) = solverData(v, solveKey) |> getSolved
292+
getSolved(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol=:default) = getSolved(getVariable(dfg, sym), solveKey)
287293

288294
"""
289295
$SIGNATURES
@@ -294,7 +300,10 @@ Related
294300
295301
getSolved, setSolved!
296302
"""
297-
isSolved(v::VariableDataLevel2)::Bool = 0 < getSolved(v)
303+
isSolved(v::VariableNodeData) = v.solveCount
304+
isSolved(v::VariableDataLevel2, solveKey::Symbol=:default) = solverData(v, solveKey) |> isSolved
305+
isSolved(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol=:default) = isSolved(getVariable(dfg, sym), solveKey)
306+
298307

299308
"""
300309
$SIGNATURES
@@ -305,7 +314,12 @@ Related
305314
306315
getSolved, isSolved
307316
"""
308-
setSolved!(v::VariableDataLevel2, val::Int) = v.solveCount[] = val
317+
# setSolved!(v::VariableDataLevel2, val::Int) = v.solveCount[] = val
318+
# setSolved!(dfg::AbstractDFG, sym::Symbol, val::Int solveKey::Symbol=:default) = setSolved!(solverData(getVariable(dfg, sym), solveKey), val)
319+
320+
setSolved!(v::VariableNodeData, val::Int) = v.solveCount = val
321+
setSolved!(v::VariableDataLevel2, val::Int, solveKey::Symbol=:default) = setSolved!(solverData(v, solveKey), val)
322+
setSolved!(dfg::AbstractDFG, sym::Symbol, val::Int, solveKey::Symbol=:default) = setSolved!(getVariable(dfg, sym), solveKey, val)
309323

310324
"""
311325
$SIGNATURES

test/interfaceTests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ end
211211
@test !isVariable(dfg, :doesntexist)
212212
@test !isFactor(dfg, :doesntexist)
213213

214+
# test solveCount for variable
215+
@test !isSolved(v1)
216+
@test getSolved(v1) == 0
217+
setSolved!(v1, 1)
218+
@test getSolved(v1) == 1
219+
@test isSolved(v1)
220+
214221
# Session, robot, and user small data tests
215222
smallUserData = Dict{Symbol, String}(:a => "42", :b => "Hello")
216223
smallRobotData = Dict{Symbol, String}(:a => "43", :b => "Hello")

0 commit comments

Comments
 (0)