From 7cdb9b3564670d812bf9357fdaaa4c3e03f4b046 Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Fri, 4 Feb 2011 00:49:20 +0000 Subject: [PATCH] print(Matrix) now formats to allow pasting into C++ code, by including commas and formatting zeros as '0.0' --- gtsam/base/Matrix.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 56516d735..0e19fbf8d 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -379,7 +379,10 @@ void print(const Matrix& A, const string &s, ostream& stream) { for( size_t i = 0 ; i < m ; i++) { for( size_t j = 0 ; j < n ; j++) { double aij = A(i,j); - stream << setw(9) << (fabs(aij)<1e-12 ? 0 : aij) << "\t"; + if(aij != 0.0) + stream << setw(12) << setprecision(9) << aij << ",\t"; + else + stream << " 0.0,\t"; } stream << endl; }