Skip to content

Commit 9fb530a

Browse files
committed
add getPointType
1 parent c2ae4df commit 9fb530a

File tree

5 files changed

+32
-68
lines changed

5 files changed

+32
-68
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export getSolverData
135135
export getVariableType
136136

137137
# VariableType functions
138-
export getDimension, getManifolds, getManifold
138+
export getDimension, getManifolds, getManifold, getPointType
139139

140140
# Small Data CRUD
141141
export SmallDataTypes, getSmallData, addSmallData!, updateSmallData!, deleteSmallData!, listSmallData, emptySmallData!

src/services/DFGVariable.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Example:
8686
DFG.@defVariable Pose2 SpecialEuclidean(2)
8787
```
8888
"""
89-
macro defVariable(structname, manifold)
89+
macro defVariable(structname, manifold, point_type)
9090
return esc(quote
9191
Base.@__doc__ struct $structname <: InferenceVariable end
9292

@@ -95,6 +95,8 @@ macro defVariable(structname, manifold)
9595

9696
DFG.getManifold(::Type{$structname}) = $manifold
9797

98+
DFG.getPointType(::Type{$structname}) = $point_type
99+
98100
end)
99101
end
100102

@@ -120,6 +122,13 @@ getDimension(M::ManifoldsBase.AbstractManifold) = manifold_dimension(M)
120122
getDimension(var::DFGVariable) = getDimension(getVariableType(var))
121123

122124

125+
"""
126+
$SIGNATURES
127+
Interface function to return the manifold point type of an InferenceVariable, extend this function for all Types<:InferenceVariable.
128+
"""
129+
function getPointType end
130+
getPointType(::T) where {T <: InferenceVariable} = getPointType(T)
131+
123132
##------------------------------------------------------------------------------
124133
## solvedCount
125134
##------------------------------------------------------------------------------

test/runtests.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ using UUIDs
2121
# logger = SimpleLogger(stdout, Logging.Debug)
2222
# global_logger(logger)
2323

24-
# @testset "Check @defVariable design" begin
25-
# include("test_defVariable.jl")
26-
# end
24+
include("test_defVariable.jl")
2725

2826
include("testBlocks.jl")
2927

test/testBlocks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import Base: convert
1616
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(1))) = (:Euclid,)
1717
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(2))) = (:Euclid, :Euclid)
1818

19-
@defVariable TestVariableType1 Euclidean(1)
20-
@defVariable TestVariableType2 Euclidean(2)
19+
@defVariable TestVariableType1 Euclidean(1) Vector{Float64}
20+
@defVariable TestVariableType2 Euclidean(2) Vector{Float64}
2121

2222
# struct TestVariableType2 <: InferenceVariable
2323
# dims::Int

test/test_defVariable.jl

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,39 @@
1-
2-
using ManifoldsBase, Manifolds
1+
using Manifolds
32
using Test
43

5-
# abstract type InferenceVariable end
6-
7-
##
8-
9-
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(1))) = (:Euclid,)
10-
Base.convert(::Type{<:Tuple}, ::typeof(Euclidean(2))) = (:Euclid, :Euclid)
11-
12-
##
13-
14-
## WARNING, THIS IS A DUPLICATE OF THE MACRO IN DFGVariable.jl TO MAKE SURE OVERLOADS ARE WORKING RIGHT
15-
macro defVariable(structname, manifold)
16-
return esc(quote
17-
Base.@__doc__ struct $structname <: InferenceVariable end
18-
19-
@assert ($manifold isa AbstractManifold) "@defVariable of "*string($structname)*" requires that the "*string($manifold)*" be a subtype of `ManifoldsBase.AbstractManifold`"
20-
21-
# manifold must be is a <:Manifold
22-
Base.convert(::Type{<:AbstractManifold}, ::Union{<:T, Type{<:T}}) where {T <: $structname} = $manifold
23-
24-
getManifold(::Type{M}) where {M <: $structname} = $manifold
25-
getManifold(::M) where {M <: $structname} = getManifold(M)
26-
27-
getDimension(::Type{M}) where {M <: $structname} = manifold_dimension(getManifold(M))
28-
getDimension(::M) where {M <: $structname} = manifold_dimension(getManifold(M))
29-
# FIXME legacy API to be deprecated
30-
# getManifolds(::Type{M}) where {M <: $structname} = convert(Tuple, $manifold)
31-
# getManifolds(::M) where {M <: $structname} = convert(Tuple, $manifold)
32-
end)
33-
end
34-
35-
36-
##
37-
38-
39-
ex = macroexpand(Main, :(@defVariable(TestVariableType1, Euclidean(1))) )
40-
41-
4+
@testset "Testing @defVariable" begin
425
##
436

447
struct NotAManifold end
458

46-
try
47-
@defVariable(MyVar, NotAManifold())
48-
catch AssertionError
49-
@test true
50-
end
9+
@test_throws AssertionError @defVariable(MyVar, NotAManifold(), Matrix{3})
5110

5211
##
5312

54-
@defVariable(TestVariableType1, Euclidean(1))
55-
@defVariable(TestVariableType2, Euclidean(2))
13+
@defVariable(TestVarType1, Euclidean(3), Vector{Float64})
14+
@defVariable(TestVarType2, SpecialEuclidean(3), ProductRepr{Tuple{Vector{Float64}, Matrix{Float64}}})
5615

5716

5817
##
5918

60-
@test getManifold( TestVariableType1) == Euclidean(1)
61-
@test getManifold( TestVariableType2) == Euclidean(2)
19+
@test getManifold( TestVarType1) == Euclidean(3)
20+
@test getManifold( TestVarType2) == SpecialEuclidean(3)
6221

63-
# legacy
64-
# @test getManifolds(TestVariableType1) == (:Euclid,)
65-
@test getDimension(TestVariableType1) === 1
66-
# @test getManifolds(TestVariableType2) == (:Euclid,:Euclid)
67-
@test getDimension(TestVariableType2) === 2
22+
@test getDimension(TestVarType1) === 3
23+
@test getDimension(TestVarType2) === 6
6824

25+
@test getPointType(TestVarType1) == Vector{Float64}
26+
@test getPointType(TestVarType2) == ProductRepr{Tuple{Vector{Float64}, Matrix{Float64}}}
6927
##
7028

7129

72-
@test getManifold( TestVariableType1()) == Euclidean(1)
73-
@test getManifold( TestVariableType2()) == Euclidean(2)
30+
@test getManifold( TestVarType1()) == Euclidean(3)
31+
@test getManifold( TestVarType2()) == SpecialEuclidean(3)
7432

75-
# legacy
76-
# @test getManifolds(TestVariableType1()) == (:Euclid,)
77-
@test getDimension(TestVariableType1()) === 1
78-
# @test getManifolds(TestVariableType2()) == (:Euclid,:Euclid)
79-
@test getDimension(TestVariableType2()) === 2
33+
@test getDimension(TestVarType1()) === 3
34+
@test getDimension(TestVarType2()) === 6
8035

36+
@test getPointType(TestVarType1()) == Vector{Float64}
37+
@test getPointType(TestVarType2()) == ProductRepr{Tuple{Vector{Float64}, Matrix{Float64}}}
8138

82-
##
39+
end

0 commit comments

Comments
 (0)