Fixed compiler warnings
parent
92d705e25b
commit
ad0bd147f0
|
@ -85,7 +85,7 @@ bool FactorGraph<Factor>::equals
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
size_t FactorGraph<Factor>::nrFactors() const {
|
size_t FactorGraph<Factor>::nrFactors() const {
|
||||||
int size_ = 0;
|
size_t size_ = 0;
|
||||||
for (const_iterator factor = factors_.begin(); factor != factors_.end(); factor++)
|
for (const_iterator factor = factors_.begin(); factor != factors_.end(); factor++)
|
||||||
if (*factor != NULL) size_++;
|
if (*factor != NULL) size_++;
|
||||||
return size_;
|
return size_;
|
||||||
|
@ -97,7 +97,7 @@ void FactorGraph<Factor>::push_back(sharedFactor factor) {
|
||||||
factors_.push_back(factor); // add the actual factor
|
factors_.push_back(factor); // add the actual factor
|
||||||
if (factor==NULL) return;
|
if (factor==NULL) return;
|
||||||
|
|
||||||
int i = factors_.size() - 1; // index of factor
|
size_t i = factors_.size() - 1; // index of factor
|
||||||
associateFactor(i, factor);
|
associateFactor(i, factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,16 +150,16 @@ std::pair<FactorGraph<Factor>, set<Symbol> > FactorGraph<Factor>::removeSingleto
|
||||||
// find all the singleton variables
|
// find all the singleton variables
|
||||||
Ordering new_singletons;
|
Ordering new_singletons;
|
||||||
Symbol key;
|
Symbol key;
|
||||||
list<int> indices;
|
list<size_t> indices;
|
||||||
BOOST_FOREACH(boost::tie(key, indices), indices_) {
|
BOOST_FOREACH(boost::tie(key, indices), indices_) {
|
||||||
// find out the number of factors associated with the current key
|
// find out the number of factors associated with the current key
|
||||||
int numValidFactors = 0;
|
size_t numValidFactors = 0;
|
||||||
BOOST_FOREACH(const int& i, indices)
|
BOOST_FOREACH(const size_t& i, indices)
|
||||||
if (factors_[i]!=NULL) numValidFactors++;
|
if (factors_[i]!=NULL) numValidFactors++;
|
||||||
|
|
||||||
if (numValidFactors == 1) {
|
if (numValidFactors == 1) {
|
||||||
new_singletons.push_back(key);
|
new_singletons.push_back(key);
|
||||||
BOOST_FOREACH(const int& i, indices)
|
BOOST_FOREACH(const size_t& i, indices)
|
||||||
if (factors_[i]!=NULL) singletonGraph.push_back(factors_[i]);
|
if (factors_[i]!=NULL) singletonGraph.push_back(factors_[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ Ordering FactorGraph<Factor>::getConstrainedOrdering(const set<Symbol>& lastKeys
|
||||||
/** O(1) */
|
/** O(1) */
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
list<int> FactorGraph<Factor>::factors(const Symbol& key) const {
|
list<size_t> FactorGraph<Factor>::factors(const Symbol& key) const {
|
||||||
return indices_.at(key);
|
return indices_.at(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,10 +322,10 @@ Factors FactorGraph<Factor>::findAndRemoveFactors(const Symbol& key) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
"FactorGraph::findAndRemoveFactors: key "
|
"FactorGraph::findAndRemoveFactors: key "
|
||||||
+ (string)key + " not found");
|
+ (string)key + " not found");
|
||||||
const list<int>& factorsAssociatedWithKey = it->second;
|
const list<size_t>& factorsAssociatedWithKey = it->second;
|
||||||
|
|
||||||
Factors found;
|
Factors found;
|
||||||
BOOST_FOREACH(const int& i, factorsAssociatedWithKey) {
|
BOOST_FOREACH(const size_t& i, factorsAssociatedWithKey) {
|
||||||
sharedFactor& fi = factors_.at(i); // throws exception !
|
sharedFactor& fi = factors_.at(i); // throws exception !
|
||||||
if(fi == NULL) continue; // skip NULL factors
|
if(fi == NULL) continue; // skip NULL factors
|
||||||
found.push_back(fi); // add to found
|
found.push_back(fi); // add to found
|
||||||
|
@ -339,7 +339,7 @@ Factors FactorGraph<Factor>::findAndRemoveFactors(const Symbol& key) {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
void FactorGraph<Factor>::associateFactor(int index, const sharedFactor& factor) {
|
void FactorGraph<Factor>::associateFactor(size_t index, const sharedFactor& factor) {
|
||||||
const list<Symbol> keys = factor->keys(); // get keys for factor
|
const list<Symbol> keys = factor->keys(); // get keys for factor
|
||||||
// rtodo: Can optimize factor->keys to return a const reference
|
// rtodo: Can optimize factor->keys to return a const reference
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ template<class Factor> void FactorGraph<Factor>::checkGraphConsistency() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure each factor listed for a variable actually involves that variable
|
// Make sure each factor listed for a variable actually involves that variable
|
||||||
BOOST_FOREACH(const SymbolMap<list<int> >::value_type& var, indices_) {
|
BOOST_FOREACH(const SymbolMap<list<size_t> >::value_type& var, indices_) {
|
||||||
BOOST_FOREACH(size_t i, var.second) {
|
BOOST_FOREACH(size_t i, var.second) {
|
||||||
if(i >= factors_.size()) {
|
if(i >= factors_.size()) {
|
||||||
cout << "*** Factor graph inconsistency: " << (string)var.first << " lists factor " <<
|
cout << "*** Factor graph inconsistency: " << (string)var.first << " lists factor " <<
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace gtsam {
|
||||||
std::vector<sharedFactor> factors_;
|
std::vector<sharedFactor> factors_;
|
||||||
|
|
||||||
/** For each variable a list of factor indices connected to it */
|
/** For each variable a list of factor indices connected to it */
|
||||||
typedef SymbolMap<std::list<int> > Indices;
|
typedef SymbolMap<std::list<size_t> > Indices;
|
||||||
Indices indices_;
|
Indices indices_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -117,7 +117,7 @@ namespace gtsam {
|
||||||
* Return indices for all factors that involve the given node
|
* Return indices for all factors that involve the given node
|
||||||
* @param key the key for the given node
|
* @param key the key for the given node
|
||||||
*/
|
*/
|
||||||
std::list<int> factors(const Symbol& key) const;
|
std::list<size_t> factors(const Symbol& key) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find all the factors that involve the given node and remove them
|
* find all the factors that involve the given node and remove them
|
||||||
|
@ -151,7 +151,7 @@ namespace gtsam {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Associate factor index with the variables connected to the factor */
|
/** Associate factor index with the variables connected to the factor */
|
||||||
void associateFactor(int index, const sharedFactor& factor);
|
void associateFactor(size_t index, const sharedFactor& factor);
|
||||||
|
|
||||||
/** Serialization function */
|
/** Serialization function */
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
|
|
|
@ -14,21 +14,21 @@ using namespace gtsam;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
GaussianConditional::GaussianConditional(const Symbol& key,Vector d, Matrix R, Vector sigmas) :
|
GaussianConditional::GaussianConditional(const Symbol& key,Vector d, Matrix R, Vector sigmas) :
|
||||||
Conditional (key), R_(R),sigmas_(sigmas),d_(d)
|
Conditional (key), R_(R),d_(d),sigmas_(sigmas)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
GaussianConditional::GaussianConditional(const Symbol& key, Vector d, Matrix R,
|
GaussianConditional::GaussianConditional(const Symbol& key, Vector d, Matrix R,
|
||||||
const Symbol& name1, Matrix S, Vector sigmas) :
|
const Symbol& name1, Matrix S, Vector sigmas) :
|
||||||
Conditional (key), R_(R), sigmas_(sigmas), d_(d) {
|
Conditional (key), R_(R), d_(d), sigmas_(sigmas) {
|
||||||
parents_.insert(make_pair(name1, S));
|
parents_.insert(make_pair(name1, S));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
GaussianConditional::GaussianConditional(const Symbol& key, Vector d, Matrix R,
|
GaussianConditional::GaussianConditional(const Symbol& key, Vector d, Matrix R,
|
||||||
const Symbol& name1, Matrix S, const Symbol& name2, Matrix T, Vector sigmas) :
|
const Symbol& name1, Matrix S, const Symbol& name2, Matrix T, Vector sigmas) :
|
||||||
Conditional (key), R_(R),sigmas_(sigmas), d_(d) {
|
Conditional (key), R_(R), d_(d),sigmas_(sigmas) {
|
||||||
parents_.insert(make_pair(name1, S));
|
parents_.insert(make_pair(name1, S));
|
||||||
parents_.insert(make_pair(name2, T));
|
parents_.insert(make_pair(name2, T));
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ GaussianConditional::GaussianConditional(const Symbol& key, Vector d, Matrix R,
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
GaussianConditional::GaussianConditional(const Symbol& key,
|
GaussianConditional::GaussianConditional(const Symbol& key,
|
||||||
const Vector& d, const Matrix& R, const SymbolMap<Matrix>& parents, Vector sigmas) :
|
const Vector& d, const Matrix& R, const SymbolMap<Matrix>& parents, Vector sigmas) :
|
||||||
Conditional (key), R_(R),sigmas_(sigmas), d_(d), parents_(parents) {
|
Conditional (key), R_(R), parents_(parents), d_(d),sigmas_(sigmas) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -64,7 +64,7 @@ bool GaussianConditional::equals(const Conditional &c, double tol) const {
|
||||||
if (parents_.size() != p->parents_.size()) return false;
|
if (parents_.size() != p->parents_.size()) return false;
|
||||||
|
|
||||||
// check if R_ and d_ are equal up to a sign
|
// check if R_ and d_ are equal up to a sign
|
||||||
for (int i=0; i<d_.size(); i++) {
|
for (size_t i=0; i<d_.size(); i++) {
|
||||||
Vector row1 = row_(R_, i);
|
Vector row1 = row_(R_, i);
|
||||||
Vector row2 = row_(p->R_, i);
|
Vector row2 = row_(p->R_, i);
|
||||||
if (!((::equal_with_abs_tol(row1, row2, tol) && fabs(d_(i) - p->d_(i)) < tol) ||
|
if (!((::equal_with_abs_tol(row1, row2, tol) && fabs(d_(i) - p->d_(i)) < tol) ||
|
||||||
|
|
|
@ -77,7 +77,6 @@ GaussianFactor::GaussianFactor(const boost::shared_ptr<GaussianConditional>& cg)
|
||||||
for (; it != cg->parentsEnd(); it++)
|
for (; it != cg->parentsEnd(); it++)
|
||||||
As_.insert(*it);
|
As_.insert(*it);
|
||||||
// set sigmas from precisions
|
// set sigmas from precisions
|
||||||
size_t n = b_.size();
|
|
||||||
model_ = noiseModel::Diagonal::Sigmas(cg->get_sigmas(), true);
|
model_ = noiseModel::Diagonal::Sigmas(cg->get_sigmas(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +166,7 @@ bool GaussianFactor::equals(const Factor<VectorConfig>& f, double tol) const {
|
||||||
if(As_.size() != lf->As_.size()) return false;
|
if(As_.size() != lf->As_.size()) return false;
|
||||||
|
|
||||||
// check whether each row is up to a sign
|
// check whether each row is up to a sign
|
||||||
for (int i=0; i<b_.size(); i++) {
|
for (size_t i=0; i<b_.size(); i++) {
|
||||||
list<Vector> row1;
|
list<Vector> row1;
|
||||||
list<Vector> row2;
|
list<Vector> row2;
|
||||||
row1.push_back(Vector_(1, b_(i)));
|
row1.push_back(Vector_(1, b_(i)));
|
||||||
|
@ -442,7 +441,6 @@ GaussianFactor::eliminateMatrix(Matrix& Ab, SharedDiagonal model,
|
||||||
pair<GaussianConditional::shared_ptr, GaussianFactor::shared_ptr>
|
pair<GaussianConditional::shared_ptr, GaussianFactor::shared_ptr>
|
||||||
GaussianFactor::eliminate(const Symbol& key) const
|
GaussianFactor::eliminate(const Symbol& key) const
|
||||||
{
|
{
|
||||||
bool verbose = false;
|
|
||||||
// if this factor does not involve key, we exit with empty CG and LF
|
// if this factor does not involve key, we exit with empty CG and LF
|
||||||
const_iterator it = As_.find(key);
|
const_iterator it = As_.find(key);
|
||||||
if (it==As_.end()) {
|
if (it==As_.end()) {
|
||||||
|
|
|
@ -146,12 +146,16 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the first key
|
* return the first key
|
||||||
|
* TODO: this function should be removed and the minimum spanning tree code
|
||||||
|
* modified accordingly.
|
||||||
* @return The set of all variable keys
|
* @return The set of all variable keys
|
||||||
*/
|
*/
|
||||||
Symbol key1() const { return As_.begin()->first; }
|
Symbol key1() const { return As_.begin()->first; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the first key
|
* return the first key
|
||||||
|
* TODO: this function should be removed and the minimum spanning tree code
|
||||||
|
* modified accordingly.
|
||||||
* @return The set of all variable keys
|
* @return The set of all variable keys
|
||||||
*/
|
*/
|
||||||
Symbol key2() const {
|
Symbol key2() const {
|
||||||
|
|
|
@ -166,7 +166,7 @@ bool linear_dependent(const Matrix& A, const Matrix& B, double tol) {
|
||||||
|
|
||||||
if(m1!=m2 || n1!=n2) return false;
|
if(m1!=m2 || n1!=n2) return false;
|
||||||
|
|
||||||
for(int i=0; i<m1; i++) {
|
for(size_t i=0; i<m1; i++) {
|
||||||
if (!gtsam::linear_dependent(row_(A,i), row_(B,i), tol))
|
if (!gtsam::linear_dependent(row_(A,i), row_(B,i), tol))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,12 @@ namespace noiseModel {
|
||||||
static void updateAb(Matrix& Ab, int j, const Vector& a, const Vector& rd) {
|
static void updateAb(Matrix& Ab, int j, const Vector& a, const Vector& rd) {
|
||||||
size_t m = Ab.size1(), n = Ab.size2()-1;
|
size_t m = Ab.size1(), n = Ab.size2()-1;
|
||||||
|
|
||||||
for (int i = 0; i < m; i++) { // update all rows
|
for (size_t i = 0; i < m; i++) { // update all rows
|
||||||
double ai = a(i);
|
double ai = a(i);
|
||||||
double *Aij = Ab.data().begin() + i * (n+1) + j + 1;
|
double *Aij = Ab.data().begin() + i * (n+1) + j + 1;
|
||||||
const double *rptr = rd.data().begin() + j + 1;
|
const double *rptr = rd.data().begin() + j + 1;
|
||||||
// Ab(i,j+1:end) -= ai*rd(j+1:end)
|
// Ab(i,j+1:end) -= ai*rd(j+1:end)
|
||||||
for (int j2 = j + 1; j2 < n+1; j2++, Aij++, rptr++)
|
for (size_t j2 = j + 1; j2 < n+1; j2++, Aij++, rptr++)
|
||||||
*Aij -= ai * (*rptr);
|
*Aij -= ai * (*rptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ Gaussian::shared_ptr Gaussian::Covariance(const Matrix& covariance, bool smart)
|
||||||
if (m != n) throw invalid_argument("Gaussian::Covariance: covariance not square");
|
if (m != n) throw invalid_argument("Gaussian::Covariance: covariance not square");
|
||||||
if (smart) {
|
if (smart) {
|
||||||
// check all non-diagonal entries
|
// check all non-diagonal entries
|
||||||
int i,j;
|
size_t i,j;
|
||||||
for (i = 0; i < m; i++)
|
for (i = 0; i < m; i++)
|
||||||
for (j = 0; j < n; j++)
|
for (j = 0; j < n; j++)
|
||||||
if (i != j && fabs(covariance(i, j) > 1e-9)) goto full;
|
if (i != j && fabs(covariance(i, j) > 1e-9)) goto full;
|
||||||
|
@ -128,7 +128,7 @@ SharedDiagonal Gaussian::QR(Matrix& Ab) const {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Diagonal::Diagonal(const Vector& sigmas) :
|
Diagonal::Diagonal(const Vector& sigmas) :
|
||||||
Gaussian(sigmas.size()), invsigmas_(reciprocal(sigmas)), sigmas_(sigmas) {
|
Gaussian(sigmas.size()), sigmas_(sigmas), invsigmas_(reciprocal(sigmas)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Diagonal::shared_ptr Diagonal::Variances(const Vector& variances, bool smart) {
|
Diagonal::shared_ptr Diagonal::Variances(const Vector& variances, bool smart) {
|
||||||
|
@ -174,7 +174,7 @@ void Diagonal::WhitenInPlace(Matrix& H) const {
|
||||||
|
|
||||||
Vector Diagonal::sample() const {
|
Vector Diagonal::sample() const {
|
||||||
Vector result(dim_);
|
Vector result(dim_);
|
||||||
for (int i = 0; i < dim_; i++) {
|
for (size_t i = 0; i < dim_; i++) {
|
||||||
typedef boost::normal_distribution<double> Normal;
|
typedef boost::normal_distribution<double> Normal;
|
||||||
Normal dist(0.0, this->sigmas_(i));
|
Normal dist(0.0, this->sigmas_(i));
|
||||||
boost::variate_generator<boost::minstd_rand&, Normal> norm(generator, dist);
|
boost::variate_generator<boost::minstd_rand&, Normal> norm(generator, dist);
|
||||||
|
@ -315,7 +315,7 @@ Vector Isotropic::sample() const {
|
||||||
Normal dist(0.0, this->sigma_);
|
Normal dist(0.0, this->sigma_);
|
||||||
boost::variate_generator<boost::minstd_rand&, Normal> norm(generator, dist);
|
boost::variate_generator<boost::minstd_rand&, Normal> norm(generator, dist);
|
||||||
Vector result(dim_);
|
Vector result(dim_);
|
||||||
for (int i = 0; i < dim_; i++)
|
for (size_t i = 0; i < dim_; i++)
|
||||||
result(i) = norm();
|
result(i) = norm();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,14 @@ namespace gtsam { // note, deliberately not in noiseModel namespace
|
||||||
inline SharedDiagonal sharedSigmas(const Vector& sigmas) {
|
inline SharedDiagonal sharedSigmas(const Vector& sigmas) {
|
||||||
return noiseModel::Diagonal::Sigmas(sigmas);
|
return noiseModel::Diagonal::Sigmas(sigmas);
|
||||||
}
|
}
|
||||||
inline SharedDiagonal sharedSigma(int dim, double sigma) {
|
inline SharedDiagonal sharedSigma(size_t dim, double sigma) {
|
||||||
return noiseModel::Isotropic::Sigma(dim, sigma);
|
return noiseModel::Isotropic::Sigma(dim, sigma);
|
||||||
}
|
}
|
||||||
|
inline SharedDiagonal sharedPrecisions(const Vector& precisions) {
|
||||||
|
return noiseModel::Diagonal::Precisions(precisions);
|
||||||
|
}
|
||||||
|
inline SharedDiagonal sharedPrecision(size_t dim, double precision) {
|
||||||
|
return noiseModel::Isotropic::Precision(dim, precision);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,6 @@ pair<sharedPose2Graph, sharedPose2Config> load2D(const string& filename,
|
||||||
string tag;
|
string tag;
|
||||||
|
|
||||||
// load the poses
|
// load the poses
|
||||||
bool firstPose;
|
|
||||||
while (is) {
|
while (is) {
|
||||||
is >> tag;
|
is >> tag;
|
||||||
|
|
||||||
|
@ -200,7 +199,6 @@ bool load3D(const string& filename) {
|
||||||
is.clear(); /* clears the end-of-file and error flags */
|
is.clear(); /* clears the end-of-file and error flags */
|
||||||
is.seekg(0, ios::beg);
|
is.seekg(0, ios::beg);
|
||||||
|
|
||||||
bool edgesOk = true;
|
|
||||||
while (is) {
|
while (is) {
|
||||||
char buf[LINESIZE];
|
char buf[LINESIZE];
|
||||||
is.getline(buf, LINESIZE);
|
is.getline(buf, LINESIZE);
|
||||||
|
|
|
@ -120,8 +120,8 @@ predecessorMap2Graph(const PredecessorMap<Key>& p_map) {
|
||||||
|
|
||||||
if (!foundRoot)
|
if (!foundRoot)
|
||||||
throw invalid_argument("predecessorMap2Graph: invalid predecessor map!");
|
throw invalid_argument("predecessorMap2Graph: invalid predecessor map!");
|
||||||
|
else
|
||||||
return boost::tuple<G, V, std::map<Key, V> >(g, root, key2vertex);
|
return boost::tuple<G, V, std::map<Key, V> >(g, root, key2vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -110,7 +110,7 @@ int main()
|
||||||
size_t n1 = 10000000;
|
size_t n1 = 10000000;
|
||||||
timeLog = clock();
|
timeLog = clock();
|
||||||
|
|
||||||
for(int i = 0; i < n1; i++)
|
for(size_t i = 0; i < n1; i++)
|
||||||
Matrix Ab = combined.matrix_augmented(ordering, true);
|
Matrix Ab = combined.matrix_augmented(ordering, true);
|
||||||
|
|
||||||
timeLog2 = clock();
|
timeLog2 = clock();
|
||||||
|
|
|
@ -35,7 +35,7 @@ double timeCollect(size_t p, size_t m, size_t n, bool passDims, size_t reps) {
|
||||||
|
|
||||||
// fill the matrices with identities
|
// fill the matrices with identities
|
||||||
vector<const Matrix *> matrices;
|
vector<const Matrix *> matrices;
|
||||||
for (int i=0; i<p;++i) {
|
for (size_t i=0; i<p;++i) {
|
||||||
Matrix * M = new Matrix;
|
Matrix * M = new Matrix;
|
||||||
(*M) = eye(m,n);
|
(*M) = eye(m,n);
|
||||||
matrices.push_back(M);
|
matrices.push_back(M);
|
||||||
|
@ -48,15 +48,15 @@ double timeCollect(size_t p, size_t m, size_t n, bool passDims, size_t reps) {
|
||||||
boost::timer t;
|
boost::timer t;
|
||||||
|
|
||||||
if (passDims)
|
if (passDims)
|
||||||
for (int i=0; i<reps; ++i)
|
for (size_t i=0; i<reps; ++i)
|
||||||
result = collect(matrices, m, n);
|
result = collect(matrices, m, n);
|
||||||
else
|
else
|
||||||
for (int i=0; i<reps; ++i)
|
for (size_t i=0; i<reps; ++i)
|
||||||
result = collect(matrices);
|
result = collect(matrices);
|
||||||
elapsed = t.elapsed();
|
elapsed = t.elapsed();
|
||||||
}
|
}
|
||||||
// delete the matrices
|
// delete the matrices
|
||||||
for (int i=0; i<p;++i) {
|
for (size_t i=0; i<p;++i) {
|
||||||
delete matrices[i];
|
delete matrices[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,20 +74,20 @@ double timeCollect(size_t p, size_t m, size_t n, bool passDims, size_t reps) {
|
||||||
double timeVScaleColumn(size_t m, size_t n, size_t reps) {
|
double timeVScaleColumn(size_t m, size_t n, size_t reps) {
|
||||||
// make a matrix to scale
|
// make a matrix to scale
|
||||||
Matrix M(m, n);
|
Matrix M(m, n);
|
||||||
for (int i=0; i<m; ++i)
|
for (size_t i=0; i<m; ++i)
|
||||||
for (int j=0; j<n; ++j)
|
for (size_t j=0; j<n; ++j)
|
||||||
M(i,j) = 2*i+j;
|
M(i,j) = 2*i+j;
|
||||||
|
|
||||||
// make a vector to use for scaling
|
// make a vector to use for scaling
|
||||||
Vector V(m);
|
Vector V(m);
|
||||||
for (int i=0; i<m; ++i)
|
for (size_t i=0; i<m; ++i)
|
||||||
V(i) = i*2;
|
V(i) = i*2;
|
||||||
|
|
||||||
double elapsed;
|
double elapsed;
|
||||||
Matrix result;
|
Matrix result;
|
||||||
{
|
{
|
||||||
boost::timer t;
|
boost::timer t;
|
||||||
for (int i=0; i<reps; ++i)
|
for (size_t i=0; i<reps; ++i)
|
||||||
Matrix result = vector_scale(M,V);
|
Matrix result = vector_scale(M,V);
|
||||||
elapsed = t.elapsed();
|
elapsed = t.elapsed();
|
||||||
}
|
}
|
||||||
|
@ -105,20 +105,20 @@ double timeVScaleColumn(size_t m, size_t n, size_t reps) {
|
||||||
double timeVScaleRow(size_t m, size_t n, size_t reps) {
|
double timeVScaleRow(size_t m, size_t n, size_t reps) {
|
||||||
// make a matrix to scale
|
// make a matrix to scale
|
||||||
Matrix M(m, n);
|
Matrix M(m, n);
|
||||||
for (int i=0; i<m; ++i)
|
for (size_t i=0; i<m; ++i)
|
||||||
for (int j=0; j<n; ++j)
|
for (size_t j=0; j<n; ++j)
|
||||||
M(i,j) = 2*i+j;
|
M(i,j) = 2*i+j;
|
||||||
|
|
||||||
// make a vector to use for scaling
|
// make a vector to use for scaling
|
||||||
Vector V(n);
|
Vector V(n);
|
||||||
for (int i=0; i<n; ++i)
|
for (size_t i=0; i<n; ++i)
|
||||||
V(i) = i*2;
|
V(i) = i*2;
|
||||||
|
|
||||||
double elapsed;
|
double elapsed;
|
||||||
Matrix result;
|
Matrix result;
|
||||||
{
|
{
|
||||||
boost::timer t;
|
boost::timer t;
|
||||||
for (int i=0; i<reps; ++i)
|
for (size_t i=0; i<reps; ++i)
|
||||||
result = vector_scale(V,M);
|
result = vector_scale(V,M);
|
||||||
elapsed = t.elapsed();
|
elapsed = t.elapsed();
|
||||||
}
|
}
|
||||||
|
@ -139,8 +139,8 @@ double timeColumn(size_t reps) {
|
||||||
// create a matrix
|
// create a matrix
|
||||||
size_t m = 100; size_t n = 100;
|
size_t m = 100; size_t n = 100;
|
||||||
Matrix M(m, n);
|
Matrix M(m, n);
|
||||||
for (int i=0; i<m; ++i)
|
for (size_t i=0; i<m; ++i)
|
||||||
for (int j=0; j<n; ++j)
|
for (size_t j=0; j<n; ++j)
|
||||||
M(i,j) = 2*i+j;
|
M(i,j) = 2*i+j;
|
||||||
|
|
||||||
// extract a column
|
// extract a column
|
||||||
|
|
|
@ -85,7 +85,7 @@ struct Value {
|
||||||
double v;
|
double v;
|
||||||
Value() : v(0.0) {}
|
Value() : v(0.0) {}
|
||||||
Value(double vi) : v(vi) {}
|
Value(double vi) : v(vi) {}
|
||||||
operator string() { lexical_cast<string>(v); }
|
operator string() { return lexical_cast<string>(v); }
|
||||||
bool operator!=(const Value& vc) { return v != vc.v; }
|
bool operator!=(const Value& vc) { return v != vc.v; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,4 +175,6 @@ int main(int argc, char *argv[]) {
|
||||||
cout << i << " values, avg " << (time/(double)i)*1e6 << " mu-s per lookup" << endl;
|
cout << i << " values, avg " << (time/(double)i)*1e6 << " mu-s per lookup" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ using namespace gtsam;
|
||||||
double time = t.elapsed(); \
|
double time = t.elapsed(); \
|
||||||
cout << "Average elapsed time :" << 10e3 * time / n << "ms." << endl; }
|
cout << "Average elapsed time :" << 10e3 * time / n << "ms." << endl; }
|
||||||
|
|
||||||
#define TIME(STATEMENT) TIME1(for (int j = 0; j < n; ++j) STATEMENT;)
|
#define TIME(STATEMENT) TIME1(for (size_t j = 0; j < n; ++j) STATEMENT;)
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
|
@ -44,7 +44,7 @@ int main(int argc, char ** argv) {
|
||||||
VectorBTree p, q;
|
VectorBTree p, q;
|
||||||
VectorMap old;
|
VectorMap old;
|
||||||
cout << "Creating VectorBTree:" << endl;
|
cout << "Creating VectorBTree:" << endl;
|
||||||
TIME1(for (int i = 0; i < m; ++i) {
|
TIME1(for (size_t i = 0; i < m; ++i) {
|
||||||
Vector v = zero(r);
|
Vector v = zero(r);
|
||||||
Symbol key('x', i);
|
Symbol key('x', i);
|
||||||
p.insert(key, v);
|
p.insert(key, v);
|
||||||
|
@ -59,10 +59,10 @@ int main(int argc, char ** argv) {
|
||||||
TIME(axpy(alpha,p,q));
|
TIME(axpy(alpha,p,q));
|
||||||
|
|
||||||
cout << "VectorBTree get:" << endl;
|
cout << "VectorBTree get:" << endl;
|
||||||
TIME1(for (int i = 0; i < m; ++i) p[Symbol('x', i)]);
|
TIME1(for (size_t i = 0; i < m; ++i) p[Symbol('x', i)]);
|
||||||
|
|
||||||
cout << "VectorMap get:" << endl;
|
cout << "VectorMap get:" << endl;
|
||||||
TIME1(for (int i = 0; i < m; ++i) old[Symbol('x', i)]);
|
TIME1(for (size_t i = 0; i < m; ++i) old[Symbol('x', i)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue