本文整理汇总了C++中SparseMatrix::ProcessQueues方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::ProcessQueues方法的具体用法?C++ SparseMatrix::ProcessQueues怎么用?C++ SparseMatrix::ProcessQueues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix::ProcessQueues方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Helmholtz
void Helmholtz( SparseMatrix<F>& H, Int nx, Int ny, F shift )
{
DEBUG_CSE
typedef Base<F> Real;
const Int n = nx*ny;
Zeros( H, n, n );
const Real hxInv = nx+1;
const Real hyInv = ny+1;
const Real hxInvSquared = hxInv*hxInv;
const Real hyInvSquared = hyInv*hyInv;
const F mainTerm = 2*(hxInvSquared+hyInvSquared) - shift;
H.Reserve( 5*n );
for( Int i=0; i<n; ++i )
{
const Int x = i % nx;
const Int y = i/nx;
H.QueueUpdate( i, i, mainTerm );
if( x != 0 )
H.QueueUpdate( i, i-1, -hxInvSquared );
if( x != nx-1 )
H.QueueUpdate( i, i+1, -hxInvSquared );
if( y != 0 )
H.QueueUpdate( i, i-nx, -hyInvSquared );
if( y != ny-1 )
H.QueueUpdate( i, i+nx, -hyInvSquared );
}
H.ProcessQueues();
}
示例2: T
void ShiftDiagonal
( SparseMatrix<T>& A, S alphaPre, Int offset, bool existingDiag )
{
EL_DEBUG_CSE
const Int m = A.Height();
const Int n = A.Width();
const T alpha = T(alphaPre);
if( existingDiag )
{
T* valBuf = A.ValueBuffer();
for( Int i=Max(0,-offset); i<Min(m,n-offset); ++i )
{
const Int e = A.Offset( i, i+offset );
valBuf[e] += alpha;
}
}
else
{
const Int diagLength = Min(m,n-offset) - Max(0,-offset);
A.Reserve( diagLength );
for( Int i=Max(0,-offset); i<Min(m,n-offset); ++i )
A.QueueUpdate( i, i+offset, alpha );
A.ProcessQueues();
}
}
示例3: func
void EntrywiseMap
( const SparseMatrix<S>& A,
SparseMatrix<T>& B,
function<T(S)> func )
{
DEBUG_CSE
const Int numEntries = A.NumEntries();
B.graph_ = A.graph_;
B.vals_.resize( numEntries );
for( Int k=0; k<numEntries; ++k )
B.vals_[k] = func(A.vals_[k]);
B.ProcessQueues();
}
示例4: Fill
void Fill( SparseMatrix<T>& A, T alpha )
{
EL_DEBUG_CSE
const Int m = A.Height();
const Int n = A.Width();
A.Resize( m, n );
Zero( A );
if( alpha != T(0) )
{
A.Reserve( m*n );
for( Int i=0; i<m; ++i )
for( Int j=0; j<n; ++j )
A.QueueUpdate( i, j, alpha );
A.ProcessQueues();
}
}
示例5: JordanCholesky
void JordanCholesky( SparseMatrix<T>& A, Int n )
{
DEBUG_ONLY(CSE cse("JordanCholesky"))
Zeros( A, n, n );
A.Reserve( 3*n );
for( Int e=0; e<n; ++e )
{
if( e == 0 )
A.QueueUpdate( e, e, T(1) );
else
A.QueueUpdate( e, e, T(5) );
if( e > 0 )
A.QueueUpdate( e, e-1, T(2) );
if( e < n-1 )
A.QueueUpdate( e, e+1, T(2) );
}
A.ProcessQueues();
}
示例6: Zeros
void RLS
( const SparseMatrix<Real>& A,
const Matrix<Real>& b,
Real rho,
Matrix<Real>& x,
const socp::affine::Ctrl<Real>& ctrl )
{
DEBUG_CSE
const Int m = A.Height();
const Int n = A.Width();
Matrix<Int> orders, firstInds;
Zeros( orders, m+n+3, 1 );
Zeros( firstInds, m+n+3, 1 );
for( Int i=0; i<m+1; ++i )
{
orders.Set( i, 0, m+1 );
firstInds.Set( i, 0, 0 );
}
for( Int i=0; i<n+2; ++i )
{
orders.Set( i+m+1, 0, n+2 );
firstInds.Set( i+m+1, 0, m+1 );
}
// G := | -1 0 0 |
// | 0 0 A |
// | 0 -1 0 |
// | 0 0 -I |
// | 0 0 0 |
SparseMatrix<Real> G;
{
const Int numEntriesA = A.NumEntries();
Zeros( G, m+n+3, n+2 );
G.Reserve( numEntriesA+n+2 );
G.QueueUpdate( 0, 0, -1 );
for( Int e=0; e<numEntriesA; ++e )
G.QueueUpdate( A.Row(e)+1, A.Col(e)+2, A.Value(e) );
G.QueueUpdate( m+1, 1, -1 );
for( Int j=0; j<n; ++j )
G.QueueUpdate( j+m+2, j+2, -1 );
G.ProcessQueues();
}
// h := | 0 |
// | b |
// | 0 |
// | 0 |
// | 1 |
Matrix<Real> h;
Zeros( h, m+n+3, 1 );
auto hb = h( IR(1,m+1), ALL );
hb = b;
h.Set( END, 0, 1 );
// c := [1; rho; 0]
Matrix<Real> c;
Zeros( c, n+2, 1 );
c.Set( 0, 0, 1 );
c.Set( 1, 0, rho );
SparseMatrix<Real> AHat;
Zeros( AHat, 0, n+2 );
Matrix<Real> bHat;
Zeros( bHat, 0, 1 );
Matrix<Real> xHat, y, z, s;
SOCP( AHat, G, bHat, c, h, orders, firstInds, xHat, y, z, s, ctrl );
x = xHat( IR(2,END), ALL );
}