diff --git a/gtsam_unstable/nonlinear/Expression-inl.h b/gtsam_unstable/nonlinear/Expression-inl.h index 215f19c1a..ca8ff1bea 100644 --- a/gtsam_unstable/nonlinear/Expression-inl.h +++ b/gtsam_unstable/nonlinear/Expression-inl.h @@ -26,6 +26,8 @@ #include #include +#include +#include // template meta-programming headers #include @@ -48,7 +50,8 @@ namespace gtsam { template class Expression; -typedef std::vector > > JacobianMap; +typedef std::pair > JacobianPair; +typedef std::vector JacobianMap; //----------------------------------------------------------------------------- /** @@ -78,28 +81,20 @@ struct CallRecord { template void handleLeafCase(const Eigen::Matrix& dTdA, JacobianMap& jacobians, Key key) { - for(JacobianMap::iterator it = jacobians.begin(); it != jacobians.end(); ++it) - { - if(it->first == key) - { - it->second.block(0, 0) += dTdA; // block makes HUGE difference - break; - } - } + JacobianMap::iterator it = std::find_if(jacobians.begin(), jacobians.end(), + boost::bind(&JacobianPair::first, _1)==key); + assert(it~= jacobians.end()); + it->second.block(0, 0) += dTdA; // block makes HUGE difference } /// Handle Leaf Case for Dynamic Matrix type (slower) template<> void handleLeafCase( const Eigen::Matrix& dTdA, JacobianMap& jacobians, Key key) { - for(JacobianMap::iterator it = jacobians.begin(); it != jacobians.end(); ++it) - { - if(it->first == key) - { - it->second += dTdA; // block makes HUGE difference - break; - } - } + JacobianMap::iterator it = std::find_if(jacobians.begin(), jacobians.end(), + boost::bind(&JacobianPair::first, _1)==key); + assert(it~= jacobians.end()); + it->second += dTdA; } //-----------------------------------------------------------------------------