From 0a5f2205343eb95f75d63c70f09cdb049985243e Mon Sep 17 00:00:00 2001 From: alexhagiopol Date: Fri, 20 Feb 2015 14:33:15 -0500 Subject: [PATCH 1/6] 10% reduction in lines of code included by Vector.h. --- gtsam/base/Matrix.h | 6 ++++++ gtsam/base/Vector.cpp | 5 +++-- gtsam/base/Vector.h | 12 +++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index c3cbfa341..294b5e63a 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -27,6 +27,12 @@ #include #include +#include +#include +#include +#include + + /** * Matrix is a typedef in the gtsam namespace * TODO: make a version to work with matlab wrapping diff --git a/gtsam/base/Vector.cpp b/gtsam/base/Vector.cpp index a9ef8fe10..5368e708e 100644 --- a/gtsam/base/Vector.cpp +++ b/gtsam/base/Vector.cpp @@ -16,9 +16,10 @@ * @author Frank Dellaert */ + #include #include -#include +//#include #include #include #include @@ -27,7 +28,7 @@ #include #include #include - +#include //added by alex #include diff --git a/gtsam/base/Vector.h b/gtsam/base/Vector.h index 74cd248a1..58e1d2ff6 100644 --- a/gtsam/base/Vector.h +++ b/gtsam/base/Vector.h @@ -18,14 +18,16 @@ // \callgraph + #pragma once - #include -#include -#include +//#include +//#include #include -#include - +//#include +//#include +//#include +#include namespace gtsam { // Vector is just a typedef of the Eigen dynamic vector type From 7dca1d76a55fd614ffb96c01685acea0d67e809f Mon Sep 17 00:00:00 2001 From: alexhagiopol Date: Fri, 20 Feb 2015 17:09:17 -0500 Subject: [PATCH 2/6] More reductions in included lines. --- gtsam/base/FastSet.h | 2 +- gtsam/base/GenericValue.h | 2 +- gtsam/base/Matrix.h | 1 - gtsam/base/Vector.cpp | 3 +-- gtsam/base/Vector.h | 5 ----- gtsam/base/types.cpp | 2 +- gtsam/base/types.h | 5 +++-- gtsam/geometry/EssentialMatrix.h | 2 +- 8 files changed, 8 insertions(+), 14 deletions(-) diff --git a/gtsam/base/FastSet.h b/gtsam/base/FastSet.h index 69e841e57..810a48c60 100644 --- a/gtsam/base/FastSet.h +++ b/gtsam/base/FastSet.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/gtsam/base/GenericValue.h b/gtsam/base/GenericValue.h index c67f7dd61..dd0811d8b 100644 --- a/gtsam/base/GenericValue.h +++ b/gtsam/base/GenericValue.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include // operator typeid namespace gtsam { diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index 294b5e63a..d5c433d35 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -21,7 +21,6 @@ // \callgraph #pragma once - #include #include #include diff --git a/gtsam/base/Vector.cpp b/gtsam/base/Vector.cpp index 5368e708e..1b145a116 100644 --- a/gtsam/base/Vector.cpp +++ b/gtsam/base/Vector.cpp @@ -19,7 +19,6 @@ #include #include -//#include #include #include #include @@ -28,7 +27,7 @@ #include #include #include -#include //added by alex +#include #include diff --git a/gtsam/base/Vector.h b/gtsam/base/Vector.h index 58e1d2ff6..d19fee298 100644 --- a/gtsam/base/Vector.h +++ b/gtsam/base/Vector.h @@ -21,12 +21,7 @@ #pragma once #include -//#include -//#include #include -//#include -//#include -//#include #include namespace gtsam { diff --git a/gtsam/base/types.cpp b/gtsam/base/types.cpp index 3f86dc0c1..9a0d6c627 100644 --- a/gtsam/base/types.cpp +++ b/gtsam/base/types.cpp @@ -18,7 +18,7 @@ */ #include - +//#include #include #include diff --git a/gtsam/base/types.h b/gtsam/base/types.h index aca04a14b..839016fd9 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -21,10 +21,11 @@ #include #include - +//#include +#include #include #include -#include +#include #include #include #include diff --git a/gtsam/geometry/EssentialMatrix.h b/gtsam/geometry/EssentialMatrix.h index 606f62f87..9ebcbcf5c 100644 --- a/gtsam/geometry/EssentialMatrix.h +++ b/gtsam/geometry/EssentialMatrix.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace gtsam { From 3f4558cacb2a8b86230e3cfcb2940240211ce227 Mon Sep 17 00:00:00 2001 From: alexhagiopol Date: Mon, 23 Feb 2015 18:45:25 -0500 Subject: [PATCH 3/6] SVD removed from Matrix.h --- gtsam/base/Matrix.cpp | 16 ++++++++++++++++ gtsam/base/Matrix.h | 19 ++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 7bcd32b9f..7136db768 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -32,6 +32,9 @@ #include #include +#include +#include + using namespace std; namespace gtsam { @@ -697,6 +700,19 @@ std::string formatMatrixIndented(const std::string& label, const Matrix& matrix, return ss.str(); } +void inplace_QR(Matrix& A){ + size_t rows = A.rows(); + size_t cols = A.cols(); + size_t size = std::min(rows,cols); + typedef Eigen::internal::plain_diag_type::type HCoeffsType; + typedef Eigen::internal::plain_row_type::type RowVectorType; + HCoeffsType hCoeffs(size); + RowVectorType temp(cols); + + Eigen::internal::householder_qr_inplace_blocked::run(A, hCoeffs, 48, temp.data()); + + zeroBelowDiagonal(A); +} } // namespace gtsam diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index d5c433d35..ee3c84464 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -25,10 +25,8 @@ #include #include #include - #include #include -#include #include @@ -372,21 +370,8 @@ GTSAM_EXPORT std::pair qr(const Matrix& A); * @param A is the input matrix, and is the output * @param clear_below_diagonal enables zeroing out below diagonal */ -template -void inplace_QR(MATRIX& A) { - size_t rows = A.rows(); - size_t cols = A.cols(); - size_t size = std::min(rows,cols); - - typedef Eigen::internal::plain_diag_type::type HCoeffsType; - typedef Eigen::internal::plain_row_type::type RowVectorType; - HCoeffsType hCoeffs(size); - RowVectorType temp(cols); - - Eigen::internal::householder_qr_inplace_blocked::run(A, hCoeffs, 48, temp.data()); - - zeroBelowDiagonal(A); -} +//template +void inplace_QR(Matrix& A); /** * Imperative algorithm for in-place full elimination with From c13bde99f2e03644ef19bd22ffc817843c116583 Mon Sep 17 00:00:00 2001 From: alexhagiopol Date: Tue, 24 Feb 2015 00:19:13 -0500 Subject: [PATCH 4/6] More header bloat reduction. --- gtsam/base/Matrix.h | 1 - gtsam/base/types.cpp | 1 - gtsam/base/types.h | 1 - gtsam/nonlinear/Values.h | 6 ------ 4 files changed, 9 deletions(-) diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index ee3c84464..fc9f27099 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -370,7 +370,6 @@ GTSAM_EXPORT std::pair qr(const Matrix& A); * @param A is the input matrix, and is the output * @param clear_below_diagonal enables zeroing out below diagonal */ -//template void inplace_QR(Matrix& A); /** diff --git a/gtsam/base/types.cpp b/gtsam/base/types.cpp index 9a0d6c627..4f61c6a1d 100644 --- a/gtsam/base/types.cpp +++ b/gtsam/base/types.cpp @@ -18,7 +18,6 @@ */ #include -//#include #include #include diff --git a/gtsam/base/types.h b/gtsam/base/types.h index 839016fd9..d0ba526c2 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -21,7 +21,6 @@ #include #include -//#include #include #include #include diff --git a/gtsam/nonlinear/Values.h b/gtsam/nonlinear/Values.h index 73d0711be..ad727f45e 100644 --- a/gtsam/nonlinear/Values.h +++ b/gtsam/nonlinear/Values.h @@ -26,14 +26,9 @@ #include #include -#include #include - -#include -#include #include #include -#include #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" @@ -43,7 +38,6 @@ #pragma GCC diagnostic pop #endif #include -#include #include #include From 77770b48b51135660bad396a3ddacee2f18735bc Mon Sep 17 00:00:00 2001 From: alexhagiopol Date: Tue, 24 Feb 2015 14:39:08 -0500 Subject: [PATCH 5/6] Include in types.h only when TBB is on. --- gtsam/base/FastSet.h | 3 +-- gtsam/base/Vector.h | 1 + gtsam/base/types.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gtsam/base/FastSet.h b/gtsam/base/FastSet.h index 810a48c60..29fb3fcd9 100644 --- a/gtsam/base/FastSet.h +++ b/gtsam/base/FastSet.h @@ -19,9 +19,8 @@ #pragma once #include - #include -#include +#include #include #include #include diff --git a/gtsam/base/Vector.h b/gtsam/base/Vector.h index d19fee298..1c433eb4a 100644 --- a/gtsam/base/Vector.h +++ b/gtsam/base/Vector.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace gtsam { // Vector is just a typedef of the Eigen dynamic vector type diff --git a/gtsam/base/types.h b/gtsam/base/types.h index d0ba526c2..122bc18a0 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include #endif #ifdef GTSAM_USE_EIGEN_MKL_OPENMP From d8468567b2533ca9a684a7f59f7593fd75836e0c Mon Sep 17 00:00:00 2001 From: alexhagiopol Date: Mon, 2 Mar 2015 20:19:59 -0500 Subject: [PATCH 6/6] MOre bloat reduction and header ordering. --- gtsam/base/FastSet.h | 8 ++++---- gtsam/base/Matrix.cpp | 12 +++++++++--- gtsam/base/Matrix.h | 13 +++++++++---- gtsam/base/Value.h | 5 +++-- gtsam/base/Vector.cpp | 17 +++++++++++------ gtsam/base/Vector.h | 14 ++++++++++---- gtsam/base/types.cpp | 2 +- gtsam/base/types.h | 6 +++--- 8 files changed, 50 insertions(+), 27 deletions(-) diff --git a/gtsam/base/FastSet.h b/gtsam/base/FastSet.h index 29fb3fcd9..4ef963f5d 100644 --- a/gtsam/base/FastSet.h +++ b/gtsam/base/FastSet.h @@ -19,14 +19,14 @@ #pragma once #include -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include BOOST_MPL_HAS_XXX_TRAIT_DEF(print) diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 7136db768..7fa0992ca 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -32,9 +34,6 @@ #include #include -#include -#include - using namespace std; namespace gtsam { @@ -183,6 +182,7 @@ void transposeMultiplyAdd(double alpha, const Matrix& A, const Vector& e, SubVec } /* ************************************************************************* */ +//3 argument call void print(const Matrix& A, const string &s, ostream& stream) { size_t m = A.rows(), n = A.cols(); @@ -201,6 +201,12 @@ void print(const Matrix& A, const string &s, ostream& stream) { stream << "];" << endl; } +/* ************************************************************************* */ +//1 or 2 argument call +void print(const Matrix& A, const string &s){ + print(A, s, cout); +} + /* ************************************************************************* */ void save(const Matrix& A, const string &s, const string& filename) { fstream stream(filename.c_str(), fstream::out | fstream::app); diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index fc9f27099..27b7ec8f7 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -22,12 +22,12 @@ #pragma once #include -#include -#include #include #include #include #include +#include +#include /** @@ -201,9 +201,14 @@ inline MATRIX prod(const MATRIX& A, const MATRIX&B) { } /** - * print a matrix + * print without optional string, must specify cout yourself */ -GTSAM_EXPORT void print(const Matrix& A, const std::string& s = "", std::ostream& stream = std::cout); +GTSAM_EXPORT void print(const Matrix& A, const std::string& s, std::ostream& stream); + +/** + * print with optional string to cout + */ +GTSAM_EXPORT void print(const Matrix& A, const std::string& s = ""); /** * save a matrix to file, which can be loaded by matlab diff --git a/gtsam/base/Value.h b/gtsam/base/Value.h index a12f453f4..70677cad1 100644 --- a/gtsam/base/Value.h +++ b/gtsam/base/Value.h @@ -18,9 +18,10 @@ #pragma once -#include -#include #include +#include +#include + namespace gtsam { diff --git a/gtsam/base/Vector.cpp b/gtsam/base/Vector.cpp index 1b145a116..0a708427a 100644 --- a/gtsam/base/Vector.cpp +++ b/gtsam/base/Vector.cpp @@ -16,20 +16,18 @@ * @author Frank Dellaert */ - +#include +#include +#include +#include #include #include #include #include #include #include -#include -#include -#include #include #include -#include - using namespace std; @@ -55,6 +53,7 @@ Vector delta(size_t n, size_t i, double value) { } /* ************************************************************************* */ +//3 argument call void print(const Vector& v, const string& s, ostream& stream) { size_t n = v.size(); @@ -65,6 +64,12 @@ void print(const Vector& v, const string& s, ostream& stream) { stream << "];" << endl; } +/* ************************************************************************* */ +//1 or 2 argument call +void print(const Vector& v, const string& s) { + print(v, s, cout); +} + /* ************************************************************************* */ void save(const Vector& v, const string &s, const string& filename) { fstream stream(filename.c_str(), fstream::out | fstream::app); diff --git a/gtsam/base/Vector.h b/gtsam/base/Vector.h index 1c433eb4a..2d333848b 100644 --- a/gtsam/base/Vector.h +++ b/gtsam/base/Vector.h @@ -20,10 +20,11 @@ #pragma once -#include #include #include -#include +#include +#include + namespace gtsam { // Vector is just a typedef of the Eigen dynamic vector type @@ -95,9 +96,14 @@ GTSAM_EXPORT bool zero(const Vector& v); inline size_t dim(const Vector& v) { return v.size(); } /** - * print with optional string + * print without optional string, must specify cout yourself */ -GTSAM_EXPORT void print(const Vector& v, const std::string& s = "", std::ostream& stream = std::cout); +GTSAM_EXPORT void print(const Vector& v, const std::string& s, std::ostream& stream); + +/** + * print with optional string to cout + */ +GTSAM_EXPORT void print(const Vector& v, const std::string& s = ""); /** * save a vector to file, which can be loaded by matlab diff --git a/gtsam/base/types.cpp b/gtsam/base/types.cpp index 4f61c6a1d..03e7fd120 100644 --- a/gtsam/base/types.cpp +++ b/gtsam/base/types.cpp @@ -17,9 +17,9 @@ * @addtogroup base */ -#include #include #include +#include namespace gtsam { diff --git a/gtsam/base/types.h b/gtsam/base/types.h index 122bc18a0..a66db13c8 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -21,12 +21,12 @@ #include #include -#include -#include -#include #include #include #include +#include +#include +#include #ifdef GTSAM_USE_TBB #include