Formatting and some small problems

release/4.3a0
dellaert 2014-11-22 21:48:36 +01:00
parent cc997dd774
commit d00aeb7e70
4 changed files with 30 additions and 39 deletions

View File

@ -10,7 +10,7 @@
* -------------------------------------------------------------------------- */
/**
* @file Pose2SLAMExample.cpp
* @file Pose2SLAMExampleExpressions.cpp
* @brief Expressions version of Pose2SLAMExample.cpp
* @date Oct 2, 2014
* @author Frank Dellaert

View File

@ -24,6 +24,8 @@
#include <gtsam/base/FastVector.h>
#include <gtsam/base/Matrix.h>
#include <boost/mpl/transform.hpp>
namespace gtsam {
class JacobianMap;
@ -67,8 +69,7 @@ struct ConvertToDynamicRowsIf<false> {
* with Rows in 1..MaxSupportedStaticRows
*/
template<int MaxSupportedStaticRows, int Cols>
struct ReverseADInterface: ReverseADInterface<MaxSupportedStaticRows - 1,
Cols> {
struct ReverseADInterface: ReverseADInterface<MaxSupportedStaticRows - 1, Cols> {
using ReverseADInterface<MaxSupportedStaticRows - 1, Cols>::_reverseAD;
virtual void _reverseAD(
const Eigen::Matrix<double, MaxSupportedStaticRows, Cols> & dFdT,
@ -92,19 +93,19 @@ template<typename Derived, int MaxSupportedStaticRows, int Cols>
struct ReverseADImplementor: ReverseADImplementor<Derived,
MaxSupportedStaticRows - 1, Cols> {
private:
using ReverseADImplementor<Derived,
MaxSupportedStaticRows - 1, Cols>::_reverseAD;
using ReverseADImplementor<Derived, MaxSupportedStaticRows - 1, Cols>::_reverseAD;
virtual void _reverseAD(
const Eigen::Matrix<double, MaxSupportedStaticRows, Cols> & dFdT,
JacobianMap& jacobians) const {
static_cast<const Derived *>(this)->reverseAD(dFdT, jacobians);
}
friend struct internal::ReverseADImplementor<Derived, MaxSupportedStaticRows + 1, Cols>;
friend struct internal::ReverseADImplementor<Derived,
MaxSupportedStaticRows + 1, Cols>;
};
template<typename Derived, int Cols>
struct ReverseADImplementor<Derived, 0, Cols>
: virtual internal::ReverseADInterface<MaxVirtualStaticRows, Cols> {
struct ReverseADImplementor<Derived, 0, Cols> : virtual internal::ReverseADInterface<
MaxVirtualStaticRows, Cols> {
private:
using internal::ReverseADInterface<MaxVirtualStaticRows, Cols>::_reverseAD;
const Derived & derived() const {
@ -131,8 +132,8 @@ private:
* It is implemented in the function-style ExpressionNode's nested Record class below.
*/
template<int Cols>
struct CallRecord: virtual private internal::ReverseADInterface<MaxVirtualStaticRows,
Cols> {
struct CallRecord: virtual private internal::ReverseADInterface<
MaxVirtualStaticRows, Cols> {
inline void print(const std::string& indent) const {
_print(indent);
@ -150,8 +151,7 @@ struct CallRecord: virtual private internal::ReverseADInterface<MaxVirtualStatic
dFdT), jacobians);
}
inline void reverseAD(const Matrix & dFdT,
JacobianMap& jacobians) const {
inline void reverseAD(const Matrix & dFdT, JacobianMap& jacobians) const {
_reverseAD(dFdT, jacobians);
}
@ -161,8 +161,7 @@ struct CallRecord: virtual private internal::ReverseADInterface<MaxVirtualStatic
private:
virtual void _print(const std::string& indent) const = 0;
virtual void _startReverseAD(JacobianMap& jacobians) const = 0;
using internal::ReverseADInterface<MaxVirtualStaticRows,
Cols>::_reverseAD;
using internal::ReverseADInterface<MaxVirtualStaticRows, Cols>::_reverseAD;
};
namespace internal {
@ -172,7 +171,7 @@ namespace internal {
*/
template<typename Derived, int Cols>
struct CallRecordImplementor: public CallRecord<Cols>,
private ReverseADImplementor<Derived, MaxVirtualStaticRows, Cols> {
private ReverseADImplementor<Derived, MaxVirtualStaticRows, Cols> {
private:
const Derived & derived() const {
return static_cast<const Derived&>(*this);
@ -183,7 +182,7 @@ private:
virtual void _startReverseAD(JacobianMap& jacobians) const {
derived().startReverseAD(jacobians);
}
template <typename D, int R, int C> friend class ReverseADImplementor;
template<typename D, int R, int C> friend struct ReverseADImplementor;
};
} // namespace internal

View File

@ -28,19 +28,10 @@
#include <boost/tuple/tuple.hpp>
#include <boost/bind.hpp>
// template meta-programming headers, TODO not all needed?
#include <boost/mpl/vector.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/pop_front.hpp>
// template meta-programming headers
#include <boost/mpl/fold.hpp>
#include <boost/mpl/empty_base.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/at.hpp>
namespace MPL = boost::mpl::placeholders;
//
//#include <new> // for placement new
#include <map>
class ExpressionFactorBinaryTest;
@ -171,8 +162,9 @@ public:
content.ptr->startReverseAD(jacobians);
}
// Either add to Jacobians (Leaf) or propagate (Function)
template <typename DerivedMatrix>
void reverseAD(const Eigen::MatrixBase<DerivedMatrix> & dTdA, JacobianMap& jacobians) const {
template<typename DerivedMatrix>
void reverseAD(const Eigen::MatrixBase<DerivedMatrix> & dTdA,
JacobianMap& jacobians) const {
if (kind == Leaf)
handleLeafCase(dTdA.eval(), jacobians, content.key);
else if (kind == Function)
@ -435,7 +427,7 @@ struct FunctionalBase: ExpressionNode<T> {
}
void startReverseAD(JacobianMap& jacobians) const {
}
template <typename SomeMatrix>
template<typename SomeMatrix>
void reverseAD(const SomeMatrix & dFdT, JacobianMap& jacobians) const {
}
};
@ -511,8 +503,9 @@ struct GenerateFunctionalNode: Argument<T, A, Base::N + 1>, Base {
}
/// Given df/dT, multiply in dT/dA and continue reverse AD process
template <int Rows, int Cols>
void reverseAD(const Eigen::Matrix<double, Rows, Cols> & dFdT, JacobianMap& jacobians) const {
template<int Rows, int Cols>
void reverseAD(const Eigen::Matrix<double, Rows, Cols> & dFdT,
JacobianMap& jacobians) const {
Base::Record::reverseAD(dFdT, jacobians);
This::trace.reverseAD(dFdT * This::dTdA, jacobians);
}
@ -571,14 +564,14 @@ struct FunctionalNode {
/// Provide convenience access to Record storage and implement
/// the virtual function based interface of CallRecord using the CallRecordImplementor
struct Record:
public internal::CallRecordImplementor<Record, traits::dimension<T>::value>,
public Base::Record {
struct Record: public internal::CallRecordImplementor<Record,
traits::dimension<T>::value>, public Base::Record {
using Base::Record::print;
using Base::Record::startReverseAD;
using Base::Record::reverseAD;
virtual ~Record(){}
virtual ~Record() {
}
/// Access Value
template<class A, size_t N>
@ -690,8 +683,8 @@ public:
virtual T value(const Values& values) const {
using boost::none;
return function_(this->template expression<A1, 1>()->value(values),
this->template expression<A2, 2>()->value(values),
none, none);
this->template expression<A2, 2>()->value(values),
none, none);
}
/// Construct an execution trace for reverse AD

View File

@ -38,7 +38,6 @@ template<class T> struct Incomplete;
typedef mpl::vector<Pose3, Point3> MyTypes;
typedef FunctionalNode<Point2, MyTypes>::type Generated;
//Incomplete<Generated> incomplete;
BOOST_MPL_ASSERT((boost::is_same< Matrix2, Generated::Record::Jacobian2T >));
// Try generating vectors of ExecutionTrace
typedef mpl::vector<ExecutionTrace<Pose3>, ExecutionTrace<Point3> > ExpectedTraces;