gpt4 book ai didi

Armadillo 如何摆脱错误信息

转载 作者:行者123 更新时间:2023-12-04 00:21:50 26 4
gpt4 key购买 nike

尽管已成功捕获异常,但运行以下代码仍会产生一条错误消息,该消息会转到 stdout(而非 stderr):

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

代码运行良好,抖动策略足以满足我的操作,但如果将输出写入标准输出,我必须过滤掉错误消息。

谢谢。

最佳答案

要禁用错误消息的打印,请在包含 Armadillo header 之前定义一个名为 ARMA_DONT_PRINT_ERRORS 的宏。例如:

#define ARMA_DONT_PRINT_ERRORS
#include <armadillo>

关于 Armadillo 如何摆脱错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31547767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com