本文整理汇总了C++中Progress::canceled方法的典型用法代码示例。如果您正苦于以下问题:C++ Progress::canceled方法的具体用法?C++ Progress::canceled怎么用?C++ Progress::canceled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Progress
的用法示例。
在下文中一共展示了Progress::canceled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lincg
void lincg(PyramidT& pyramid, PyramidT& pC,
const Array2Df& b, Array2Df& x,
const int itmax, const float tol,
Progress &ph)
{
float rdotr_curr;
float rdotr_prev;
float rdotr_best;
float alpha;
float beta;
const size_t rows = pyramid.getRows();
const size_t cols = pyramid.getCols();
const size_t n = rows*cols;
const float tol2 = tol*tol;
Array2Df x_best(cols, rows);
Array2Df r(cols, rows);
Array2Df p(cols, rows);
Array2Df Ap(cols, rows);
// bnrm2 = ||b||
const float bnrm2 = utils::dotProduct(b.data(), n);
// r = b - Ax
multiplyA(pyramid, pC, x, r); // r = A x
utils::vsub(b.data(), r.data(), r.data(), n); // r = b - r
// rdotr = r.r
rdotr_best = rdotr_curr = utils::dotProduct(r.data(), n);
// Setup initial vector
std::copy(r.begin(), r.end(), p.begin()); // p = r
std::copy(x.begin(), x.end(), x_best.begin()); // x_best = x
const float irdotr = rdotr_curr;
const float percent_sf = 100.0f/std::log(tol2*bnrm2/irdotr);
int iter = 0;
int num_backwards = 0;
for (; iter < itmax; ++iter)
{
// TEST
ph.setValue(
static_cast<int>(std::log(rdotr_curr/irdotr)*percent_sf)
);
// User requested abort
if ( ph.canceled() && iter > 0 )
{
break;
}
// Ap = A p
multiplyA(pyramid, pC, p, Ap);
// alpha = r.r / (p . Ap)
alpha = rdotr_curr / utils::dotProduct(p.data(), Ap.data(), n);
// r = r - alpha Ap
utils::vsubs(r.data(), alpha, Ap.data(), r.data(), n);
// rdotr = r.r
rdotr_prev = rdotr_curr;
rdotr_curr = utils::dotProduct(r.data(), n);
// Have we gone unstable?
if (rdotr_curr > rdotr_prev)
{
// Save where we've got to
if (num_backwards == 0 && rdotr_prev < rdotr_best)
{
rdotr_best = rdotr_prev;
std::copy(x.begin(), x.end(), x_best.begin());
}
num_backwards++;
}
else
{
num_backwards = 0;
}
// x = x + alpha * p
utils::vadds(x.data(), alpha, p.data(), x.data(), n);
// Exit if we're done
// fprintf(stderr, "iter:%d err:%f\n", iter+1, sqrtf(rdotr/bnrm2));
if (rdotr_curr/bnrm2 < tol2)
break;
if (num_backwards > NUM_BACKWARDS_CEILING)
{
// Reset
num_backwards = 0;
std::copy(x_best.begin(), x_best.end(), x.begin());
// r = Ax
multiplyA(pyramid, pC, x, r);
// r = b - r
//.........这里部分代码省略.........