本文整理汇总了C++中SparseMatrixType::value_data方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrixType::value_data方法的具体用法?C++ SparseMatrixType::value_data怎么用?C++ SparseMatrixType::value_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrixType
的用法示例。
在下文中一共展示了SparseMatrixType::value_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Solve
bool SuperLUSolver::Solve(SparseMatrixType& rA, VectorType& rX, VectorType& rB)
{
//std::cout << "matrix size in solver: " << rA.size1() << std::endl;
//std::cout << "RHS size in solver SLU: " << rB.size() << std::endl;
// typedef ublas::compressed_matrix<double, ublas::row_major, 0,
// ublas::unbounded_array<int>, ublas::unbounded_array<double> > cm_t;
//make a copy of the RHS
VectorType rC = rB;
superlu_options_t options;
SuperLUStat_t stat;
/* Set the default input options:
options.Fact = DOFACT;
options.Equil = YES;
options.ColPerm = COLAMD;
options.DiagPivotThresh = 1.0;
options.Trans = NOTRANS;
options.IterRefine = NOREFINE;
options.SymmetricMode = NO;
options.PivotGrowth = NO;
options.ConditionNumber = NO;
options.PrintStat = YES;
*/
set_default_options(&options);
options.IterRefine = SLU_DOUBLE;
// options.ColPerm = MMD_AT_PLUS_A;
//Fill the SuperLU matrices
SuperMatrix Aslu, B, L, U;
//create a copy of the matrix
int *index1_vector = new (std::nothrow) int[rA.index1_data().size()];
int *index2_vector = new (std::nothrow) int[rA.index2_data().size()];
// double *values_vector = new (std::nothrow) double[rA.value_data().size()];
for( int unsigned i = 0; i < rA.index1_data().size(); i++ )
index1_vector[i] = (int)rA.index1_data()[i];
for( unsigned int i = 0; i < rA.index2_data().size(); i++ )
index2_vector[i] = (int)rA.index2_data()[i];
/* for( unsigned int i = 0; i < rA.value_data().size(); i++ )
values_vector[i] = (double)rA.value_data()[i];*/
//create a copy of the rhs vector (it will be overwritten with the solution)
/* double *b_vector = new (std::nothrow) double[rB.size()];
for( unsigned int i = 0; i < rB.size(); i++ )
b_vector[i] = rB[i];*/
/*
dCreate_CompCol_Matrix (&Aslu, rA.size1(), rA.size2(),
rA.nnz(),
values_vector,
index2_vector,
index1_vector,
SLU_NR, SLU_D, SLU_GE
);*/
//works also with dCreate_CompCol_Matrix
dCreate_CompRow_Matrix (&Aslu, rA.size1(), rA.size2(),
rA.nnz(),
rA.value_data().begin(),
index2_vector, //can not avoid a copy as ublas uses unsigned int internally
index1_vector, //can not avoid a copy as ublas uses unsigned int internally
SLU_NR, SLU_D, SLU_GE
);
dCreate_Dense_Matrix (&B, rB.size(), 1,&rB[0],rB.size(),SLU_DN, SLU_D, SLU_GE);
//allocate memory for permutation arrays
int* perm_c;
int* perm_r;
if ( !(perm_c = intMalloc(rA.size1())) ) ABORT("Malloc fails for perm_c[].");
if ( !(perm_r = intMalloc(rA.size2())) ) ABORT("Malloc fails for perm_r[].");
//initialize container for statistical data
StatInit(&stat);
//call solver routine
int info;
dgssv(&options, &Aslu, perm_c, perm_r, &L, &U, &B, &stat, &info);
//print output
if (options.PrintStat) {
StatPrint(&stat);
}
//resubstitution of results
#pragma omp parallel for
for(int i=0; i<static_cast<int>(rB.size()); i++ )
rX[i] = rB[i]; // B(i,0);
//recover the RHS
rB=rC;
//deallocate memory used
StatFree(&stat);
//.........这里部分代码省略.........