犰狳如何摆脱错误信息 [英] armadillo how to get rid of error message
本文介绍了犰狳如何摆脱错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行以下代码仍会产生一条错误消息,尽管已成功捕获到异常,但该消息会转到stdout(不是stderr):
Running the following code still produces an error message that goes to stdout (not stderr) although the exception was successfully caught:
Mat<double> matrix_quantiles(const vector<double> & quantiles,
const Mat<double> & m) {
Mat<double> sorted_matrix;
try {
sorted_matrix = arma::sort(arma::cor(m));
} catch(std::logic_error & e) {
/*
Sometimes a col is constant, causing the correlation to be
infinite. If that happens, add normal random jitter to the
values and retry.
*/
const Mat<double> jitter = Mat<double>(
m.n_rows, m.n_cols, arma::fill::randn);
return matrix_quantiles(quantiles, 1.e-3 * jitter + m);
}
etc.
错误消息是:
error: sort(): given object has non-finite elements
代码运行良好,抖动策略足以胜任我的工作,但是如果我将输出写入stdout,则必须过滤掉错误消息.
The code runs fine, and the jittering strategy is good enough for what I do, but I have to filter out the error message if I write the output to stdout.
谢谢.
推荐答案
要禁用打印错误消息,请在包含Armadillo标头之前定义一个名为 ARMA_DONT_PRINT_ERRORS
的宏.例如:
To disable printing of error messagaes, define a macro named ARMA_DONT_PRINT_ERRORS
before including the Armadillo header. For example:
#define ARMA_DONT_PRINT_ERRORS
#include <armadillo>
这篇关于犰狳如何摆脱错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文