Skip to content

Commit

Permalink
Merge pull request #583 from JuliaRobotics/feat/20Q3/defSoftypeMacro
Browse files Browse the repository at this point in the history
Macro to create a new <:InferenceVariable
  • Loading branch information
Affie authored Aug 10, 2020
2 parents 91665b3 + 068df11 commit 21655bf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export getSolverData

export getVariableType

# Softtype functions
export getDimension, getManifolds

# Small Data CRUD
export SmallDataTypes, getSmallData, addSmallData!, updateSmallData!, deleteSmallData!, listSmallData, emptySmallData!
export getSmallData, setSmallData!
Expand Down
10 changes: 0 additions & 10 deletions src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@

abstract type InferenceVariable end

"""
$SIGNATURES
Interface function to return the softtype dimention of an InferenceVariable, extend this function for all Types<:InferenceVariable.
"""
function getDimension end
"""
$SIGNATURES
Interface function to return the softtype manifolds of an InferenceVariable, extend this function for all Types<:InferenceVariable.
"""
function getManifolds end
##==============================================================================
## VariableNodeData
##==============================================================================
Expand Down
31 changes: 31 additions & 0 deletions src/services/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ Alias for [`getSofttype`](@ref).
"""
getVariableType(args...) = getSofttype(args...)


##------------------------------------------------------------------------------
## InferenceVariable
##------------------------------------------------------------------------------
"""
$SIGNATURES
Interface function to return the softtype dimention of an InferenceVariable, extend this function for all Types<:InferenceVariable.
"""
function getDimension end
"""
$SIGNATURES
Interface function to return the softtype manifolds of an InferenceVariable, extend this function for all Types<:InferenceVariable.
"""
function getManifolds end

"""
@defVariable StructName dimension manifolds
A macro to create a new variable with name `StructName`, dimension and manifolds.
Example:
```
DFG.@defVariable Pose2 3 (:Euclid, :Euclid, :Circular)
```
"""
macro defVariable(structname, dimension::Int, manifolds)#::Vararg{Symbol})#NTuple{dimension, Symbol})
# :(struct $structname <: InferenceVariable end)
return esc(quote
struct $structname <: InferenceVariable end
DistributedFactorGraphs.getDimension(::$structname) = $dimension
DistributedFactorGraphs.getManifolds(::$structname) = $manifolds
end)
end
##------------------------------------------------------------------------------
## solvedCount
##------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions test/consol_DataEntryBlobTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ ade2,adb2 = addData!(dfg, :x2, deepcopy(ade), dataset1)
@test adb == adb2# == adb3

deleteData!(dfg, :x2, :random)

#test default folder store
dfs = FolderStore("/tmp/defaultfolderstore")
@test dfs.folder == "/tmp/defaultfolderstore"
@test dfs.key == :default_folder_store
@test dfs isa FolderStore{Vector{UInt8}}

##==============================================================================
## Unimplemented store
##==============================================================================
Expand Down
19 changes: 11 additions & 8 deletions test/testBlocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ using UUIDs
import Base: convert

# Test InferenceVariable Types
struct TestSofttype1 <: InferenceVariable
dims::Int
manifolds::Tuple{Symbol}
TestSofttype1() = new(1,(:Euclid,))
end
# struct TestSofttype1 <: InferenceVariable
# dims::Int
# manifolds::Tuple{Symbol}
# TestSofttype1() = new(1,(:Euclid,))
# end

DFG.@defVariable TestSofttype1 1 (:Euclid,)

struct TestSofttype2 <: InferenceVariable
dims::Int
Expand Down Expand Up @@ -288,9 +290,10 @@ function DFGVariableSCA()

#no accessors on dataDict, only CRUD

#deprecated
# @test @test_deprecated solverData(v1, :default) === v1.solverDataDict[:default]

#softtype functions
testvar = TestSofttype1()
@test getDimension(testvar) == 1
@test getManifolds(testvar) == (:Euclid,)

# #TODO sort out
# getPPEs
Expand Down

0 comments on commit 21655bf

Please sign in to comment.