本文整理汇总了C++中eigen::Matrix::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::swap方法的具体用法?C++ Matrix::swap怎么用?C++ Matrix::swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Matrix
的用法示例。
在下文中一共展示了Matrix::swap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: alpha
//.........这里部分代码省略.........
const REAL sdg(-(fu1.dot(lamu1) + fu2.dot(lamu2)));
if (sdg < pdtol)
break;
const REAL tau(mu*2*M/sdg);
const REAL inv_tau = REAL(-1)/tau;
tmpM1 = (-lamu1.cwiseProduct(fu1)).array() + inv_tau;
tmpM2 = (-lamu2.cwiseProduct(fu2)).array() + inv_tau;
const REAL resnorm = sqrt(AtvNormSq + rdualNormSq + tmpM1.squaredNorm() + tmpM2.squaredNorm());
for (unsigned i=0; i<M; ++i) {
REAL& tmpM3i = tmpM3(i);
tmpM3i = inv_tau/fu1(i);
REAL& tmpM4i = tmpM4(i);
tmpM4i = inv_tau/fu2(i);
w2(i) = tmpM3i + tmpM4i - REAL(1);
}
tmpM1 = lamu1.cwiseQuotient(fu1);
tmpM2 = lamu2.cwiseQuotient(fu2);
sig1 = -tmpM1 - tmpM2;
sig2 = tmpM1 - tmpM2;
sigx = sig1 - sig2.cwiseAbs2().cwiseQuotient(sig1);
H11p = At*(Eigen::DiagonalMatrix<REAL,Eigen::Dynamic>(sigx)*A);
w1p = At*(tmpM4 - tmpM3 - (sig2.cwiseQuotient(sig1).cwiseProduct(w2)));
// optimized solver as A is positive definite and symmetric
dx = H11p.ldlt().solve(w1p);
Adx = A*dx;
du = (w2 - sig2.cwiseProduct(Adx)).cwiseQuotient(sig1);
dlamu1 = -tmpM1.cwiseProduct(Adx-du) - lamu1 + tmpM3;
dlamu2 = tmpM2.cwiseProduct(Adx+du) - lamu2 + tmpM4;
Atdv = At*(dlamu1-dlamu2);
// make sure that the step is feasible: keeps lamu1,lamu2 > 0, fu1,fu2 < 0
REAL s(1);
for (unsigned i=0; i<M; ++i) {
REAL& dlamu1i = dlamu1(i);
if (dlamu1i < 0) {
const REAL tmp = -lamu1(i)/dlamu1i;
if (s > tmp)
s = tmp;
}
REAL& dlamu2i = dlamu2(i);
if (dlamu2i < 0) {
const REAL tmp = -lamu2(i)/dlamu2i;
if (s > tmp)
s = tmp;
}
}
for (unsigned i=0; i<M; ++i) {
REAL& Adxi = Adx(i);
REAL& dui = du(i);
REAL Adx_du = Adxi-dui;
if (Adx_du > 0) {
const REAL tmp = -fu1(i)/Adx_du;
if (s > tmp)
s = tmp;
}
Adx_du = -Adxi-dui;
if (Adx_du > 0) {
const REAL tmp = -fu2(i)/Adx_du;
if (s > tmp)
s = tmp;
}
}
s *= REAL(0.99);
// backtrack
lamu1 += s*dlamu1; lamu2 += s*dlamu2;
rdual = (-lamu1-lamu2).array() + REAL(1);
rdualNormSq = rdual.squaredNorm();
bool suffdec = false;
unsigned backiter = 0;
do {
xp = x + s*dx; up = u + s*du;
Axp = Ax + s*Adx; Atvp = Atv + s*Atdv;
fu1 = Axp - y - up; fu2 = -Axp + y - up;
AtvNormSq = Atvp.squaredNorm();
tmpM1 = (-lamu1.cwiseProduct(fu1)).array() + inv_tau;
tmpM2 = (-lamu2.cwiseProduct(fu2)).array() + inv_tau;
const REAL newresnorm = sqrt(AtvNormSq + rdualNormSq + tmpM1.squaredNorm() + tmpM2.squaredNorm());
suffdec = (newresnorm <= (REAL(1)-alpha*s)*resnorm);
s = beta*s;
if (++backiter > 32) {
//("error: stuck backtracking, returning last iterate"); // see Section 4 of notes for more information
xp.swap(x);
return false;
}
} while (!suffdec);
// next iteration
x.swap(xp); u.swap(up);
Ax.swap(Axp); Atv.swap(Atvp);
}
return true;
}
示例2: swap
inline void swap(Eigen::Matrix<_Scalar,_Rows,_Cols,_StorageOrder,_MaxRows,_MaxCols>& lhs,Eigen::Matrix<_Scalar,_Rows,_Cols,_StorageOrder,_MaxRows,_MaxCols>& rhs)
{
lhs.swap(rhs);
}