Skip to content

Commit

Permalink
Internal API redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
artivis committed Aug 2, 2020
1 parent 2307206 commit 19177be
Show file tree
Hide file tree
Showing 84 changed files with 4,304 additions and 2,986 deletions.
19 changes: 18 additions & 1 deletion include/manif/Rn.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@
#define _MANIF_RN_H_

#include "manif/impl/macro.h"
#include "manif/constants.h"
#include "manif/impl/utils.h"
#include "manif/impl/lie_group_base.h"

#include "manif/impl/traits.h"
#include "manif/impl/core/crtp.h"

#include "manif/impl/eigen.h"

#include "manif/impl/expr/expr.h"
#include "manif/impl/random.h"
#include "manif/impl/generator.h"
#include "manif/impl/assignment_assert.h"

#include "lt/optional.hpp"

#include "manif/impl/tangent_base.h"
#include "manif/impl/lie_group_base.h"

#include "manif/impl/rn/Rn_properties.h"
#include "manif/impl/rn/Rn_base.h"
#include "manif/impl/rn/RnTangent_base.h"
#include "manif/impl/rn/Rn.h"
#include "manif/impl/rn/Rn_expr.h"
#include "manif/impl/rn/RnTangent.h"
#include "manif/impl/rn/RnTangent_expr.h"

#include "manif/impl/rn/Rn_map.h"
#include "manif/impl/rn/RnTangent_map.h"

Expand Down
20 changes: 19 additions & 1 deletion include/manif/SE2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@
#define _MANIF_SE2_H_

#include "manif/impl/macro.h"
#include "manif/impl/lie_group_base.h"
#include "manif/constants.h"
#include "manif/impl/utils.h"

#include "manif/impl/traits.h"
#include "manif/impl/core/crtp.h"

#include "manif/impl/eigen.h"

#include "manif/impl/expr/expr.h"
#include "manif/impl/random.h"
#include "manif/impl/generator.h"
#include "manif/impl/assignment_assert.h"

#include "lt/optional.hpp"

#include "manif/impl/tangent_base.h"
#include "manif/impl/lie_group_base.h"

#include "manif/impl/se2/SE2_properties.h"
#include "manif/impl/se2/SE2_base.h"
#include "manif/impl/se2/SE2Tangent_base.h"
#include "manif/impl/se2/SE2.h"
#include "manif/impl/se2/SE2_expr.h"
#include "manif/impl/se2/SE2Tangent.h"
#include "manif/impl/se2/SE2Tangent_expr.h"

#include "manif/impl/se2/SE2_map.h"
#include "manif/impl/se2/SE2Tangent_map.h"

Expand Down
27 changes: 24 additions & 3 deletions include/manif/SE3.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
#ifndef _MANIF_SE3_H_
#define _MANIF_SE3_H_

#include "manif/impl/macro.h"
#include "manif/impl/lie_group_base.h"
#include "manif/impl/tangent_base.h"
// #include "manif/impl/macro.h"
// #include "manif/constants.h"
// #include "manif/impl/utils.h"
//
// #include "manif/impl/traits.h"
// #include "manif/impl/core/crtp.h"
//
// #include "manif/impl/eigen.h"
//
// #include "manif/impl/expr/expr.h"
// #include "manif/impl/random.h"
// #include "manif/impl/generator.h"
// #include "manif/impl/assignment_assert.h"
//
// #include "lt/optional.hpp"
//
// #include "manif/impl/tangent_base.h"
// #include "manif/impl/lie_group_base.h"

#include "manif/SO3.h"

#include "manif/impl/se3/SE3_utils.h"
#include "manif/impl/se3/SE3_properties.h"
#include "manif/impl/se3/SE3_base.h"
#include "manif/impl/se3/SE3Tangent_base.h"
#include "manif/impl/se3/SE3.h"
#include "manif/impl/se3/SE3_expr.h"
#include "manif/impl/se3/SE3Tangent.h"
#include "manif/impl/se3/SE3Tangent_expr.h"

#include "manif/impl/se3/SE3_map.h"
#include "manif/impl/se3/SE3Tangent_map.h"

Expand Down
19 changes: 18 additions & 1 deletion include/manif/SO2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@
#define _MANIF_SO2_H_

#include "manif/impl/macro.h"
#include "manif/constants.h"
#include "manif/impl/utils.h"
#include "manif/impl/lie_group_base.h"

#include "manif/impl/traits.h"
#include "manif/impl/core/crtp.h"

