Skip to content

Commit 9f14979

Browse files
committed
deprecate variableType and add covar
1 parent 7d3712f commit 9f14979

File tree

8 files changed

+81
-95
lines changed

8 files changed

+81
-95
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2020
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2121
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2222
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
23+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2324
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
2425
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
2526
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export AbstractManifold, manifold_dimension
3838

3939
import RecursiveArrayTools: ArrayPartition
4040
export ArrayPartition
41+
using StaticArrays
4142

4243
import Base: getindex
4344

src/entities/DFGVariable.jl

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ $(TYPEDEF)
1313
Data container for solver-specific data.
1414
1515
---
16+
T: Variable type, such as Position1, or RoME.Pose2, etc.
17+
P: Variable point type, the type of the manifold point.
18+
N: Manifold dimension.
1619
Fields:
1720
$(TYPEDFIELDS)
1821
"""
19-
Base.@kwdef mutable struct VariableNodeData{T<:InferenceVariable, P}
22+
Base.@kwdef mutable struct VariableNodeData{T<:InferenceVariable, P, N}
23+
"DEPRECATED remove in DFG v0.21"
24+
variableType::T=T() #tricky deprecation, also change covar to using N and not variableType
2025
"""
2126
Globally unique identifier.
2227
"""
@@ -29,6 +34,8 @@ Base.@kwdef mutable struct VariableNodeData{T<:InferenceVariable, P}
2934
Common kernel bandwith parameter used with ManifoldKernelDensity, and as legacy also stores covariance until a dedicated field is created for parametric case.
3035
"""
3136
bw::Matrix{Float64} = zeros(0,0)
37+
"Parametric (Gaussian) covariance."
38+
const covar::Vector{SMatrix{N, N, Float64}} = SMatrix{getDimension(variableType), getDimension(variableType), Float64}[]
3239
BayesNetOutVertIDs::Vector{Symbol} = Symbol[]
3340
dimIDs::Vector{Int} = Int[] # TODO Likely deprecate
3441

@@ -40,10 +47,6 @@ Base.@kwdef mutable struct VariableNodeData{T<:InferenceVariable, P}
4047
BayesNetVertID::Symbol = :NOTHING # Union{Nothing, }
4148
separator::Vector{Symbol} = Symbol[]
4249
"""
43-
Variables each have a type, such as Position1, or RoME.Pose2, etc.
44-
"""
45-
variableType::T = T()
46-
"""
4750
False if initial numerical values are not yet available or stored values are not ready for further processing yet.
4851
"""
4952
initialized::Bool = false
@@ -81,8 +84,8 @@ end
8184

8285
##------------------------------------------------------------------------------
8386
## Constructors
84-
VariableNodeData{T}(; kwargs...) where T <: InferenceVariable = VariableNodeData{T,getPointType(T)}(; kwargs...)
85-
VariableNodeData(variableType::InferenceVariable; kwargs...) = VariableNodeData{typeof(variableType)}(; kwargs...)
87+
VariableNodeData{T}(; kwargs...) where T <: InferenceVariable = VariableNodeData{T,getPointType(T),getDimension(T)}(; kwargs...)
88+
VariableNodeData(variableType::InferenceVariable; kwargs...) = VariableNodeData{typeof(variableType)}(;kwargs...)
8689

8790

