diff --git a/gtsam/linear/GaussianFactorGraph.cpp b/gtsam/linear/GaussianFactorGraph.cpp index 91b27af4f..766aceec6 100644 --- a/gtsam/linear/GaussianFactorGraph.cpp +++ b/gtsam/linear/GaussianFactorGraph.cpp @@ -79,7 +79,7 @@ namespace gtsam { } /* ************************************************************************* */ - std::vector > GaussianFactorGraph::sparseJacobian() const { + vector > GaussianFactorGraph::sparseJacobian() const { // First find dimensions of each variable vector dims; BOOST_FOREACH(const sharedFactor& factor, *this) { @@ -146,7 +146,7 @@ namespace gtsam { // call sparseJacobian typedef boost::tuple triplet; - std::vector result = sparseJacobian(); + vector result = sparseJacobian(); // translate to base 1 matrix size_t nzmax = result.size(); @@ -169,7 +169,7 @@ namespace gtsam { } /* ************************************************************************* */ - std::pair GaussianFactorGraph::jacobian( + pair GaussianFactorGraph::jacobian( boost::optional optionalOrdering) const { Matrix augmented = augmentedJacobian(optionalOrdering); return make_pair(augmented.leftCols(augmented.cols() - 1), @@ -188,7 +188,7 @@ namespace gtsam { } /* ************************************************************************* */ - std::pair GaussianFactorGraph::hessian( + pair GaussianFactorGraph::hessian( boost::optional optionalOrdering) const { Matrix augmented = augmentedHessian(optionalOrdering); return make_pair( @@ -206,6 +206,24 @@ namespace gtsam { return d; } + /* ************************************************************************* */ + map GaussianFactorGraph::hessianBlockDiagonal() const { + map blocks; + BOOST_FOREACH(const sharedFactor& factor, *this) { + map BD = factor->hessianBlockDiagonal(); + map::const_iterator it = BD.begin(); + for(;it!=BD.end();it++) { + Key j = it->first; // variable key for this block + const Matrix& Bj = it->second; + if (blocks.count(j)) + blocks[j] += Bj; + else + blocks.insert(make_pair(j,Bj)); + } + } + return blocks; + } + /* ************************************************************************* */ VectorValues GaussianFactorGraph::optimize(OptionalOrdering ordering, const Eliminate& function) const { @@ -217,9 +235,9 @@ namespace gtsam { namespace { JacobianFactor::shared_ptr convertToJacobianFactorPtr(const GaussianFactor::shared_ptr &gf) { JacobianFactor::shared_ptr result = boost::dynamic_pointer_cast(gf); - if( !result ) { - result = boost::make_shared(*gf); // Convert any non-Jacobian factors to Jacobians (e.g. Hessian -> Jacobian with Cholesky) - } + if( !result ) + // Convert any non-Jacobian factors to Jacobians (e.g. Hessian -> Jacobian with Cholesky) + result = boost::make_shared(*gf); return result; } }