diff --git a/test/interfaceTests.jl b/test/interfaceTests.jl index 516e001d..6ecc1166 100644 --- a/test/interfaceTests.jl +++ b/test/interfaceTests.jl @@ -219,6 +219,30 @@ end end end +@testset "Mixing Compute and DFG graph nodes" begin + com_fg = testDFGAPI() + pac_fg = testDFGAPI{NoSolverParams, VariableDFG, FactorDFG}() + + v = addVariable!(com_fg, var1) + @test v == var1 + pv = addVariable!(pac_fg, v) + @test packVariable(v) == pv + + pv = addVariable!(pac_fg, var2) + @test unpackVariable(pv) == var2 + v = addVariable!(com_fg, pv) + @test v == var2 + + f = addFactor!(com_fg, fac0) + @test f == fac0 + pf = addFactor!(pac_fg, f) + @test packFactor(f) == pf + + pf = addFactor!(pac_fg, fac1) + @test unpackFactor(pf) == fac1 + f = addFactor!(com_fg, pf) + @test f == fac1 +end #= fg = fg1 v1 = var1 diff --git a/test/runtests.jl b/test/runtests.jl index 2e041d32..6dbf241b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -63,6 +63,8 @@ end if get(ENV, "IIF_TEST", "true") == "true" # Switch to our upstream test branch. + #FIXME This is a temporary fix to use the develop branch of AMP. + Pkg.add(PackageSpec(; name = "ApproxManifoldProducts", rev = "develop")) #FIXME This is a temporary fix to use the develop branch of IIF. # Pkg.add(PackageSpec(; name = "IncrementalInference", rev = "upstream/dfg_integration_test")) # Pkg.add(PackageSpec(; name = "IncrementalInference", rev = "develop")) diff --git a/test/testBlocks.jl b/test/testBlocks.jl index b8d2258f..afea6dbb 100644 --- a/test/testBlocks.jl +++ b/test/testBlocks.jl @@ -1,7 +1,9 @@ using DistributedFactorGraphs using Test using Dates -using Manifolds +using LieGroups +using LieGroups: TranslationGroup +# using Manifolds using DistributedFactorGraphs: LabelExistsError, @@ -13,61 +15,32 @@ using DistributedFactorGraphs: import Base: convert # import DistributedFactorGraphs: getData, addData!, updateData!, deleteData! -Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(1))) = (:Euclid,) -Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(2))) = (:Euclid, :Euclid) +# Base.convert(::Type{<:Tuple}, ::typeof(TranslationGroup(1))) = (:Euclid,) +# Base.convert(::Type{<:Tuple}, ::typeof(TranslationGroup(2))) = (:Euclid, :Euclid) -@defVariable TestVariableType1 Euclidean(1) [0.0;] -DFG.@defStateTypeN TestVariableType{N} Euclidean(N) zeros(N) +# define a few varaible to use +@defVariable TestVariableType1 TranslationGroup(1) [0.0;] +DFG.@defStateTypeN TestVariableType{N} TranslationGroup(N) zeros(N) const TestVariableType2 = TestVariableType{2} -struct TestFunctorInferenceType1 <: AbstractRelative end -struct TestFunctorInferenceType2 <: AbstractRelative end +# define a few factor types to use +DFG.@defObservationType TestFunctorInferenceType1 RelativeObservation TranslationGroup(1) +DFG.@defObservationType TestFunctorInferenceType2 RelativeObservation TranslationGroup(1) +DFG.@defObservationType TestAbstractPrior PriorObservation TranslationGroup(1) -struct TestAbstractPrior <: PriorObservation end -# struct TestAbstractRelativeFactor <: AbstractRelativeRoots end -struct TestAbstractRelativeFactorMinimize <: RelativeObservation end +TestFunctorInferenceType1() = TestFunctorInferenceType1(nothing) +TestFunctorInferenceType2() = TestFunctorInferenceType2(nothing) +TestAbstractPrior() = TestAbstractPrior(nothing) -Base.@kwdef struct PackedTestFunctorInferenceType1 <: AbstractPackedObservation - s::String = "" -end -# PackedTestFunctorInferenceType1() = PackedTestFunctorInferenceType1("") - -function Base.convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1) - # @info "convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)" - return PackedTestFunctorInferenceType1() -end - -function DFG.reconstFactorData( - dfg::AbstractDFG, - vo::AbstractVector, - ::Type{TestFunctorInferenceType1}, - d::PackedTestFunctorInferenceType1, - ::String, -) - error("obsolete, TODO remove") - return TestFunctorInferenceType1() -end - -# overly simplified test requires both reconstitute and convert -function Base.convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1) - # @info "convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInferenceType1)" - return TestFunctorInferenceType1() -end - -Base.@kwdef struct PackedTestAbstractPrior <: AbstractPackedObservation - s::String = "" -end -# PackedTestAbstractPrior() = PackedTestAbstractPrior("") - -function Base.convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior) - # @info "convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)" - return PackedTestAbstractPrior() +struct PackedNothingDistribution <: AbstractPackedBelief + _type::Symbol + function PackedNothingDistribution(; _type::String = "PackedNothingDistribution") + return new(Symbol(_type)) + end end -function Base.convert(::Type{TestAbstractPrior}, d::PackedTestAbstractPrior) - # @info "onvert(::Type{TestAbstractPrior}, d::PackedTestAbstractPrior)" - return TestAbstractPrior() -end +DFG.packDistribution(::Nothing) = PackedNothingDistribution() +DFG.unpackDistribution(::PackedNothingDistribution) = nothing struct TestCCW{T <: AbstractObservation} <: FactorCache usrfnc!::T @@ -77,46 +50,6 @@ TestCCW{T}() where {T} = TestCCW(T()) Base.:(==)(a::TestCCW, b::TestCCW) = a.usrfnc! == b.usrfnc! -# DFG.rebuildFactorCache!(dfg::AbstractDFG{NoSolverParams}, fac::FactorCompute) = fac - -function DFG.reconstFactorData( - dfg::AbstractDFG, - vo::AbstractVector, - ::Type{<:DFG.FunctionNodeData{TestCCW{F}}}, - d::DFG.PackedFunctionNodeData{<:AbstractPackedObservation}, -) where {F <: DFG.AbstractObservation} - error("obsolete, TODO remove") - nF = convert(F, d.fnc) - return DFG.FunctionNodeData( - d.eliminated, - d.potentialused, - d.edgeIDs, - TestCCW(nF), - d.multihypo, - d.certainhypo, - d.nullhypo, - d.solveInProgress, - d.inflation, - ) -end - -function Base.convert( - ::Type{DFG.PackedFunctionNodeData{P}}, - d::DFG.FunctionNodeData{<:FactorCache}, -) where {P <: AbstractPackedObservation} - return DFG.PackedFunctionNodeData( - d.eliminated, - d.potentialused, - d.edgeIDs, - convert(P, d.fnc.usrfnc!), - d.multihypo, - d.certainhypo, - d.nullhypo, - d.solveInProgress, - d.inflation, - ) -end - ## # global testDFGAPI = GraphsDFG # T = testDFGAPI @@ -357,7 +290,7 @@ function DFGVariableSCA() #variableType functions testvar = TestVariableType1() @test getDimension(testvar) == 1 - @test getManifold(testvar) == Euclidean(1) + @test getManifold(testvar) == TranslationGroup(1) # #TODO sort out # getPPEs @@ -410,8 +343,8 @@ function DFGFactorSCA() @test setSolvable!(f1, 1) == 1 #TODO These 2 function are equivelent - @test typeof(getFactorType(f1)) == TestFunctorInferenceType1 - @test typeof(getFactorFunction(f1)) == TestFunctorInferenceType1 + @test typeof(getFactorType(f1)) == TestFunctorInferenceType1{Nothing} + @test typeof(getFactorFunction(f1)) == TestFunctorInferenceType1{Nothing} #TODO here for now, don't recommend usage. testTags = [:tag1, :tag2] @@ -1148,12 +1081,15 @@ function testGroup!(fg, v1, v2, f0, f1) @test isPrior(fg, :af1) # if f1 is prior @test lsfPriors(fg) == [:af1] - @test issetequal([TestFunctorInferenceType1, TestAbstractPrior], DFG.lsfTypes(fg)) + @test issetequal( + [TestFunctorInferenceType1{Nothing}, TestAbstractPrior{Nothing}], + DFG.lsfTypes(fg), + ) facTypesDict = DFG.lsfTypesDict(fg) @test issetequal(collect(keys(facTypesDict)), DFG.lsfTypes(fg)) - @test issetequal(facTypesDict[TestFunctorInferenceType1], [:abf1]) - @test issetequal(facTypesDict[TestAbstractPrior], [:af1]) + @test issetequal(facTypesDict[TestFunctorInferenceType1{Nothing}], [:abf1]) + @test issetequal(facTypesDict[TestAbstractPrior{Nothing}], [:af1]) @test ls(fg, TestFunctorInferenceType1) == [:abf1] @test lsf(fg, TestAbstractPrior) == [:af1] @@ -1672,7 +1608,7 @@ function ProducingDotFiles( @test DFG.toDot(dotdfg) == "graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n" end - @test DFG.toDotFile(dotdfg, "something.dot") == nothing + @test DFG.toDotFile(dotdfg, "something.dot") === nothing return Base.rm("something.dot") end