8891
##==============================================================================
@@ -209,35 +212,35 @@ Complete variable structure for a DistributedFactorGraph variable.
209212
Fields:
210213
$(TYPEDFIELDS)
211214
"""
212-
Base.@kwdef struct DFGVariable{T<:InferenceVariable, P} <: AbstractDFGVariable
215+
Base.@kwdef struct DFGVariable{T<:InferenceVariable, P, N} <: AbstractDFGVariable
213216
"""The ID for the variable"""
214-
id::Union{UUID, Nothing}
217+
id::Union{UUID, Nothing} = nothing
215218
"""Variable label, e.g. :x1.
216219
Accessor: [`getLabel`](@ref)"""
217220
label::Symbol
218221
"""Variable timestamp.
219222
Accessors: [`getTimestamp`](@ref), [`setTimestamp`](@ref)"""
220-
timestamp::ZonedDateTime
223+
timestamp::ZonedDateTime = now(localzone())
221224
"""Nano second time, for more resolution on timestamp (only subsecond information)"""
222-
nstime::Nanosecond
225+
nstime::Nanosecond = Nanosecond(0)
223226
"""Variable tags, e.g [:POSE, :VARIABLE, and :LANDMARK].
224227
Accessors: [`getTags`](@ref), [`mergeTags!`](@ref), and [`removeTags!`](@ref)"""
225-
tags::Set{Symbol}
228+
tags::Set{Symbol} = Set{Symbol}()
226229
"""Dictionary of parametric point estimates keyed by solverDataDict keys
227230
Accessors: [`addPPE!`](@ref), [`updatePPE!`](@ref), and [`deletePPE!`](@ref)"""
228-
ppeDict::Dict{Symbol, <: AbstractPointParametricEst}
231+
ppeDict::Dict{Symbol, AbstractPointParametricEst} = Dict{Symbol, AbstractPointParametricEst}()
229232
"""Dictionary of solver data. May be a subset of all solutions if a solver key was specified in the get call.
230233
Accessors: [`addVariableSolverData!`](@ref), [`updateVariableSolverData!`](@ref), and [`deleteVariableSolverData!`](@ref)"""
231-
solverDataDict::Dict{Symbol, VariableNodeData{T,P}}
234+
solverDataDict::Dict{Symbol, VariableNodeData{T,P,N}} = Dict{Symbol, VariableNodeData{T,P,N}}()
232235
"""Dictionary of small data associated with this variable.
233236
Accessors: [`getSmallData`](@ref), [`setSmallData!`](@ref)"""
234-
smallData::Dict{Symbol, SmallDataTypes}
237+
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
235238
"""Dictionary of large data associated with this variable.
236-
Accessors: [`addDataEntry!`](@ref), [`getBlobEntry`](@ref), [`updateDataEntry!`](@ref), and [`deleteDataEntry!`](@ref)"""
237-
dataDict::Dict{Symbol, BlobEntry}
239+
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`updateBlobEntry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
240+
dataDict::Dict{Symbol, BlobEntry} = Dict{Symbol, BlobEntry}()
238241
"""Solvable flag for the variable.
239242
Accessors: [`getSolvable`](@ref), [`setSolvable!`](@ref)"""
240-
solvable::Base.RefValue{Int}
243+
solvable::Base.RefValue{Int} = Ref(1)
241244
end
242245

243246
##------------------------------------------------------------------------------
@@ -247,43 +250,34 @@ end
247250
$SIGNATURES
248251
The default DFGVariable constructor.
249252
"""
250-
function DFGVariable(label::Symbol, variableType::Type{T};
251-
id::Union{UUID,Nothing}=nothing,
252-
timestamp::ZonedDateTime=now(localzone()),
253-
nstime::Nanosecond = Nanosecond(0),
254-
tags::Set{Symbol}=Set{Symbol}(),
255-
estimateDict::Dict{Symbol, <: AbstractPointParametricEst}=Dict{Symbol, MeanMaxPPE}(),
256-
solverDataDict::Dict{Symbol, VariableNodeData{T,P}}=Dict{Symbol, VariableNodeData{T,getPointType(T)}}(),
257-
smallData::Dict{Symbol, SmallDataTypes}=Dict{Symbol, SmallDataTypes}(),
258-
dataDict::Dict{Symbol, BlobEntry}=Dict{Symbol,BlobEntry}(),
259-
solvable::Int=1) where {T <: InferenceVariable, P}
260-
#
261-
DFGVariable{T,P}(id, label, timestamp, nstime, tags, estimateDict, solverDataDict, smallData, dataDict, Ref(solvable))
262-
end
253+
function DFGVariable(
254+
label::Symbol,
255+
T::Type{<:InferenceVariable};
256+
estimateDict=nothing,
257+
timestamp=now(localzone()),
258+
solvable::Union{Int, Base.RefValue{Int}}=Ref(1),
259+
kwargs...
260+
)
261+
#TODO deprecated, remove in v0.21 should have already been deprecated
262+
if !isnothing(estimateDict)
263+
error("Keyword argument `estimateDict` is deprecated use `ppeDict`")
264+
end
265+
if !isa(timestamp, ZonedDateTime)
266+
@warn "timestamp<:DateTime is deprecated, timestamp must be a ZonedDateTime, using local zone."
267+
timestamp = ZonedDateTime(timestamp,localzone())
268+
end
263269

