本文整理汇总了C++中DVectorSlice::size方法的典型用法代码示例。如果您正苦于以下问题:C++ DVectorSlice::size方法的具体用法?C++ DVectorSlice::size怎么用?C++ DVectorSlice::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DVectorSlice
的用法示例。
在下文中一共展示了DVectorSlice::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Vp_StMtV
void MatrixSymDiagStd::Vp_StMtV(
DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
, const DVectorSlice& vs_rhs2, value_type beta) const
{
const DVectorSlice diag = this->diag();
size_type n = diag.size();
//
// y = b*y + a * op(A) * x
//
DenseLinAlgPack::Vp_MtV_assert_sizes(
vs_lhs->size(), n, n, trans_rhs1, vs_rhs2.size() );
//
// A is symmetric and diagonal A = diag(diag) so:
//
// y(j) += a * diag(j) * x(j), for j = 1...n
//
if( vs_rhs2.stride() == 1 && vs_lhs->stride() == 1 ) {
// Optimized implementation
const value_type
*d_itr = diag.raw_ptr(),
*x_itr = vs_rhs2.raw_ptr();
value_type
*y_itr = vs_lhs->raw_ptr(),
*y_end = y_itr + vs_lhs->size();
if( beta == 0.0 ) {
while( y_itr != y_end )
*y_itr++ = alpha * (*d_itr++) * (*x_itr++);
}
else if( beta == 1.0 ) {
while( y_itr != y_end )
*y_itr++ += alpha * (*d_itr++) * (*x_itr++);
}
else {
for( ; y_itr != y_end; ++y_itr )
*y_itr = beta * (*y_itr) + alpha * (*d_itr++) * (*x_itr++);
}
}
else {
// Generic implementation
DVectorSlice::const_iterator
d_itr = diag.begin(),
x_itr = vs_rhs2.begin();
DVectorSlice::iterator
y_itr = vs_lhs->begin(),
y_end = vs_lhs->end();
for( ; y_itr != y_end; ++y_itr, ++d_itr, ++x_itr ) {
#ifdef LINALGPACK_CHECK_RANGE
TEST_FOR_EXCEPT( !( d_itr < diag.end() ) );
TEST_FOR_EXCEPT( !( x_itr < vs_rhs2.end() ) );
TEST_FOR_EXCEPT( !( y_itr < vs_lhs->end() ) );
#endif
*y_itr = beta * (*y_itr) + alpha * (*d_itr) * (*x_itr);
}
}
}
示例2: V_InvMtV
void MatrixSymDiagStd::V_InvMtV(
DVectorSlice* vs_lhs, BLAS_Cpp::Transp trans_rhs1
, const SpVectorSlice& sv_rhs2) const
{
const DVectorSlice diag = this->diag();
size_type n = diag.size();
// y = inv(op(A)) * x
//
// A is symmetric and diagonal A = diag(diag) so:
//
// y(j) = x(j) / diag(j), for j = 1...n
//
// x is sparse so take account of this.
DenseLinAlgPack::Vp_MtV_assert_sizes( vs_lhs->size()
, n, n, trans_rhs1, sv_rhs2.size() );
for( SpVectorSlice::const_iterator x_itr = sv_rhs2.begin()
; x_itr != sv_rhs2.end()
; ++x_itr )
{
(*vs_lhs)(x_itr->indice() + sv_rhs2.offset())
= x_itr->value() / diag(x_itr->indice() + sv_rhs2.offset());
// Note: The indice x(i) invocations are ranged check
// if this is compiled into the code.
}
}
示例3: Vp_StMtV
void MatrixHessianRelaxed::Vp_StMtV(
DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans
, const DVectorSlice& x, value_type b ) const
{
using BLAS_Cpp::no_trans;
using BLAS_Cpp::trans;
using AbstractLinAlgPack::Vp_StMtV;
//
// y = b*y + a * M * x
//
// = b*y + a * [ H 0 ] * [ x1 ]
// [ 0 bigM ] [ x2 ]
//
// =>
//
// y1 = b*y1 + a*H*x1
//
// y2 = b*y2 + bigM * x2
//
LinAlgOpPack::Vp_MtV_assert_sizes(y->size(),rows(),cols(),M_trans,x.size());
DVectorSlice
y1 = (*y)(1,n_);
value_type
&y2 = (*y)(n_+1);
const DVectorSlice
x1 = x(1,n_);
const value_type
x2 = x(n_+1);
// y1 = b*y1 + a*H*x1
Vp_StMtV( &y1, a, *H_, no_trans, x1, b );
// y2 = b*y2 + bigM * x2
if( b == 0.0 )
y2 = bigM_ * x2;
else
y2 = b*y2 + bigM_ * x2;
}
示例4: loqo_b
QPSolverStats::ESolutionType
QPSolverRelaxedLOQO::imp_solve_qp(
std::ostream* out, EOutputLevel olevel, ERunTests test_what
, const DVectorSlice& g, const MatrixOp& G
, value_type etaL
, const SpVectorSlice& dL, const SpVectorSlice& dU
, const MatrixOp* E, BLAS_Cpp::Transp trans_E, const DVectorSlice* b
, const SpVectorSlice* eL, const SpVectorSlice* eU
, const MatrixOp* F, BLAS_Cpp::Transp trans_F, const DVectorSlice* f
, value_type* obj_d
, value_type* eta, DVectorSlice* d
, SpVector* nu
, SpVector* mu, DVectorSlice* Ed
, DVectorSlice* lambda, DVectorSlice* Fd
)
{
using Teuchos::Workspace;
Teuchos::WorkspaceStore* wss = wsp::default_workspace_store.get();
const value_type inf_bnd = std::numeric_limits<value_type>::max();
// const value_type real_big = 1e+20;
const value_type real_big = HUGE_VAL;
const size_type
nd = g.size(),
m_in = E ? b->size() : 0,
m_eq = F ? f->size() : 0;
//
// Create a LOQO QP definition struct
//
LOQO *loqo_lp = openlp();
TEUCHOS_TEST_FOR_EXCEPT( !( loqo_lp ) );
//
// Setup loqo_r and loqo_b and count the number of actual
// constraints.
//
// LOQO's b vector storage
MALLOC( loqo_lp->b, m_in+m_eq, double ); // May not use all of this storage
DVectorSlice loqo_b( loqo_lp->b, m_in+m_eq );
// LOQO's r vector storage
MALLOC( loqo_lp->r, m_in+m_eq, double ); // May not use all of this storage
DVectorSlice loqo_r( loqo_lp->r, m_in+m_eq );
// Gives status of b.
// / j : if eL(j) > -inf_bnd
// loqo_b_stat(k) = |
// \ -j : if eL(j) <= -inf_bnd && eU(j) < +inf_bnd
//
// , for k = 1...num_inequal
//
Workspace<int> loqo_b_stat_ws(wss,m_in); // May not use all of this
DenseLinAlgPack::VectorSliceTmpl<int> loqo_b_stat(&loqo_b_stat_ws[0],loqo_b_stat_ws.size());
std::fill( loqo_b_stat.begin(), loqo_b_stat.end(), 0 ); // Initialize to zero
// Fill up loqo_b, loqo_r and loqo_b_stat
size_type num_inequal = 0; // The actual number of bouned general inequalities
if(E) {
// Read iterators
AbstractLinAlgPack::sparse_bounds_itr
eLU_itr( eL->begin(), eL->end(), eL->offset()
, eU->begin(), eU->end(), eU->offset(), inf_bnd );
// written iterators
DVectorSlice::iterator
b_itr = loqo_b.begin(),
r_itr = loqo_r.begin();
DenseLinAlgPack::VectorSliceTmpl<int>::iterator
b_stat_itr = loqo_b_stat.begin();
// loop
for( int k = 1; !eLU_itr.at_end(); ++k, ++eLU_itr, ++b_itr, ++r_itr, ++b_stat_itr, ++num_inequal )
{
const size_type j = eLU_itr.indice();
if(eLU_itr.lbound() > -inf_bnd) {
*b_itr = eLU_itr.lbound();
*r_itr = eLU_itr.ubound() >= inf_bnd ? real_big : eLU_itr.ubound() - eLU_itr.lbound();
*b_stat_itr = j; // We need to make A(k,:) = [ +op(E)(j,:), -b(j) ]
}
else {
TEUCHOS_TEST_FOR_EXCEPT( !( eLU_itr.ubound() < +inf_bnd ) );
*b_itr = -eLU_itr.ubound();
*r_itr = eLU_itr.lbound() <= -inf_bnd ? real_big : - eLU_itr.lbound() + eLU_itr.ubound();
*b_stat_itr = -j; // We need to make A(k,:) = [ -op(E)(j,:), +b(j) ]
}
}
}
if(F) {
LinAlgOpPack::V_StV( &loqo_b(num_inequal+1,num_inequal+m_eq), -1.0, *f );
loqo_r(num_inequal+1,num_inequal+m_eq) = 0.0;
}
//
// Setup the QP dimensions
//
loqo_lp->n = nd+1;
loqo_lp->m = num_inequal + m_eq;
//
//.........这里部分代码省略.........
示例5: initialize_kkt_system
void QPSchurInitKKTSystemHessianRelaxed::initialize_kkt_system(
const DVectorSlice& g
,const MatrixOp& G
,value_type etaL
,const SpVectorSlice& dL
,const SpVectorSlice& dU
,const MatrixOp* F
,BLAS_Cpp::Transp trans_F
,const DVectorSlice* f
,const DVectorSlice& d
,const SpVectorSlice& nu
,size_type* n_R
,i_x_free_t* i_x_free
,i_x_fixed_t* i_x_fixed
,bnd_fixed_t* bnd_fixed
,j_f_decomp_t* j_f_decomp
,DVector* b_X
,Ko_ptr_t* Ko
,DVector* fo
) const
{
using BLAS_Cpp::trans;
// Validate type of and convert G
const MatrixSymHessianRelaxNonSing
*G_relax_ptr = dynamic_cast<const MatrixSymHessianRelaxNonSing*>(&G);
if( G_relax_ptr == NULL ) {
init_kkt_full_.initialize_kkt_system(
g,G,etaL,dL,dU,F,trans_F,f,d,nu,n_R,i_x_free,i_x_fixed,bnd_fixed
,j_f_decomp,b_X,Ko,fo);
return;
}
const MatrixSymHessianRelaxNonSing
&G_relax = *G_relax_ptr;
// get some stuff
const MatrixSymWithOpFactorized
&G_orig = G_relax.G(),
&M = G_relax.M();
const size_type
nd = g.size(),
no = G_orig.rows(),
nr = M.rows();
TEST_FOR_EXCEPT( !( no + nr == nd ) );
// Setup output arguments
// n_R = nd_R
*n_R = no;
// i_x_free.size() == 0 and i_x_free is implicitly identity
i_x_free->resize(no);
{ for(size_type l = 1; l <= no; ++l ) {
(*i_x_free)[l-1] = l;
}
}
// i_x_fixed[]
i_x_fixed->resize(nr+1);
if(nr) {
// i_x_fixed[l-1] = no + l, l = 1...nr
for( size_type l = 1; l <= nr; ++l )
(*i_x_fixed)[l-1] = no+l;
}
(*i_x_fixed)[nr] = nd+1; // extra relaxation is always initially active
// bnd_fixed[]
bnd_fixed->resize(nr+1);
if(nr) {
// bnd_fixed[l-1] = LOWER, l = 1...nr
std::fill_n( bnd_fixed->begin(), nr, LOWER );
}
(*bnd_fixed)[nr] = LOWER; // relaxation is always initially active
// j_f_decomp[]
j_f_decomp->resize(0);
// b_X
b_X->resize(nr+1);
if(nr) {
// b_X[l-1] = dL(no+l), l = 1...nr
LinAlgOpPack::assign( &(*b_X)(1,nr), dL(no+1,no+nr) );
}
(*b_X)[nr] = etaL; // relaxation is always initially active
// Ko = G.G
*Ko = G_relax.G_ptr(); // now B_RR is a shared object
// fo = - *g(1:no)
LinAlgOpPack::V_StV( fo, -1.0, g(1,no) );
}
开发者ID:haripandey,项目名称:trilinos,代码行数:87,代码来源:ConstrainedOptPack_QPSchurInitKKTSystemHessianRelaxed.cpp
示例6: Vp_StPtMtV
void MatrixHessianRelaxed::Vp_StPtMtV(
DVectorSlice* y, value_type a
, const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
, BLAS_Cpp::Transp M_trans
, const DVectorSlice& x, value_type b ) const
{
using BLAS_Cpp::no_trans;
using BLAS_Cpp::trans;
namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
//
// y = b*y + a * op(P) * M * x
//
// = b*y + a * [ op(P1) op(P2) ] * [ H 0 ] * [ x1 ]
// [ 0 bigM ] [ x2 ]
//
// =>
//
// y = b*y + a*op(P1)*H*x1 + a*op(P2)*bigM*x2
//
LinAlgOpPack::Vp_MtV_assert_sizes(y->size(),P.rows(),P.cols(),P_trans
, BLAS_Cpp::rows( rows(), cols(), M_trans) );
LinAlgOpPack::Vp_MtV_assert_sizes( BLAS_Cpp::cols( P.rows(), P.cols(), P_trans)
,rows(),cols(),M_trans,x.size());
// For this to work (as shown below) we need to have P sorted by
// row if op(P) = P' or sorted by column if op(P) = P. If
// P is not sorted properly, we will just use the default
// implementation of this operation.
if( ( P.ordered_by() == GPMSIP::BY_ROW && P_trans == no_trans )
|| ( P.ordered_by() == GPMSIP::BY_COL && P_trans == trans ) )
{
// Call the default implementation
MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b);
return;
}
if( P.is_identity() )
TEUCHOS_TEST_FOR_EXCEPT( !( BLAS_Cpp::rows( P.rows(), P.cols(), P_trans ) == n_ ) );
const GenPermMatrixSlice
P1 = ( P.is_identity()
? GenPermMatrixSlice( n_, n_, GenPermMatrixSlice::IDENTITY_MATRIX )
: P.create_submatrix(Range1D(1,n_),P_trans==trans?GPMSIP::BY_ROW:GPMSIP::BY_COL)
),
P2 = ( P.is_identity()
? GenPermMatrixSlice(
P_trans == no_trans ? n_ : 1
, P_trans == no_trans ? 1 : n_
, GenPermMatrixSlice::ZERO_MATRIX )
: P.create_submatrix(Range1D(n_+1,n_+1),P_trans==trans?GPMSIP::BY_ROW:GPMSIP::BY_COL)
);
const DVectorSlice
x1 = x(1,n_);
const value_type
x2 = x(n_+1);
// y = b*y + a*op(P1)*H*x1
AbstractLinAlgPack::Vp_StPtMtV( y, a, P1, P_trans, *H_, no_trans, x1, b );
// y += a*op(P2)*bigM*x2
if( P2.nz() ){
TEUCHOS_TEST_FOR_EXCEPT( !( P2.nz() == 1 ) );
const size_type
i = P_trans == no_trans ? P2.begin()->row_i() : P2.begin()->col_j();
(*y)(i) += a * bigM_ * x2;
}
}