diff --git a/cpp/Matrix.cpp b/cpp/Matrix.cpp index e7f87098d..04ab4b2ff 100644 --- a/cpp/Matrix.cpp +++ b/cpp/Matrix.cpp @@ -150,16 +150,18 @@ Vector Vector_(const Matrix& A) } /* ************************************************************************* */ -Vector column(const Matrix& A, size_t j) { - if (j>=A.size2()) - throw invalid_argument("Column index out of bounds!"); +Vector column_(const Matrix& A, size_t j) { +// if (j>=A.size2()) +// throw invalid_argument("Column index out of bounds!"); + + return column(A,j); // real boost version // TODO: improve this - size_t m = A.size1(); - Vector a(m); - for (size_t i=0; i(A, j2)); + r(j2) = inner_prod(pseudo, ublas::matrix_column(A, j2)); // TODO: don't use ublas // create the rhs double d = inner_prod(pseudo, b); @@ -359,7 +361,7 @@ weighted_eliminate(Matrix& A, Vector& b, const Vector& sigmas) { // exit after rank exhausted if (results.size()>=maxRank) break; - // update A, b, expensive, suing outer product + // update A, b, expensive, using outer product // A' \define A_{S}-a*r and b'\define b-d*a updateAb(A, b, j, a, r, d); } diff --git a/cpp/Matrix.h b/cpp/Matrix.h index 723523013..813e15d8e 100644 --- a/cpp/Matrix.h +++ b/cpp/Matrix.h @@ -144,11 +144,12 @@ Matrix sub(const Matrix& A, size_t i1, size_t i2, size_t j1, size_t j2); /** * extracts a column from a matrix + * NOTE: using this without the underscore is the ublas version! * @param matrix to extract column from * @param index of the column * @return the column in vector form */ -Vector column(const Matrix& A, size_t j); +Vector column_(const Matrix& A, size_t j); /** * extracts a row from a matrix diff --git a/cpp/NoiseModel.cpp b/cpp/NoiseModel.cpp index bd50756c9..f9c985a99 100644 --- a/cpp/NoiseModel.cpp +++ b/cpp/NoiseModel.cpp @@ -188,7 +188,10 @@ namespace gtsam { // Then update A and b by substituting x with d-rS, zero-ing out x's column. for (size_t j=0; j +#include #include #include "Matrix.h" using namespace std; using namespace gtsam; +namespace ublas = boost::numeric::ublas; /* * Results: @@ -114,13 +116,41 @@ double timeVScaleRow(size_t m, size_t n, size_t reps) { { boost::timer t; for (int i=0; i(M, j); + //result = column(M, j); + elapsed = t.elapsed(); + } + return elapsed; +} + int main(int argc, char ** argv) { // Time collect() @@ -143,5 +173,11 @@ int main(int argc, char ** argv) { double vsRow_time = timeVScaleRow(m1, n1, reps1); cout << "Elapsed time for vector_scale(row) [(" << m1 << ", " << n1 << ") matrix] : " << vsRow_time << endl; + // Time column_() NOTE: using the gtsam version + cout << "Starting column_() Timing" << endl; + size_t reps2 = 200000; + double column_time = timeColumn(reps2); + cout << "Time: " << column_time << " sec" << endl; + return 0; }