Skip to content

Commit 21655bf

Browse files
authored
Merge pull request #583 from JuliaRobotics/feat/20Q3/defSoftypeMacro
Macro to create a new <:InferenceVariable
2 parents 91665b3 + 068df11 commit 21655bf

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export getSolverData
123123

124124
export getVariableType
125125

126+
# Softtype functions
127+
export getDimension, getManifolds
128+
126129
# Small Data CRUD
127130
export SmallDataTypes, getSmallData, addSmallData!, updateSmallData!, deleteSmallData!, listSmallData, emptySmallData!
128131
export getSmallData, setSmallData!

src/entities/DFGVariable.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44

55
abstract type InferenceVariable end
66

7-
"""
8-
$SIGNATURES
9-
Interface function to return the softtype dimention of an InferenceVariable, extend this function for all Types<:InferenceVariable.
10-
"""
11-
function getDimension end
12-
"""
13-
$SIGNATURES
14-
Interface function to return the softtype manifolds of an InferenceVariable, extend this function for all Types<:InferenceVariable.
15-
"""
16-
function getManifolds end
177
##==============================================================================
188
## VariableNodeData
199
##==============================================================================

src/services/DFGVariable.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ Alias for [`getSofttype`](@ref).
5151
"""
5252
getVariableType(args...) = getSofttype(args...)
5353

54+
55+
##------------------------------------------------------------------------------
56+
## InferenceVariable
57+
##------------------------------------------------------------------------------
58+
"""
59+
$SIGNATURES
60+
Interface function to return the softtype dimention of an InferenceVariable, extend this function for all Types<:InferenceVariable.
61+
"""
62+
function getDimension end
63+
"""
64+
$SIGNATURES
65+
Interface function to return the softtype manifolds of an InferenceVariable, extend this function for all Types<:InferenceVariable.
66+
"""
67+
function getManifolds end
68+
69+
"""
70+
@defVariable StructName dimension manifolds
71+
A macro to create a new variable with name `StructName`, dimension and manifolds.
72+
Example:
73+
```
74+
DFG.@defVariable Pose2 3 (:Euclid, :Euclid, :Circular)
75+
```
76+
"""
77+
macro defVariable(structname, dimension::Int, manifolds)#::Vararg{Symbol})#NTuple{dimension, Symbol})
78+
# :(struct $structname <: InferenceVariable end)
79+
return esc(quote
80+
struct $structname <: InferenceVariable end
81+
DistributedFactorGraphs.getDimension(::$structname) = $dimension
82+
DistributedFactorGraphs.getManifolds(::$structname) = $manifolds
83+
end)
84+
end
5485
##------------------------------------------------------------------------------
5586
## solvedCount
5687
##------------------------------------------------------------------------------

test/consol_DataEntryBlobTests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ ade2,adb2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
9090
@test adb == adb2# == adb3
9191

9292
deleteData!(dfg, :x2, :random)
93+
94+
#test default folder store
95+
dfs = FolderStore("/tmp/defaultfolderstore")
96+
@test dfs.folder == "/tmp/defaultfolderstore"
97+
@test dfs.key == :default_folder_store
98+
@test dfs isa FolderStore{Vector{UInt8}}
99+
93100
##==============================================================================
94101
## Unimplemented store
95102
##==============================================================================

test/testBlocks.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ using UUIDs
66
import Base: convert
77

88
# Test InferenceVariable Types
9-
struct TestSofttype1 <: InferenceVariable
10-
dims::Int
11-
manifolds::Tuple{Symbol}
12-
TestSofttype1() = new(1,(:Euclid,))
13-
end
9+
# struct TestSofttype1 <: InferenceVariable
10+
# dims::Int
11+
# manifolds::Tuple{Symbol}
12+
# TestSofttype1() = new(1,(:Euclid,))
13+
# end
14+
15+
DFG.@defVariable TestSofttype1 1 (:Euclid,)
1416

1517
struct TestSofttype2 <: InferenceVariable
1618
dims::Int
@@ -288,9 +290,10 @@ function DFGVariableSCA()
288290

289291
#no accessors on dataDict, only CRUD
290292

291-
#deprecated
292-
# @test @test_deprecated solverData(v1, :default) === v1.solverDataDict[:default]
293-
293+
#softtype functions
294+
testvar = TestSofttype1()
295+
@test getDimension(testvar) == 1
296+
@test getManifolds(testvar) == (:Euclid,)
294297

295298
# #TODO sort out
296299
# getPPEs

0 commit comments

Comments
 (0)