#include "manif/impl/eigen.h"

#include "manif/impl/expr/expr.h"
#include "manif/impl/random.h"
#include "manif/impl/generator.h"
#include "manif/impl/assignment_assert.h"

#include "lt/optional.hpp"

#include "manif/impl/tangent_base.h"
#include "manif/impl/lie_group_base.h"

#include "manif/impl/so2/SO2_properties.h"
#include "manif/impl/so2/SO2_base.h"
#include "manif/impl/so2/SO2Tangent_base.h"
#include "manif/impl/so2/SO2.h"
#include "manif/impl/so2/SO2_expr.h"
#include "manif/impl/so2/SO2Tangent.h"
#include "manif/impl/so2/SO2Tangent_expr.h"

#include "manif/impl/so2/SO2_map.h"
#include "manif/impl/so2/SO2Tangent_map.h"

Expand Down
20 changes: 19 additions & 1 deletion include/manif/SO3.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@
#define _MANIF_SO3_H_

#include "manif/impl/macro.h"
#include "manif/impl/lie_group_base.h"
#include "manif/constants.h"
#include "manif/impl/utils.h"

#include "manif/impl/traits.h"
#include "manif/impl/core/crtp.h"

#include "manif/impl/eigen.h"

#include "manif/impl/expr/expr.h"
#include "manif/impl/random.h"
#include "manif/impl/generator.h"
#include "manif/impl/assignment_assert.h"

#include "lt/optional.hpp"

#include "manif/impl/tangent_base.h"
#include "manif/impl/lie_group_base.h"

#include "manif/impl/so3/SO3_properties.h"
#include "manif/impl/so3/SO3_base.h"
#include "manif/impl/so3/SO3Tangent_base.h"
#include "manif/impl/so3/SO3.h"
#include "manif/impl/so3/SO3_expr.h"
#include "manif/impl/so3/SO3Tangent.h"
#include "manif/impl/so3/SO3Tangent_expr.h"

#include "manif/impl/so3/SO3_map.h"
#include "manif/impl/so3/SO3Tangent_map.h"

Expand Down
28 changes: 28 additions & 0 deletions include/manif/impl/core/crtp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _MANIF_MANIF_IMPL_CRTP_H_
#define _MANIF_MANIF_IMPL_CRTP_H_

namespace manif {
namespace internal {

template <typename Derived>
struct crtp
{
protected:
/** Return reference to this as derived object */
inline Derived &derived() & noexcept {
return *static_cast<Derived *>(this);
}
/** Return reference to this as derived object */
inline const Derived &derived() const & noexcept {
return *static_cast<Derived const *>(this);
}
/** Return reference to this as derived object, when this is rvalue */
inline Derived &&derived() && noexcept {
return std::move(*static_cast<Derived *>(this));
}
};

} // namespace internal
} // namespace manif

#endif // _MANIF_MANIF_IMPL_CRTP_H_
33 changes: 33 additions & 0 deletions include/manif/impl/core/storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
#define _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_

namespace manif {
namespace internal {

template <typename T>
struct storage_selector {
using type = T;
};

template <typename T>
struct storage_selector<T&> {
using type = T&;
};

template <typename T>
struct storage_selector<const T&> {
using type = const T&;
};

template <typename T>
struct storage_selector<T&&> {
using type = T;
};

template <typename T>
using storage_t = typename storage_selector<T>::type;

} // namespace internal
} // namespace manif

#endif // _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
71 changes: 71 additions & 0 deletions include/manif/impl/core/unary_storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
#define _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_


