solved the issue with empty rows
parent
ddd84ee598
commit
6c4c4f150e
|
|
@ -222,19 +222,23 @@ void FactorGraph<Factor>::getOrdering(Ordering& ordering, boost::optional<const
|
||||||
// Below, we compute a symbolic matrix stored in sparse columns.
|
// Below, we compute a symbolic matrix stored in sparse columns.
|
||||||
map<Symbol, vector<int> > columns; // map from keys to a sparse column of non-zero row indices
|
map<Symbol, vector<int> > columns; // map from keys to a sparse column of non-zero row indices
|
||||||
int nrNonZeros = 0; // number of non-zero entries
|
int nrNonZeros = 0; // number of non-zero entries
|
||||||
int n_row = factors_.size(); /* colamd arg 1: number of rows in A */
|
int n_row = 0; /* colamd arg 1: number of rows in A */
|
||||||
|
|
||||||
// loop over all factors = rows
|
// loop over all factors = rows
|
||||||
bool hasInterested = interested.is_initialized();
|
bool hasInterested = interested.is_initialized();
|
||||||
for (int i = 0; i < n_row; i++) {
|
bool inserted;
|
||||||
if (factors_[i]==NULL) continue;
|
BOOST_FOREACH(const sharedFactor& factor, factors_) {
|
||||||
list<Symbol> keys = factors_[i]->keys();
|
if (factor==NULL) continue;
|
||||||
|
list<Symbol> keys = factor->keys();
|
||||||
|
inserted = false;
|
||||||
BOOST_FOREACH(const Symbol& key, keys) {
|
BOOST_FOREACH(const Symbol& key, keys) {
|
||||||
if (!hasInterested || interested->find(key) != interested->end()) {
|
if (!hasInterested || interested->find(key) != interested->end()) {
|
||||||
columns[key].push_back(i);
|
columns[key].push_back(n_row);
|
||||||
nrNonZeros++;
|
nrNonZeros++;
|
||||||
|
inserted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (inserted) n_row++;
|
||||||
}
|
}
|
||||||
int n_col = (int)(columns.size()); /* colamd arg 2: number of columns in A */
|
int n_col = (int)(columns.size()); /* colamd arg 2: number of columns in A */
|
||||||
if(n_col != 0)
|
if(n_col != 0)
|
||||||
|
|
|
||||||
|
|
@ -37,3 +37,16 @@ Ordering Ordering::subtract(const Ordering& keys) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
void Unordered::print(const string& s) const {
|
||||||
|
cout << s << " (" << size() << "):";
|
||||||
|
BOOST_FOREACH(const Symbol& key, *this)
|
||||||
|
cout << " " << (string)key;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
bool Unordered::equals(const Unordered &other, double tol) const {
|
||||||
|
return *this == other;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Testable.h"
|
#include "Testable.h"
|
||||||
#include "Key.h"
|
#include "Key.h"
|
||||||
|
|
@ -43,4 +44,26 @@ namespace gtsam {
|
||||||
Ordering subtract(const Ordering& keys) const;
|
Ordering subtract(const Ordering& keys) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class Unordered
|
||||||
|
* @brief a set of unordered indice
|
||||||
|
*/
|
||||||
|
class Unordered: public std::set<Symbol>, public Testable<Unordered> {
|
||||||
|
public:
|
||||||
|
/** Default constructor creates empty ordering */
|
||||||
|
Unordered() { }
|
||||||
|
|
||||||
|
/** Create from a single symbol */
|
||||||
|
Unordered(Symbol key) { insert(key); }
|
||||||
|
|
||||||
|
/** Copy constructor */
|
||||||
|
Unordered(const std::set<Symbol>& keys_in) : std::set<Symbol>(keys_in) {}
|
||||||
|
|
||||||
|
/** whether a key exists */
|
||||||
|
bool exists(const Symbol& key) { return find(key) != end(); }
|
||||||
|
|
||||||
|
// Testable
|
||||||
|
void print(const std::string& s = "Unordered") const;
|
||||||
|
bool equals(const Unordered &t, double tol=0) const;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue