diff --git a/gtsam_unstable/nonlinear/CallRecord.h b/gtsam_unstable/nonlinear/CallRecord.h index 2161d9cb8..3206ba9b1 100644 --- a/gtsam_unstable/nonlinear/CallRecord.h +++ b/gtsam_unstable/nonlinear/CallRecord.h @@ -67,9 +67,8 @@ struct ConvertToDynamicRowsIf { * with Rows in 1..MaxSupportedStaticRows */ template -struct ReverseADInterface: public ReverseADInterface { -protected: using ReverseADInterface::_reverseAD; virtual void _reverseAD( const Eigen::Matrix & dFdT, @@ -78,10 +77,15 @@ protected: template struct ReverseADInterface<0, Cols> { -protected: - void _reverseAD() { - } //dummy to allow the using directive in the template without failing for MaxSupportedStaticRows == 1. + virtual void _reverseAD( + const Eigen::Matrix & dFdT, + JacobianMap& jacobians) const = 0; + virtual void _reverseAD(const Matrix & dFdT, + JacobianMap& jacobians) const = 0; }; + +template +struct ReverseADImplementor; // forward for CallRecord's friend declaration } /** @@ -115,15 +119,12 @@ struct CallRecord: private internal::ReverseADInterface::_reverseAD; virtual void _print(const std::string& indent) const = 0; virtual void _startReverseAD(JacobianMap& jacobians) const = 0; - virtual void _reverseAD( - const Eigen::Matrix & dFdT, - JacobianMap& jacobians) const = 0; - virtual void _reverseAD(const Matrix & dFdT, - JacobianMap& jacobians) const = 0; + using internal::ReverseADInterface::_reverseAD; + template + friend struct internal::ReverseADImplementor; }; namespace internal { @@ -136,17 +137,33 @@ template struct ReverseADImplementor: ReverseADImplementor { -protected: - +private: + using ReverseADImplementor::_reverseAD; virtual void _reverseAD( const Eigen::Matrix & dFdT, JacobianMap& jacobians) const { static_cast(this)->reverseAD(dFdT, jacobians); } + friend struct internal::ReverseADImplementor; }; template struct ReverseADImplementor : CallRecord { +private: + using CallRecord::_reverseAD; + const Derived & derived() const { + return static_cast(*this); + } + virtual void _reverseAD( + const Eigen::Matrix & dFdT, + JacobianMap& jacobians) const { + derived().reverseAD(dFdT, jacobians); + } + virtual void _reverseAD(const Matrix & dFdT, JacobianMap& jacobians) const { + derived().reverseAD(dFdT, jacobians); + } + friend struct internal::ReverseADImplementor; }; /** @@ -154,7 +171,7 @@ struct ReverseADImplementor : CallRecord { * delegating to its corresponding (templated) non-virtual methods. */ template -struct CallRecordImplementor: public ReverseADImplementor { private: const Derived & derived() const { @@ -166,14 +183,6 @@ private: virtual void _startReverseAD(JacobianMap& jacobians) const { derived().startReverseAD(jacobians); } - virtual void _reverseAD( - const Eigen::Matrix & dFdT, - JacobianMap& jacobians) const { - derived().reverseAD(dFdT, jacobians); - } - virtual void _reverseAD(const Matrix & dFdT, JacobianMap& jacobians) const { - derived().reverseAD(dFdT, jacobians); - } }; } // internal