【发布时间】:2018-06-26 20:36:42
【问题描述】:
这是以下先前问题的组合:Apply function to all Eigen matrix element 和 Set coefficients of an Eigen::Matrix according an arbitrary distribution。基本上我正在尝试生成一个特征矩阵,其系数从高斯分布中采样。
这是我执行此操作的代码(静态类方法),它返回一个相当神秘的错误消息:
matrix_eig EigenUtil::GaussianNoise(size_t rows, size_t cols,
float mean, float std) {
matrix_eig m(rows, cols);
std::mt19937 rng;
std::normal_distribution<float> nd(mean, std);
auto sampler = [&]() { return nd(rng); };
return matrix_eig::Zero(rows, cols).unaryExpr(sampler);
}
返回错误: 错误:
no type named 'type' in 'std::__1::result_of<(lambda at eigen_util.cpp:101:18) (const float &)>'
typedef typename std::result_of<T>::type type1;
【问题讨论】:
-
这看起来不像一元函数,它看起来像一个空函数。如果您不能使用给定的参数调用给定的函数,
std::result_of是未定义的。试试[&](float /*unused*/)吧?