264-
DFGVariable(label::Symbol,
265-
variableType::T;
266-
solverDataDict::Dict{Symbol, VariableNodeData{T,P}}=Dict{Symbol, VariableNodeData{T,getPointType(T)}}(),
267-
kw...) where {T <: InferenceVariable, P} = DFGVariable(label, T; solverDataDict=solverDataDict, kw...)
268-
#
269-
@deprecate DFGVariable(label::Symbol, T_::Type{<:InferenceVariable},w...; timestamp::DateTime=now(),kw...) DFGVariable(label, T_, w...; timestamp=ZonedDateTime(timestamp), kw...)
270-
#
271-
272-
273-
function DFGVariable(label::Symbol,
274-
solverData::VariableNodeData{T};
275-
id::Union{UUID, Nothing} = nothing,
276-
timestamp::ZonedDateTime = now(localzone()),
277-
nstime::Nanosecond = Nanosecond(0),
278-
tags::Set{Symbol}=Set{Symbol}(),
279-
estimateDict::Dict{Symbol, <: AbstractPointParametricEst}=Dict{Symbol, MeanMaxPPE}(),
280-
smallData::Dict{Symbol, SmallDataTypes}=Dict{Symbol, SmallDataTypes}(),
281-
dataDict::Dict{Symbol, <: BlobEntry}=Dict{Symbol,BlobEntry}(),
282-
solvable::Int=1) where {T <: InferenceVariable}
283-
#
284-
DFGVariable{T}(id, label, timestamp, nstime, tags, estimateDict, Dict{Symbol, VariableNodeData{T, getPointType(T)}}(:default=>solverData), smallData, dataDict, Ref(solvable))
270+
solvable isa Int && (solvable = Ref(solvable))
271+
272+
N = getDimension(T)
273+
P = getPointType(T)
274+
DFGVariable{T,P,N}(;label, timestamp, solvable, kwargs...)
285275
end
286276

277+
DFGVariable(label::Symbol, variableType::InferenceVariable; kwargs...) = DFGVariable(label, typeof(variableType); kwargs...)
278+
279+
DFGVariable(label::Symbol, solverData::VariableNodeData; kwargs...) = DFGVariable(;label, solverDataDict=Dict(:default=>solverData), kwargs...)
280+
287281
Base.getproperty(x::DFGVariable,f::Symbol) = begin
288282
if f == :solvable
289283
getfield(x,f)[]
@@ -301,14 +295,6 @@ Base.setproperty!(x::DFGVariable,f::Symbol, val) = begin
301295
end
302296

303297

304-
##------------------------------------------------------------------------------
305-
# TODO: can't see the reason to overwrite copy, leaving it here for now
306-
# function Base.copy(o::DFGVariable)::DFGVariable
307-
# return DFGVariable(o.label, getVariableType(o)(), tags=copy(o.tags), estimateDict=copy(o.estimateDict),
308-
# solverDataDict=copy(o.solverDataDict), smallData=copy(o.smallData),
309-
# dataDict=copy(o.dataDict), solvable=getSolvable(o))
310-
# end
311-
312298
##------------------------------------------------------------------------------
313299
## DFGVariableSummary lv1
314300
##------------------------------------------------------------------------------

