Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defFactorType macro #1077

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/entities/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
## Abstract Types
##==============================================================================

# TODO consider changing this to AbstractFactor
abstract type AbstractFactor end
abstract type AbstractPackedFactor end

abstract type AbstractPrior <: AbstractFactor end
abstract type AbstractRelative <: AbstractFactor end
# abstract type AbstractRelativeRoots <: AbstractRelative end # TODO deprecate
abstract type AbstractRelativeMinimize <: AbstractRelative end
abstract type AbstractManifoldMinimize <: AbstractRelative end

Expand Down
45 changes: 45 additions & 0 deletions src/services/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,51 @@ function _getPriorType(_type::Type{<:InferenceVariable})
return getfield(_type.name.module, Symbol(:Prior, _type.name.name))
end


Affie marked this conversation as resolved.
Show resolved Hide resolved
##==============================================================================
## Default Factors Function Macro
##==============================================================================
function pack end
function unpack end
"""
@defFactorFunction StructName factortype<:AbstractFactor manifolds<:ManifoldsBase.AbstractManifold

A macro to create a new factor function with name `StructName` and manifolds. Note that
the `manifolds` is an object and *must* be a subtype of `ManifoldsBase.AbstractManifold`.
See documentation in [Manifolds.jl on making your own](https://juliamanifolds.github.io/Manifolds.jl/stable/examples/manifold.html).

Example:
```
DFG.@defFactorFunction Pose2Pos2 AbstractManifoldMinimize SpecialEuclidean(2)
```
"""
macro defFactorFunction(structname, factortype, manifold)
packedstructname = Symbol("Packed", structname)
return esc(
quote
Base.@__doc__ struct $structname{T} <: $factortype
Affie marked this conversation as resolved.
Show resolved Hide resolved
Z::T
end

# Base.@__doc__ struct $packedstructname{T<:PackedSamplableBelief} <: AbstractPackedFactor
Base.@__doc__ struct $packedstructname{T} <: AbstractPackedFactor
Affie marked this conversation as resolved.
Show resolved Hide resolved
Z::T
end

# user manifold must be a <:Manifold
@assert ($manifold isa AbstractManifold) "@defVariable of " *
string($structname) *
" requires that the " *
string($manifold) *
" be a subtype of `ManifoldsBase.AbstractManifold`"

DFG.getManifold(::Type{$structname}) = $manifold
DFG.pack(d::$structname) = $packedstructname(packDistribution(d.Z))
DFG.unpack(d::$packedstructname) = $structname(unpackDistribution(d.Z))
Affie marked this conversation as resolved.
Show resolved Hide resolved
end,
)
end

##==============================================================================
## Factors
##==============================================================================
Expand Down
Loading