Skip to content

Commit 870e518

Browse files
authored
Merge pull request #974 from JuliaRobotics/maint/4Q20/bson
standardize serialization, final prep v0.16.1
2 parents 96c3205 + 28a98d7 commit 870e518

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ version = "0.16.1"
77
[deps]
88
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"
99
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
10+
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
1011
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
1112
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1213
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -40,6 +41,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
4041

4142
[compat]
4243
ApproxManifoldProducts = "0.1, 0.2"
44+
BSON = "0.2"
4345
Combinatorics = "1.0"
4446
DataStructures = "0.16, 0.17, 0.18"
4547
DistributedFactorGraphs = "0.10.6"
@@ -63,10 +65,9 @@ TimeZones = "1.3.1"
6365
julia = "1.4"
6466

6567
[extras]
66-
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
6768
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
6869
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
6970
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7071

7172
[targets]
72-
test = ["BSON", "Flux", "Test"]
73+
test = ["Flux", "InteractiveUtils", "Test"]

src/FactorGraph.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,21 @@ Notes
567567
- Will not work in all situations, but good enough so far.
568568
- # TODO standardize
569569
"""
570-
function calcZDim(usrfnc::T, Xi::Vector{<:DFGVariable})::Int where {T <: FunctorInferenceType}
570+
function calcZDim(usrfnc::T,
571+
Xi::Vector{<:DFGVariable},
572+
fmd::FactorMetadata=FactorMetadata()) where {T <: FunctorInferenceType}
571573
# zdim = T != GenericMarginal ? size(getSample(usrfnc, 2)[1],1) : 0
572574
zdim = if T != GenericMarginal
573575
vnds = Xi # (x->getSolverData(x)).(Xi)
574-
smpls = freshSamples(usrfnc, 2, FactorMetadata(), vnds)[1]
576+
smpls = freshSamples(usrfnc, 2, fmd, vnds)[1]
575577
size(smpls,1)
576578
else
577579
0
578580
end
579581
return zdim
580582
end
581583

584+
582585
function prepgenericconvolution(
583586
Xi::Vector{<:DFGVariable},
584587
usrfnc::T;
@@ -589,7 +592,9 @@ function prepgenericconvolution(
589592
ARR = Array{Array{Float64,2},1}()
590593
maxlen, sfidx, manis = prepareparamsarray!(ARR, Xi, nothing, 0) # Nothing for init.
591594
fldnms = fieldnames(T) # typeof(usrfnc)
592-
zdim = calcZDim(usrfnc, Xi)
595+
596+
fmd = _defaultFactorMetadata(Xi)
597+
zdim = calcZDim(usrfnc, Xi, fmd)
593598
# zdim = T != GenericMarginal ? size(getSample(usrfnc, 2)[1],1) : 0
594599
certainhypo = multihypo != nothing ? collect(1:length(multihypo.p))[multihypo.p .== 0.0] : collect(1:length(Xi))
595600
ccw = CommonConvWrapper(

src/FactorGraphTypes.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ end
137137
"""
138138
$(TYPEDEF)
139139
140-
TODO remove Union types -- issue #383
140+
DevNotes
141+
- # TODO remove Union types -- issue #383
142+
- # TODO standardize -- #927
143+
- # FIXME standardize inner constructors
141144
"""
142145
mutable struct FactorMetadata{T}
143146
factoruserdata # TODO maybe deprecate, not in use in RoME or IIF
@@ -148,14 +151,20 @@ mutable struct FactorMetadata{T}
148151
dbg::Bool #
149152
cachedata::Union{Nothing,Vector{T}} # New. Maybe change to Vector{T}
150153
fullvariables::Vector{DFGVariable}# New. Vector{DFGVariable}
151-
154+
155+
# inner constructors (delete?)
152156
FactorMetadata{T}() where T = new{T}()
153-
FactorMetadata{T}(fud, vud, vsm, sf, vl, dbg, cd, fv) where T =
154-
FactorMetadata{T}(fud, vud, vsm, sf, vl, dbg, cd, fv)
157+
FactorMetadata{T}(fud, vud, vsm, sf, vl, dbg, cd, fv) where T = new{T}(fud, vud, vsm, sf, vl, dbg, cd, fv)
155158
end
156159
FactorMetadata() = FactorMetadata{Any}()
157160
FactorMetadata(fud, vud, vsm, sf=nothing, vl=nothing, dbg=false, cd=nothing, fv=DFGVariable[]) =
158-
FactorMetadata(fud, vud, vsm, sf, vl, dbg, cd, fv)
161+
FactorMetadata{Any}(fud, vud, vsm, sf, vl, dbg, cd, fv)
162+
163+
function _defaultFactorMetadata(Xi::AbstractVector{<:DFGVariable};
164+
dbg::Bool=false)
165+
# FIXME standardize fmd, see #927
166+
FactorMetadata(nothing,[],[],nothing,map(x->x.label,Xi),dbg,nothing,copy(Xi))
167+
end
159168

160169
"""
161170
$(TYPEDEF)

src/Flux/FluxModelsSerialization.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Serialization functions for Flux models that depend on BSON
22

3-
@info "IncrementalInference is adding Flux/BSON serialization functionality."
3+
# @info "IncrementalInference is adding Flux/BSON serialization functionality."
44

55
export PackedFluxModelsDistribution
66

7-
using .BSON
87
using Base64
98

109
import Base: convert

src/IncrementalInference.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using
2424
Optim,
2525
StatsBase,
2626
JLD2,
27+
BSON,
2728
FileIO,
2829
ProgressMeter,
2930
DocStringExtensions,
@@ -500,7 +501,7 @@ function __init__()
500501
# combining neural networks natively into the non-Gaussian factor graph object
501502
@require Flux="587475ba-b771-5e3f-ad9e-33799f191a9c" begin
502503
include("Flux/FluxModelsDistribution.jl")
503-
@require BSON="fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" include("Flux/FluxModelsSerialization.jl")
504+
include("Flux/FluxModelsSerialization.jl") # uses BSON
504505
end
505506
end
506507

test/testMixturePrior.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ solveTree!(fg);
4949
marginalPts = getBelief(fg, :x0) |> getPoints
5050

5151
# check solver solution consistent too
52-
@test sum(marginalPts .< -2.5) - sum(-2.5 .< marginalPts) |> abs < 0.25*N
52+
@test sum(marginalPts .< -2.5) - sum(-2.5 .< marginalPts) |> abs < 0.3*N
5353

5454

5555
end
@@ -70,7 +70,7 @@ solveTree!(fg_);
7070
marginalPts = getBelief(fg_, :x0) |> getPoints
7171

7272
# check solver solution consistent too
73-
@test sum(marginalPts .< -2.5) - sum(-2.5 .< marginalPts) |> abs < 0.25*N
73+
@test sum(marginalPts .< -2.5) - sum(-2.5 .< marginalPts) |> abs < 0.3*N
7474

7575

7676
# cleanup

0 commit comments

Comments
 (0)