Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
Created March 17, 2020 03:11
Show Gist options
  • Save insaneyilin/d08efa50a3dd6033ede2bc1259dbcd33 to your computer and use it in GitHub Desktop.
Save insaneyilin/d08efa50a3dd6033ede2bc1259dbcd33 to your computer and use it in GitHub Desktop.
Print Eigen's Matrix
void PrintEigenMat(const Eigen::Ref<const Eigen::MatrixXd> &x,
const std::string mat_name) {
if (!mat_name.empty()) {
std::cout << mat_name << " =\n";
}
const int rows = x.rows();
const int cols = x.cols();
char buf[200];
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
double val = x(i, j);
sprintf(buf, "%.8lf", val);
std::cout << "\t" << std::setprecision(9) << buf;
}
std::cout << std::endl;
}
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment