Skip to content

Commit a26c938

Browse files
committed
updateState -> copytoState
1 parent 8026e4a commit a26c938

File tree

9 files changed

+22
-120
lines changed

9 files changed

+22
-120
lines changed

IncrementalInferenceTypes/src/IncrementalInferenceTypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ include("variables/DefaultVariableTypes.jl")
5656
# Factor Definitions
5757
include("factors/DefaultPrior.jl")
5858
#FIXME maybe upgrade linear relative to this
59-
# include("factors/LinearRelative.jl")
59+
include("factors/LinearRelative.jl")
6060
include("factors/Circular.jl")
6161

6262
# Distribution Serialization

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
2121
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
2222
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
2323
FunctionalStateMachine = "3e9e306e-7e3c-11e9-12d2-8f8f67a2f951"
24+
IncrementalInferenceTypes = "9808408f-4dbc-47e4-913c-6068b950e289"
2425
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
2526
KernelDensityEstimate = "2472808a-b354-52ea-a80e-1658a3c6056d"
2627
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/Factors/DefaultPrior.jl

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
11

2-
"""
3-
$(TYPEDEF)
2+
IIFTypes.Prior(::UniformScaling) = Prior(Normal())
43

5-
Default prior on all dimensions of a variable node in the factor graph. `Prior` is
6-
not recommended when non-Euclidean dimensions are used in variables.
7-
"""
8-
struct Prior{T <: SamplableBelief} <: AbstractPrior
9-
Z::T
10-
end
11-
Prior(::UniformScaling) = Prior(Normal())
12-
13-
getManifold(pr::Prior) = TranslationGroup(getDimension(pr.Z))
144
# getSample(cf::CalcFactor{<:Prior}) = rand(cf.factor.Z)
155

166
# basic default
177
(s::CalcFactor{<:Prior})(z, x1) = z .- x1
18-
19-
## packed types are still developed by hand. Future versions would likely use a @packable macro to write Protobuf safe versions of factors
20-
21-
"""
22-
$(TYPEDEF)
23-
24-
Serialization type for Prior.
25-
"""
26-
Base.@kwdef mutable struct PackedPrior <: AbstractPackedFactor
27-
Z::PackedSamplableBelief
28-
end
29-
function convert(::Type{PackedPrior}, d::Prior)
30-
return PackedPrior(convert(PackedSamplableBelief, d.Z))
31-
end
32-
function convert(::Type{Prior}, d::PackedPrior)
33-
return Prior(convert(SamplableBelief, d.Z))
34-
end
35-
36-
function DFG.pack(d::Prior)
37-
return PackedPrior(DFG.packDistribution(d.Z))
38-
end
39-
function DFG.unpack(d::PackedPrior)
40-
return Prior(DFG.unpackDistribution(d.Z))
41-
end
42-
43-
#

src/Factors/LinearRelative.jl

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,6 @@
11

22
export LinearRelative, PackedLinearRelative
33

4-
"""
5-
$(TYPEDEF)
6-
7-
Default linear offset between two scalar variables.
8-
9-
```math
10-
X_2 = X_1 + η_Z
11-
```
12-
"""
13-
struct LinearRelative{N, T <: SamplableBelief} <: AbstractManifoldMinimize # AbstractRelativeMinimize
14-
Z::T
15-
end
16-
17-
# need several helper constructors since the dimension over which LinearRelative will be used is unknown at this point
18-
function LinearRelative{N}(
19-
z0::T = MvNormal(zeros(N), diagm(ones(N))),
20-
) where {N, T <: SamplableBelief}
21-
#
22-
return LinearRelative{N, T}(z0)
23-
end
24-
25-
function LinearRelative(::UniformScaling = LinearAlgebra.I)
26-
return LinearRelative{1}(MvNormal(zeros(1), diagm(ones(1))))
27-
end
28-
function LinearRelative(nm::Distributions.ContinuousUnivariateDistribution)
29-
return LinearRelative{1, typeof(nm)}(nm)
30-
end
31-
LinearRelative(nm::MvNormal) = LinearRelative{length(nm.μ), typeof(nm)}(nm)
32-
function LinearRelative(nm::Union{<:BallTreeDensity, <:ManifoldKernelDensity})
33-
return LinearRelative{Ndim(nm), typeof(nm)}(nm)
34-
end
35-
36-
getManifold(::InstanceType{LinearRelative{N}}) where {N} = getManifold(ContinuousEuclid{N})
37-
384
# TODO standardize
395
getDimension(::InstanceType{LinearRelative{N}}) where {N} = N
406

