|
2 | 2 | using IncrementalInference |
3 | 3 | using Test |
4 | 4 |
|
| 5 | +## |
| 6 | + |
5 | 7 | @testset "saving to and loading from FileDFG" begin |
| 8 | +## |
| 9 | + |
| 10 | +fg = generateCanonicalFG_Kaess() |
| 11 | +addVariable!(fg, :x4, ContinuousScalar) |
| 12 | +addFactor!(fg, [:x2;:x3;:x4], LinearRelative(Normal()), multihypo=[1.0;0.6;0.4]) |
6 | 13 |
|
7 | | - fg = generateCanonicalFG_Kaess() |
8 | | - addVariable!(fg, :x4, ContinuousScalar) |
9 | | - addFactor!(fg, [:x2;:x3;:x4], LinearRelative(Normal()), multihypo=[1.0;0.6;0.4]) |
| 14 | +saveFolder = "/tmp/dfg_test" |
| 15 | +saveDFG(fg, saveFolder) |
| 16 | +# VERSION above 1.0.x hack required since Julia 1.0 does not seem to havfunction `splitpath` |
10 | 17 |
|
11 | | - saveFolder = "/tmp/dfg_test" |
12 | | - saveDFG(fg, saveFolder) |
13 | | - # VERSION above 1.0.x hack required since Julia 1.0 does not seem to havfunction `splitpath` |
14 | | - if v"1.1" <= VERSION |
15 | | - retDFG = initfg() |
16 | | - retDFG = loadDFG!(retDFG, saveFolder) |
17 | | - Base.rm(saveFolder*".tar.gz") |
| 18 | +retDFG = initfg() |
| 19 | +retDFG = loadDFG!(retDFG, saveFolder) |
| 20 | +Base.rm(saveFolder*".tar.gz") |
18 | 21 |
|
19 | | - @test symdiff(ls(fg), ls(retDFG)) == [] |
20 | | - @test symdiff(lsf(fg), lsf(retDFG)) == [] |
| 22 | +@test symdiff(ls(fg), ls(retDFG)) == [] |
| 23 | +@test symdiff(lsf(fg), lsf(retDFG)) == [] |
21 | 24 |
|
22 | | - @show getFactor(fg, :x2x3x4f1).solverData.multihypo |
23 | | - @show getFactor(retDFG, :x2x3x4f1).solverData.multihypo |
| 25 | +@show getFactor(fg, :x2x3x4f1).solverData.multihypo |
| 26 | +@show getFactor(retDFG, :x2x3x4f1).solverData.multihypo |
24 | 27 |
|
25 | | - # check for match |
26 | | - @test getFactor(fg, :x2x3x4f1).solverData.multihypo - getFactor(retDFG, :x2x3x4f1).solverData.multihypo |> norm < 1e-10 |
27 | | - @test getFactor(fg, :x2x3x4f1).solverData.certainhypo - getFactor(retDFG, :x2x3x4f1).solverData.certainhypo |> norm < 1e-10 |
28 | | - end |
| 28 | +# check for match |
| 29 | +@test getFactor(fg, :x2x3x4f1).solverData.multihypo - getFactor(retDFG, :x2x3x4f1).solverData.multihypo |> norm < 1e-10 |
| 30 | +@test getFactor(fg, :x2x3x4f1).solverData.certainhypo - getFactor(retDFG, :x2x3x4f1).solverData.certainhypo |> norm < 1e-10 |
29 | 31 |
|
| 32 | +## |
30 | 33 | end |
31 | 34 |
|
32 | 35 |
|
33 | 36 | @testset "saving to and loading from FileDFG with nullhypo, eliminated, solveInProgress" begin |
34 | | - fg = generateCanonicalFG_Kaess() |
35 | | - addVariable!(fg, :x4, ContinuousScalar) |
36 | | - addFactor!(fg, [:x2;:x3;:x4], LinearRelative(Normal()), multihypo=[1.0;0.6;0.4]) |
37 | | - addFactor!(fg, [:x1;], Prior(Normal(10,1)), nullhypo=0.5) |
| 37 | +## |
| 38 | + |
| 39 | +fg = generateCanonicalFG_Kaess() |
| 40 | +addVariable!(fg, :x4, ContinuousScalar) |
| 41 | +addFactor!(fg, [:x2;:x3;:x4], LinearRelative(Normal()), multihypo=[1.0;0.6;0.4]) |
| 42 | +addFactor!(fg, [:x1;], Prior(Normal(10,1)), nullhypo=0.5) |
| 43 | + |
| 44 | +solveTree!(fg) |
38 | 45 |
|
39 | | - solveTree!(fg) |
| 46 | +#manually change a few fields to test if they are preserved |
| 47 | +fa = getFactor(fg, :x2x3x4f1) |
| 48 | +fa.solverData.eliminated = true |
| 49 | +fa.solverData.solveInProgress = 1 |
| 50 | +fa.solverData.nullhypo = 0.5 |
40 | 51 |
|
41 | | - #manually change a few fields to test if they are preserved |
42 | | - fa = getFactor(fg, :x2x3x4f1) |
43 | | - fa.solverData.eliminated = true |
44 | | - fa.solverData.solveInProgress = 1 |
45 | | - fa.solverData.nullhypo = 0.5 |
46 | 52 |
|
| 53 | +saveFolder = "/tmp/dfg_test" |
| 54 | +saveDFG(fg, saveFolder) |
47 | 55 |
|
48 | | - saveFolder = "/tmp/dfg_test" |
49 | | - saveDFG(fg, saveFolder) |
| 56 | +retDFG = initfg() |
| 57 | +loadDFG!(retDFG, saveFolder) |
| 58 | +Base.rm(saveFolder*".tar.gz") |
50 | 59 |
|
51 | | - retDFG = initfg() |
52 | | - loadDFG!(retDFG, saveFolder) |
53 | | - Base.rm(saveFolder*".tar.gz") |
| 60 | +@test issetequal(ls(fg), ls(retDFG)) |
| 61 | +@test issetequal(lsf(fg), lsf(retDFG)) |
54 | 62 |
|
55 | | - @test issetequal(ls(fg), ls(retDFG)) |
56 | | - @test issetequal(lsf(fg), lsf(retDFG)) |
| 63 | +@show getFactor(fg, :x2x3x4f1).solverData.multihypo |
| 64 | +@show getFactor(retDFG, :x2x3x4f1).solverData.multihypo |
57 | 65 |
|
58 | | - @show getFactor(fg, :x2x3x4f1).solverData.multihypo |
59 | | - @show getFactor(retDFG, :x2x3x4f1).solverData.multihypo |
| 66 | +# check for match |
| 67 | +@test isapprox(getFactor(fg, :x2x3x4f1).solverData.multihypo, getFactor(retDFG, :x2x3x4f1).solverData.multihypo) |
| 68 | +@test isapprox(getFactor(fg, :x2x3x4f1).solverData.certainhypo, getFactor(retDFG, :x2x3x4f1).solverData.certainhypo) |
60 | 69 |
|
61 | | - # check for match |
62 | | - @test isapprox(getFactor(fg, :x2x3x4f1).solverData.multihypo, getFactor(retDFG, :x2x3x4f1).solverData.multihypo) |
63 | | - @test isapprox(getFactor(fg, :x2x3x4f1).solverData.certainhypo, getFactor(retDFG, :x2x3x4f1).solverData.certainhypo) |
64 | 70 |
|
| 71 | +fb = getFactor(retDFG, :x2x3x4f1) |
| 72 | +@test fa == fb |
65 | 73 |
|
66 | | - fb = getFactor(retDFG, :x2x3x4f1) |
67 | | - @test fa == fb |
| 74 | +fa = getFactor(fg, :x1f2) |
| 75 | +fb = getFactor(retDFG, :x1f2) |
68 | 76 |
|
69 | | - fa = getFactor(fg, :x1f2) |
70 | | - fb = getFactor(retDFG, :x1f2) |
| 77 | +@test fa == fb |
71 | 78 |
|
72 | | - @test fa == fb |
| 79 | +## |
73 | 80 | end |
74 | 81 |
|
0 commit comments