src/services/CompareUtils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function compare(a::VariableNodeData, b::VariableNodeData)
175175
a.ismargin != b.ismargin && @debug("ismargin is not equal")==nothing && return false
176176
a.dontmargin != b.dontmargin && @debug("dontmargin is not equal")==nothing && return false
177177
a.solveInProgress != b.solveInProgress && @debug("solveInProgress is not equal")==nothing && return false
178-
typeof(a.variableType) != typeof(b.variableType) && @debug("variableType is not equal")==nothing && return false
178+
getVariableType(a) != getVariableType(b) && @debug("variableType is not equal")==nothing && return false
179179
return true
180180
end
181181

@@ -204,8 +204,8 @@ function compareVariable(A::DFGVariable,
204204
varskiplist = union(varskiplist, [:variableType])
205205
union!(varskiplist, skip)
206206
TP = TP && compareAll(Ad, Bd, skip=varskiplist, show=show)
207-
TP = TP && typeof(Ad.variableType) == typeof(Bd.variableType)
208-
TP = TP && compareAll(Ad.variableType, Bd.variableType, show=show, skip=skip)
207+
TP = TP && typeof(getVariableType(Ad)) == typeof(getVariableType(Bd))
208+
TP = TP && compareAll(getVariableType(Ad), getVariableType(Bd), show=show, skip=skip)
209209
return TP
210210
end
211211

src/services/DFGVariable.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ Related
4848
4949
getVariableType
5050
"""
51-
getVariableType(v::DFGVariable{T}) where T <: InferenceVariable = T()
51+
getVariableType(::DFGVariable{T}) where T = T()
52+
53+
getVariableType(::VariableNodeData{T}) where T = T()
5254

53-
function getVariableType(vnd::VariableNodeData)
54-
# @warn "getVariableType(::VariableNodeData) is being deprecated, use getVariableType(::DFGVariable) instead."
55-
return vnd.variableType
56-
end
5755

5856

5957
# TODO: Confirm that we can switch this out, instead of retrieving the complete variable.

src/services/Serialization.jl

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ end
7373

7474
# returns a PackedVariableNodeData
7575
function packVariableNodeData(d::VariableNodeData{T}) where {T <: InferenceVariable}
76-
@debug "Dispatching conversion variable -> packed variable for type $(string(d.variableType))"
76+
@debug "Dispatching conversion variable -> packed variable for type $(string(getVariableType(d)))"
7777
castval = if 0 < length(d.val)
7878
precast = getCoordinates.(T, d.val)
7979
@cast castval[i,j] := precast[j][i]
@@ -87,7 +87,7 @@ function packVariableNodeData(d::VariableNodeData{T}) where {T <: InferenceVaria
8787
d.BayesNetOutVertIDs,
8888
d.dimIDs, d.dims, d.eliminated,
8989
d.BayesNetVertID, d.separator,
90-
typeModuleName(d.variableType),
90+
typeModuleName(getVariableType(d)),
9191
d.initialized,
9292
d.infoPerCoord,
9393
d.ismargin,
@@ -121,25 +121,25 @@ function unpackVariableNodeData(d::PackedVariableNodeData)
121121
BW = reshape(d.vecbw,r4,c4)
122122

123123
#
124-
return VariableNodeData{T, getPointType(T)}(
125-
d.id,
126-
vals,
127-
BW,
128-
Symbol.(d.BayesNetOutVertIDs),
129-
d.dimIDs,
130-
d.dims,
131-
d.eliminated,
132-
Symbol(d.BayesNetVertID),
133-
Symbol.(d.separator),
134-
T(),
135-
d.initialized,
136-
d.infoPerCoord,
137-
d.ismargin,
138-
d.dontmargin,
139-
d.solveInProgress,
140-
d.solvedCount,
141-
Symbol(d.solveKey),
142-
Dict{Symbol,Threads.Condition}() )
124+
return VariableNodeData{T, getPointType(T), getDimension(T)}(;
125+
id = d.id,
126+
val = vals,
127+
bw = BW,
128+
# covar = #FIXME serialize covar
129+
BayesNetOutVertIDs = Symbol.(d.BayesNetOutVertIDs),
130+
dimIDs = d.dimIDs,
131+
dims = d.dims,
132+
eliminated = d.eliminated,
133+
BayesNetVertID = Symbol(d.BayesNetVertID),
134+
separator = Symbol.(d.separator),
135+
initialized = d.initialized,
136+
infoPerCoord = d.infoPerCoord,
137+
ismargin = d.ismargin,
138+
dontmargin = d.dontmargin,
139+
solveInProgress = d.solveInProgress,
140+
solvedCount = d.solvedCount,
141+
solveKey = Symbol(d.solveKey),
142+
events = Dict{Symbol,Threads.Condition}() )
143143
end
144144

145145
##==============================================================================
@@ -178,13 +178,13 @@ function unpackVariable(variable::PackedVariable; skipVersionCheck::Bool=false)
178178
metadata = JSON3.read(base64decode(variable.metadata), Dict{Symbol, DFG.SmallDataTypes})
179179

180180
return DFGVariable(
181-
id = variable.id,
182181
variable.label,
183-
variableType,
182+
variableType;
183+
id = variable.id,
184184
timestamp=variable.timestamp,
185185
nstime=Nanosecond(variable.nstime),
186186
tags=Set(variable.tags),
187-
estimateDict=ppeDict,
187+
ppeDict=ppeDict,
188188
solverDataDict=solverDict,
189189
smallData=metadata,
190190
dataDict=dataDict,

test/interfaceTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
if DistributedFactorGraphs._getDFGVersion() < v"0.19"
6666
@test String(take!(iobuf)) == "DFGVariable{TestVariableType1}\nid:\nnothing\nlabel:\n:a\ntags:\nSet([:VARIABLE, :POSE])\nsmallData:\nDict{Symbol, Union{Bool, Float64, Int64, Vector{Bool}, Vector{Float64}, Vector{Int64}, Vector{String}, String}}(:small=>\"data\")\ndataDict:\nDict{Symbol, DistributedFactorGraphs.BlobEntry}()\nsolvable:\n0\n"
6767
else
68-
@test String(take!(iobuf)) == "DFGVariable{TestVariableType1}\nid:\nnothing\nlabel:\n:a\ntags:\nSet([:VARIABLE, :POSE])\nsmallData:\nDict{Symbol, Union{Bool, Float64, Int64, Vector{Bool}, Vector{Float64}, Vector{Int64}, Vector{String}, String}}(:small=>\"data\")\ndataDict:\nDict{Symbol, BlobEntry}()\nsolvable:\n0\n"
68+
@test String(take!(iobuf)) == "DFGVariable{TestVariableType1, Vector{Float64}, 1}\nid:\nnothing\nlabel:\n:a\ntags:\nSet([:VARIABLE, :POSE])\nsmallData:\nDict{Symbol, Union{Bool, Float64, Int64, Vector{Bool}, Vector{Float64}, Vector{Int64}, Vector{String}, String}}(:small=>\"data\")\ndataDict:\nDict{Symbol, BlobEntry}()\nsolvable:\n0\n"
6969
end
7070

7171
@test printVariable(iobuf, var1, short=true) === nothing

test/testBlocks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ function VSDTestBlock!(fg, v1)
741741

742742
altVnd = vnd |> deepcopy
743743
keepVnd = getSolverData(getVariable(fg, :a), :parametric) |> deepcopy
744-
altVnd.infoPerCoord = [-99.0;]
744+
altVnd.infoPerCoord .= [-99.0;]
745745
retVnd = updateVariableSolverData!(fg, :a, altVnd, false, [:infoPerCoord;])
746746
@test retVnd == altVnd
747747

@@ -1639,7 +1639,7 @@ function FileDFGTestBlock(testDFGAPI; kwargs...)
16391639
vnd.dims = 1
16401640
vnd.dontmargin = true
16411641
vnd.eliminated = true
1642-
vnd.infoPerCoord = Float64[1.5;]
1642+
vnd.infoPerCoord .= Float64[1.5;]
16431643
vnd.initialized = true
16441644
vnd.ismargin = true
16451645
push!(vnd.separator, :sep)

0 commit comments

Comments
 (0)