Changed the type of JacobianMap as std::vector
parent
c1c6a30e50
commit
97d4120858
|
@ -48,7 +48,8 @@ namespace gtsam {
|
|||
template<typename T>
|
||||
class Expression;
|
||||
|
||||
typedef std::map<Key, Eigen::Block<Matrix> > JacobianMap;
|
||||
//typedef std::map<Key, Eigen::Block<Matrix> > JacobianMap;
|
||||
typedef std::vector<std::pair<Key, Eigen::Block<Matrix> > > JacobianMap;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
|
@ -78,16 +79,28 @@ struct CallRecord {
|
|||
template<int ROWS, int COLS>
|
||||
void handleLeafCase(const Eigen::Matrix<double, ROWS, COLS>& dTdA,
|
||||
JacobianMap& jacobians, Key key) {
|
||||
JacobianMap::iterator it = jacobians.find(key);
|
||||
it->second.block<ROWS, COLS>(0, 0) += dTdA; // block makes HUGE difference
|
||||
for(JacobianMap::iterator it = jacobians.begin(); it != jacobians.end(); ++it)
|
||||
{
|
||||
if((*it).first == key)
|
||||
{
|
||||
(*it).second.block<ROWS, COLS>(0, 0) += dTdA; // block makes HUGE difference
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Handle Leaf Case for Dynamic Matrix type (slower)
|
||||
template<>
|
||||
void handleLeafCase(
|
||||
const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>& dTdA,
|
||||
JacobianMap& jacobians, Key key) {
|
||||
JacobianMap::iterator it = jacobians.find(key);
|
||||
it->second += dTdA;
|
||||
for(JacobianMap::iterator it = jacobians.begin(); it != jacobians.end(); ++it)
|
||||
{
|
||||
if((*it).first == key)
|
||||
{
|
||||
(*it).second += dTdA; // block makes HUGE difference
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -87,12 +87,13 @@ public:
|
|||
|
||||
// Create and zero out blocks to be passed to expression_
|
||||
JacobianMap blocks;
|
||||
blocks.reserve(size());
|
||||
for (DenseIndex i = 0; i < size(); i++) {
|
||||
Matrix& Hi = H->at(i);
|
||||
Hi.resize(Dim, dimensions_[i]);
|
||||
Hi.setZero(); // zero out
|
||||
Eigen::Block<Matrix> block = Hi.block(0, 0, Dim, dimensions_[i]);
|
||||
blocks.insert(std::make_pair(keys_[i], block));
|
||||
blocks.push_back(std::make_pair(keys_[i], block));
|
||||
}
|
||||
|
||||
T value = expression_.value(x, blocks);
|
||||
|
@ -121,8 +122,9 @@ public:
|
|||
|
||||
// Create blocks into Ab_ to be passed to expression_
|
||||
JacobianMap blocks;
|
||||
blocks.reserve(size());
|
||||
for (DenseIndex i = 0; i < size(); i++)
|
||||
blocks.insert(std::make_pair(keys_[i], Ab(i)));
|
||||
blocks.push_back(std::make_pair(keys_[i], Ab(i)));
|
||||
|
||||
// Evaluate error to get Jacobians and RHS vector b
|
||||
T value = expression_.value(x, blocks); // <<< Reverse AD happens here !
|
||||
|
|
Loading…
Reference in New Issue