本文整理汇总了C++中optional::cols方法的典型用法代码示例。如果您正苦于以下问题:C++ optional::cols方法的具体用法?C++ optional::cols怎么用?C++ optional::cols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optional
的用法示例。
在下文中一共展示了optional::cols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: At
void Svd<Real>::jacobi(Matrix& At, Vec& w, Vec_d& wd, optional<Matrix&> Vt, RandomGen& rand)
{
int m = At.cols(), n = w.rows(), n1 = At.rows();
Double eps = Double_::epsilon*10;
int i, j, k, iter, max_iter = std::max(m, 30);
int acols = At.cols(), vcols = Vt ? Vt->cols() : 0;
Real c, s;
Double sd;
for( i = 0; i < n; i++ )
{
for( k = 0, sd = 0; k < m; k++ )
{
Real t = At(i,k);
sd += (Double)t*t;
}
wd[i] = sd;
}
if (Vt) Vt->fromIdentity();
for( iter = 0; iter < max_iter; iter++ )
{
bool changed = false;
for( i = 0; i < n-1; i++ )
for( j = i+1; j < n; j++ )
{
int Ai = i*acols, Aj = j*acols;
Double a = wd[i], p = 0, b = wd[j];
for( k = 0; k < m; k++ )
p += (Double)At(Ai+k)*At(Aj+k);
if( Alge_d::abs(p) <= eps*Alge_d::sqrt((Double)a*b) )
continue;
p *= 2;
Double beta = a - b, gamma = Alge_d::hypot((Double)p, beta), delta;
if( beta < 0 )
{
delta = (gamma - beta)*0.5;
s = (Real)Alge_d::sqrt(delta/gamma);
c = (Real)(p/(gamma*s*2));
}
else
{
c = (Real)Alge_d::sqrt((gamma + beta)/(gamma*2));
s = (Real)(p/(gamma*c*2));
delta = p*p*0.5/(gamma + beta);
}
if( iter % 2 )
{
wd[i] += delta;
wd[j] -= delta;
for( k = 0; k < m; k++ )
{
Real t0 = c*At(Ai+k) + s*At(Aj+k);
Real t1 = -s*At(Ai+k) + c*At(Aj+k);
At(Ai+k) = t0; At(Aj+k) = t1;
}
}
else
{
a = b = 0;
for( k = 0; k < m; k++ )
{
Real t0 = c*At(Ai+k) + s*At(Aj+k);
Real t1 = -s*At(Ai+k) + c*At(Aj+k);
At(Ai+k) = t0; At(Aj+k) = t1;
a += (Double)t0*t0; b += (Double)t1*t1;
}
wd[i] = a; wd[j] = b;
}
changed = true;
if( Vt )
{
int Vi = i*vcols, Vj = j*vcols;
for( k = 0; k < n; k++ )
{
Real t0 = c*(*Vt)(Vi+k) + s*(*Vt)(Vj+k);
Real t1 = -s*(*Vt)(Vi+k) + c*(*Vt)(Vj+k);
(*Vt)(Vi+k) = t0; (*Vt)(Vj+k) = t1;
}
}
}
if( !changed )
break;
}
for( i = 0; i < n; i++ )
{
for( k = 0, sd = 0; k < m; k++ )
{
//.........这里部分代码省略.........