namespace manif {
namespace internal {

template <typename Derived, typename RhsDerived_>
struct UnaryStorage {
private:
// Hold a reference to leaf expressions to avoid copies, but a copy of other
// expressions to avoid references to temporaries.
using RhsStore = internal::storage_t<RhsDerived_>;

// Helper to lazily instantiate is_constructible check in forwarding constructor
// We use this inside std::conjunction.
template <typename...>
struct copy_not_applicable : std::true_type {};

// Case for exactly one argument: need to check whether copy constructor applies
template <typename Arg>
struct copy_not_applicable<Arg>
: tmp::bool_constant<!std::is_same<std::decay_t<Arg>, Derived>{}> {};

public:
// Forward args to rhs (version for one argument)
// Disable if copy ctor would apply - https://stackoverflow.com/a/39646176
template <typename Arg,
std::enable_if_t<tmp::conjunction<copy_not_applicable<Arg>,
std::is_constructible<RhsStore, Arg>>{},
bool> = true>
explicit UnaryStorage(Arg &&arg) : rhs_{std::forward<Arg>(arg)} {}

// Forward args to rhs (version for 0 or more than 1 argument)
template <
typename... Args,
std::enable_if_t<tmp::conjunction<copy_not_applicable<Args...>,
std::is_constructible<RhsStore, Args...>>{},
bool> = true>
explicit UnaryStorage(Args &&... args) : rhs_{std::forward<Args>(args)...} {}

UnaryStorage() = delete;
/** Copy constructor */
UnaryStorage(const UnaryStorage &) = default;
/** Move constructor */
UnaryStorage(UnaryStorage &&) = default;
/** Copy assignment operator */
UnaryStorage &operator=(const UnaryStorage &) = default;
/** Move assignment operator */
UnaryStorage &operator=(UnaryStorage &&) = default;

const RhsStore &rhs() const & {
return rhs_;
}

RhsStore &rhs() & {
return rhs_;
}

RhsStore rhs() && {
return rhs_;
}

protected:
RhsStore rhs_;
};

} // namespace internal
} // namespace manif

#endif // _MANIF_MANIF_IMPL_CORE_UNARY_STORAGE_H_
62 changes: 62 additions & 0 deletions include/manif/impl/expr/act.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef _MANIF_MANIF_IMPL_EXPR_ACT_H_
#define _MANIF_MANIF_IMPL_EXPR_ACT_H_

namespace manif {

// MANIF_DECLARE_BINARY_EXPR(Act);

template <typename _Lhs, typename _Rhs>
struct ActExpr
: internal::ExprBase<ActExpr<_Lhs, _Rhs>>
{
using ExprDerived = ActExpr<_Lhs, _Rhs>;
using Base = internal::ExprBase<ExprDerived>;

using LieGroup = typename _Lhs::LieGroup;
using Scalar = typename internal::traits<LieGroup>::Scalar;

using LhsOptJacobianRef = ::tl::optional<Eigen::Ref<Eigen::Matrix<Scalar, internal::traits<LieGroup>::Dim, internal::traits<LieGroup>::DoF>>>;
using RhsOptJacobianRef = ::tl::optional<Eigen::Ref<Eigen::Matrix<Scalar, internal::traits<LieGroup>::Dim, internal::traits<LieGroup>::Dim>>>;

using Ret = ReturnType<ExprDerived>;

using Base::derived;
using Base::eval;

ActExpr(const _Lhs& lhsptr,
const _Rhs& rhsptr,
LhsOptJacobianRef& J_ret_lhs = {},
RhsOptJacobianRef& J_ret_rhs = {})
: lhsptr_(lhsptr)
, rhsptr_(rhsptr)
, J_ret_lhs_(J_ret_lhs)
, J_ret_rhs_(J_ret_rhs) { }

protected:

friend Base;
Ret evalImpl() const
{
return internal::ExprEvaluator<ExprDerived>::run(
lhsptr_, rhsptr_, J_ret_lhs_, J_ret_rhs_);
}

const _Lhs& lhsptr_;
const _Rhs& rhsptr_;
mutable LhsOptJacobianRef J_ret_lhs_;
mutable RhsOptJacobianRef J_ret_rhs_;
};

namespace internal {

template <template <typename _Derived> class _LieGroupBase,
typename _Derived, typename _DerivedOther>
struct ReturnTypeHelper<ActExpr<_LieGroupBase<_Derived>, _DerivedOther>>
{
using type = typename traits<_Derived>::Vector;
};

} // namespace internal
} // namespace manif

#endif // _MANIF_MANIF_IMPL_EXPR_ACT_H_
21 changes: 21 additions & 0 deletions include/manif/impl/expr/adj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _MANIF_MANIF_IMPL_EXPR_ADJ_H_
#define _MANIF_MANIF_IMPL_EXPR_ADJ_H_

namespace manif {

MANIF_DECLARE_UNARY_EXPR(Adj);

namespace internal {

// Default expression return type

template <template <typename _LieGroupDerived> class _LieGroupDerivedBase, typename _LieGroupDerived>
struct ReturnTypeHelper<AdjExpr<_LieGroupDerivedBase<_LieGroupDerived>>>
{
using type = typename internal::traits<_LieGroupDerived>::Jacobian;
};

} // namespace internal
} // namespace manif

#endif // _MANIF_MANIF_IMPL_EXPR_ADJ_H_
Loading

0 comments on commit 19177be

Please sign in to comment.