Always do BOOST_FOREACH with a reference if you can! In this case, made a noticeable difference in performance by avoiding hundreds of thousands of mallocs.
parent
84c25b2346
commit
1cba03a490
|
|
@ -29,10 +29,6 @@
|
||||||
/*template boost::shared_ptr<F> removeAndCombineFactors(FactorGraph<F>&, const std::string&);*/ \
|
/*template boost::shared_ptr<F> removeAndCombineFactors(FactorGraph<F>&, const std::string&);*/ \
|
||||||
template FactorGraph<F> combine(const FactorGraph<F>&, const FactorGraph<F>&);
|
template FactorGraph<F> combine(const FactorGraph<F>&, const FactorGraph<F>&);
|
||||||
|
|
||||||
|
|
||||||
// trick from some reading group
|
|
||||||
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
@ -340,7 +336,7 @@ PredecessorMap<Key> FactorGraph<Factor>::findMinimumSpanningTree() const {
|
||||||
template<class Factor> template <class Key, class Factor2>
|
template<class Factor> template <class Key, class Factor2>
|
||||||
void FactorGraph<Factor>::split(const PredecessorMap<Key>& tree, FactorGraph<Factor>& Ab1, FactorGraph<Factor>& Ab2) const{
|
void FactorGraph<Factor>::split(const PredecessorMap<Key>& tree, FactorGraph<Factor>& Ab1, FactorGraph<Factor>& Ab2) const{
|
||||||
|
|
||||||
BOOST_FOREACH(sharedFactor factor, factors_){
|
BOOST_FOREACH(const sharedFactor& factor, factors_){
|
||||||
if (factor->keys().size() > 2)
|
if (factor->keys().size() > 2)
|
||||||
throw(invalid_argument("split: only support factors with at most two keys"));
|
throw(invalid_argument("split: only support factors with at most two keys"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace gtsam {
|
||||||
template<class Config>
|
template<class Config>
|
||||||
Vector NonlinearFactorGraph<Config>::unwhitenedError(const Config& c) const {
|
Vector NonlinearFactorGraph<Config>::unwhitenedError(const Config& c) const {
|
||||||
list<Vector> errors;
|
list<Vector> errors;
|
||||||
BOOST_FOREACH(typename NonlinearFactorGraph<Config>::sharedFactor factor, this->factors_)
|
BOOST_FOREACH(const sharedFactor& factor, this->factors_)
|
||||||
errors.push_back(factor->unwhitenedError(c));
|
errors.push_back(factor->unwhitenedError(c));
|
||||||
return concatVectors(errors);
|
return concatVectors(errors);
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +35,7 @@ namespace gtsam {
|
||||||
double NonlinearFactorGraph<Config>::error(const Config& c) const {
|
double NonlinearFactorGraph<Config>::error(const Config& c) const {
|
||||||
double total_error = 0.;
|
double total_error = 0.;
|
||||||
// iterate over all the factors_ to accumulate the log probabilities
|
// iterate over all the factors_ to accumulate the log probabilities
|
||||||
BOOST_FOREACH(typename NonlinearFactorGraph<Config>::sharedFactor factor, this->factors_)
|
BOOST_FOREACH(const sharedFactor& factor, this->factors_)
|
||||||
total_error += factor->error(c);
|
total_error += factor->error(c);
|
||||||
return total_error;
|
return total_error;
|
||||||
}
|
}
|
||||||
|
|
@ -49,8 +49,7 @@ namespace gtsam {
|
||||||
boost::shared_ptr<GaussianFactorGraph> linearFG(new GaussianFactorGraph);
|
boost::shared_ptr<GaussianFactorGraph> linearFG(new GaussianFactorGraph);
|
||||||
|
|
||||||
// linearize all factors
|
// linearize all factors
|
||||||
typedef typename NonlinearFactorGraph<Config>::sharedFactor Factor;
|
BOOST_FOREACH(const sharedFactor& factor, this->factors_) {
|
||||||
BOOST_FOREACH(const Factor& factor, this->factors_) {
|
|
||||||
boost::shared_ptr<GaussianFactor> lf = factor->linearize(config);
|
boost::shared_ptr<GaussianFactor> lf = factor->linearize(config);
|
||||||
linearFG->push_back(lf);
|
linearFG->push_back(lf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ namespace gtsam {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef typename boost::shared_ptr<NonlinearFactor<Config> > sharedFactor;
|
||||||
|
|
||||||
/** unnormalized error */
|
/** unnormalized error */
|
||||||
double error(const Config& c) const;
|
double error(const Config& c) const;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue