本文整理汇总了C++中vec::each方法的典型用法代码示例。如果您正苦于以下问题:C++ vec::each方法的具体用法?C++ vec::each怎么用?C++ vec::each使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec
的用法示例。
在下文中一共展示了vec::each方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solve
vec bokhoven::solve(const vec& q, const stop& s, vec x ) const {
const natural n = lcp.dim();
assert(q.rows() == int(n));
if(x.empty()) { x = vec::Zero(n); }
assert( x.rows() == q.rows() );
const mat& M = lcp.M;
algo::iter_eps(s, [&](real& eps) {
x.each([&](natural i ) {
const real x_i = x(i);
x(i) = (q(i) - this->P.row(i).dot(x) + std::abs( x(i) ) - M.row(i).dot(x.array().abs().matrix()) ) / this->d(i);
const real diff = x(i) - x_i;
eps += diff * diff;
});
eps = std::sqrt(eps);
});
return (x.array().abs() + x.array());
}
示例2: print_vec
static void print_vec(const vec& eta) {
mat zob = mat::Zero(eta.rows(), 2);
eta.each([&](natural i) {
zob.col(0)(i) = i;
zob.col(1)(i) = eta(i);
});
core::log()("Cumulative variance:");
core::log()(zob);
}
示例3: cumul
vec pca::cumul(const vec& eig) {
vec res = vec::Zero(eig.rows());
real sum = 0;
eig.each([&](natural i ) {
sum += eig(i) * eig(i);
res(i) = sum;
});
assert( sum > 0 );
res /= sum;
return res;
}
示例4: cond
real cond( const vec& eigen) {
real min = 1e42;
real max = 0;
eigen.each([&](natural i) {
real ei = std::abs( eigen(i) );
if( ei < min ) min = ei;
if( ei > max ) max = ei;
});
assert( min );
return max / min;
}