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
void print(const Matrix& A, const string &s, ostream& stream) {
size_t m = A.rows(), n = A.cols();
// print out all elements
stream << s << "[\n";
for( size_t i = 0 ; i < m ; i++) {
for( size_t j = 0 ; j < n ; j++) {
double aij = A(i,j);
if(aij != 0.0)
stream << setw(12) << setprecision(9) << aij << ",\t";
else
stream << " 0.0,\t";
}
stream << endl;
}
stream << "];" << endl;
static const Eigen::IOFormat matlab(
Eigen::StreamPrecision, // precision
0, // flags
" ", // coeffSeparator
";\n", // rowSeparator
" \t", // rowPrefix
"", // rowSuffix
"[\n", // matPrefix
"\n ]" // matSuffix
);
cout << s << A.format(matlab) << endl;
}
/* ************************************************************************* */

View File

@ -347,13 +347,21 @@ JacobianFactor::JacobianFactor(const GaussianFactorGraph& graph,
/* ************************************************************************* */
void JacobianFactor::print(const string& s,
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())
cout << s << "\n";
for (const_iterator key = begin(); key != end(); ++key) {
cout
<< formatMatrixIndented(
(boost::format(" A[%1%] = ") % formatter(*key)).str(), getA(key))
<< endl;
cout << boost::format(" A[%1%] = ") % formatter(*key);
cout << getA(key).format(matlab) << endl;
}
cout << formatMatrixIndented(" b = ", getb(), true) << "\n";
if (model_)