Skip to content

Commit

Permalink
Merge pull request #94 from JuliaRobotics/hotfix/dynpose2comparetesting
Browse files Browse the repository at this point in the history
improve testing and bugfix
  • Loading branch information
dehann committed Aug 8, 2018
2 parents daf7da8 + 4c6b739 commit 6113ced
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/DynPose2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,28 @@ end



## Compare functions

function compare(a::MvNormal, b::MvNormal; tol::Float64=1e-10)::Bool
TP = true
TP = TP && norm(a.μ - b.μ)<tol
TP = TP && sum(norm.(a.Σ.mat - b.Σ.mat))<tol
return TP
end


function compare(a::DynPose2VelocityPrior, b::DynPose2VelocityPrior)::Bool
RoME.compare(a.Zpose, b.Zpose) && RoME.compare(a.Zvel, b.Zvel)
end


function compare(a::VelPose2VelPose2, b::VelPose2VelPose2; tol::Float64=1e-10)::Bool
TP = true
TP = TP && RoME.compare(a.Zpose, b.Zpose)
TP = TP && RoME.compare(a.Zvel, b.Zvel)
TP = TP && norm(a.reuseres - b.reuseres) < tol
return TP
end


## Packing types
Expand Down Expand Up @@ -121,7 +141,7 @@ mutable struct PackedVelPose2VelPose2 <: IncrementalInference.PackedInferenceTyp
end

function convert(::Type{PackedVelPose2VelPose2}, d::VelPose2VelPose2)
return PackedVelPose2VelPose2(string(d.Zpose),string(d.Zvel))
return PackedVelPose2VelPose2(string(d.Zpose.z),string(d.Zvel))
end
function convert(::Type{VelPose2VelPose2}, d::PackedVelPose2VelPose2)
posedistr = extractdistribution(d.strpose)
Expand All @@ -139,12 +159,16 @@ mutable struct PackedDynPose2Pose2 <: IncrementalInference.PackedInferenceType
end

function convert(::Type{PackedDynPose2Pose2}, d::DynPose2Pose2)
return PackedDynPose2Pose2(string(d.Zpose))
return PackedDynPose2Pose2(string(d.Zpose.z))
end
function convert(::Type{DynPose2Pose2}, d::PackedDynPose2Pose2)
posedistr = extractdistribution(d.strpose)
return DynPose2Pose2(posedistr)
end






#
32 changes: 32 additions & 0 deletions test/testDynPose2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,38 @@ warn("wrapRad issue, accepting 80% as good enough until issue JuliaRobotics/RoME
end


@testset "test distribution compare functions..." begin

mu = randn(6)
mv1 = MvNormal(deepcopy(mu), eye(6))
mv2 = MvNormal(deepcopy(mu), eye(6))
mv3 = MvNormal(randn(6), eye(6))
@test RoME.compare(mv1, mv2)
@test !RoME.compare(mv1, mv3)
@test !RoME.compare(mv2, mv3)

end


@testset "test DynPose2 packing converters..." begin

pp0 = DynPose2VelocityPrior(MvNormal(zeros(3), diagm([0.01; 0.01; 0.001].^2)),
MvNormal([10.0;0], diagm([0.1; 0.1].^2)))

pp = convert(PackedDynPose2VelocityPrior, pp0)
ppu = convert(DynPose2VelocityPrior, pp)

@test RoME.compare(pp0, ppu)

dp2dp2 = VelPose2VelPose2(MvNormal([10.0;0;0], diagm([0.01;0.01;0.001].^2)),
MvNormal([0.0;0], diagm([0.1; 0.1].^2)))

pp = convert(PackedVelPose2VelPose2, dp2dp2)
ppu = convert(VelPose2VelPose2, pp)

@test RoME.compare(dp2dp2, ppu)

end



Expand Down

0 comments on commit 6113ced

Please sign in to comment.