Merged in feature/MatrixPrinting (pull request #105)

Use Eigen::format for printing matrices
release/4.3a0
Frank Dellaert 2015-10-22 13:14:43 -07:00
commit 2f1b60fa9d
2 changed files with 23 additions and 19 deletions

View File

@ -184,21 +184,17 @@ void transposeMultiplyAdd(double alpha, const Matrix& A, const Vector& e, SubVec
/* ************************************************************************* */ /* ************************************************************************* */
//3 argument call //3 argument call
void print(const Matrix& A, const string &s, ostream& stream) { void print(const Matrix& A, const string &s, ostream& stream) {
size_t m = A.rows(), n = A.cols(); static const Eigen::IOFormat matlab(
Eigen::StreamPrecision, // precision
// print out all elements 0, // flags
stream << s << "[\n"; " ", // coeffSeparator
for( size_t i = 0 ; i < m ; i++) { ";\n", // rowSeparator
for( size_t j = 0 ; j < n ; j++) { " \t", // rowPrefix
double aij = A(i,j); "", // rowSuffix
if(aij != 0.0) "[\n", // matPrefix
stream << setw(12) << setprecision(9) << aij << ",\t"; "\n ]" // matSuffix
else );
stream << " 0.0,\t"; cout << s << A.format(matlab) << endl;
}
stream << endl;
}
stream << "];" << endl;
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -347,13 +347,21 @@ JacobianFactor::JacobianFactor(const GaussianFactorGraph& graph,
/* ************************************************************************* */ /* ************************************************************************* */
void JacobianFactor::print(const string& s, void JacobianFactor::print(const string& s,
const KeyFormatter& formatter) const { const KeyFormatter& formatter) const {
static const Eigen::IOFormat matlab(
Eigen::StreamPrecision, // precision
0, // flags
" ", // coeffSeparator
";\n", // rowSeparator
"\t", // rowPrefix
"", // rowSuffix
"[\n", // matPrefix
"\n ]" // matSuffix
);
if (!s.empty()) if (!s.empty())
cout << s << "\n"; cout << s << "\n";
for (const_iterator key = begin(); key != end(); ++key) { for (const_iterator key = begin(); key != end(); ++key) {
cout cout << boost::format(" A[%1%] = ") % formatter(*key);
<< formatMatrixIndented( cout << getA(key).format(matlab) << endl;
(boost::format(" A[%1%] = ") % formatter(*key)).str(), getA(key))
<< endl;
} }
cout << formatMatrixIndented(" b = ", getb(), true) << "\n"; cout << formatMatrixIndented(" b = ", getb(), true) << "\n";
if (model_) if (model_)