@@ -55,24 +21,3 @@ function Base.convert(
5521
return Manifolds.TranslationGroup(N)
5622
end
5723

58-
"""
59-
$(TYPEDEF)
60-
Serialization type for `LinearRelative` binary factor.
61-
"""
62-
Base.@kwdef mutable struct PackedLinearRelative <: AbstractPackedFactor
63-
Z::PackedSamplableBelief
64-
end
65-
function convert(::Type{PackedLinearRelative}, d::LinearRelative)
66-
return PackedLinearRelative(convert(PackedSamplableBelief, d.Z))
67-
end
68-
function convert(::Type{LinearRelative}, d::PackedLinearRelative)
69-
return LinearRelative(convert(SamplableBelief, d.Z))
70-
end
71-
function DFG.pack(d::LinearRelative)
72-
return PackedLinearRelative(DFG.packDistribution(d.Z))
73-
end
74-
function DFG.unpack(d::PackedLinearRelative)
75-
return LinearRelative(DFG.unpackDistribution(d.Z))
76-
end
77-
78-
#

src/IncrementalInference.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ const BeliefArray{T} = Union{<:AbstractMatrix{<:T}, <:Adjoint{<:T, AbstractMatri
102102
# FIXME, remove this and let the user do either import or const definitions
103103
export KDE, AMP, DFG, FSM, IIF
104104

105-
include("../IncrementalInferenceTypes/src/IncrementalInferenceTypes.jl")
106-
using ..IncrementalInferenceTypes
105+
# include("../IncrementalInferenceTypes/src/IncrementalInferenceTypes.jl")
106+
@reexport using IncrementalInferenceTypes
107107

108108
# TODO temporary for initial version of on-manifold products
109109
KDE.setForceEvalDirect!(true)
@@ -175,7 +175,6 @@ include("services/TreeBasedInitialization.jl")
175175

176176
# included variables of IIF, easy to extend in user's context
177177
include("Variables/DefaultVariables.jl")
178-
include("Variables/Circular.jl")
179178

180179
# included factors, see RoME.jl for more examples
181180
include("Factors/GenericFunctions.jl")

src/Serialization/services/SerializationMKD.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function parchDistribution(mkd::ManifoldKernelDensity)
4343
end
4444

4545
# Data converters for MKD
46-
function packDistribution(mkd::ManifoldKernelDensity)
46+
function DFG.packDistribution(mkd::ManifoldKernelDensity)
4747
#
4848
pts = getPoints(mkd)
4949

@@ -58,7 +58,7 @@ function packDistribution(mkd::ManifoldKernelDensity)
5858
)
5959
end
6060

61-
function unpackDistribution(dtr::PackedManifoldKernelDensity)
61+
function DFG.unpackDistribution(dtr::PackedManifoldKernelDensity)
6262
# find InferenceVariable type from string (anything Manifolds.jl?)
6363
M = DFG.getTypeFromSerializationModule(dtr.varType) |> getManifold
6464
vecP = [AMP.makePointFromCoords(M, pt) for pt in dtr.pts]

src/Variables/Circular.jl

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/services/GraphInit.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ function resetInitialValues!(
448448
for vs in varList
449449
vnd = getVariableState(getVariable(src, vs), initKey)
450450
# guess we definitely want to use copy to preserve the initKey memory
451-
updateVariableSolverData!(dest, vs, vnd, solveKey, true; warn_if_absent = false)
451+
# updateVariableSolverData!(dest, vs, vnd, solveKey, true; warn_if_absent = false)
452+
DFG.copytoVariableState!(
453+
dest,
454+
vs,
455+
solveKey,
456+
vnd,
457+
)
452458
end
453459
return dest
454460
end

src/services/SubGraphFunctions.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,17 @@ function transferUpdateSubGraph!(
142142
end
143143

144144
# transfer specific fields into dest from src
145-
for var in (x -> getVariable(src, x)).(syms)
146-
# copy not required since a broadcast is used internally
147-
updateVariableSolverData!(
145+
@time for var in (x -> getVariable(src, x)).(syms)
146+
# NOTE compared copytoVariableState! vs surgical updateVariableSolverData!
147+
# updateVariableSolverData! 0.000626 seconds (1.11 k allocations: 114.289 KiB)
148+
# copytoVariableState! 0.000099 seconds (315 allocations: 27.758 KiB)
149+
DFG.copytoVariableState!(
148150
dest,
149-
var,
151+
getLabel(var),
150152
solveKey,
151-
false,
152-
[:val; :bw; :infoPerCoord; :solvedCount; :initialized];
153-
warn_if_absent = false,
153+
getVariableState(var, solveKey),
154154
)
155+
155156
if updatePPE
156157
# create ppe on new key using defaults, TODO improve
157158
if haskey(getPPEDict(var), solveKey)

0 commit comments

Comments
 (0)