本文整理汇总了C++中blitz::Array::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::begin方法的具体用法?C++ Array::begin怎么用?C++ Array::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blitz::Array
的用法示例。
在下文中一共展示了Array::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyTensorPotentialToEpetraMatrix
void CopyTensorPotentialToEpetraMatrix(Epetra_FECrsMatrix_Ptr epetraMatrix, blitz::Array<cplx, Rank> potentialData, list pyLocalBasisPairs, blitz::TinyVector<int, Rank> globalStrides, double cutoff)
{
blitz::Array<int, 2> indexArray;
indexArray.resize(4 * potentialData.size(), 2);
indexArray = -100;
double sqrCutoff = sqr(cutoff);
//Setup structures for calculating matrix row/col indices from the
//basis pairs in the tensor potential
blitz::TinyVector< blitz::Array<int, 2>, Rank > localBasisPairs;
for (int rank=0; rank<Rank; rank++)
{
localBasisPairs(rank).reference( boost::python::extract< blitz::Array<int, 2> >(pyLocalBasisPairs[rank]) );
}
//Iterate over all items in potentialData
typename blitz::Array<cplx, Rank>::iterator it = potentialData.begin();
for (int linearCount=0; linearCount<potentialData.size(); linearCount++)
{
int globalRow = 0;
int globalCol = 0;
for (int rank=0; rank<Rank; rank++)
{
int rankPos = it.position()(rank);
globalRow += globalStrides(rank) * localBasisPairs(rank)(rankPos, 0);
globalCol += globalStrides(rank) * localBasisPairs(rank)(rankPos, 1);
}
double realVal = real(*it);
double imagVal = imag(*it);
//Skip padded elements (they have negative row/col index)
if ((globalRow < 0) || (globalCol < 0))
{
it++;
continue;
}
/*
* Because epetra does not support complex natively,
* each matrix element is a 2x2 block
*
* (A_r -A_i ) (c_r) = (A_r + i A_i) * (c_r + i c_i) = A * c
* (A_i A_r ) (c_i)
*
* Detect if A_i or A_r is zero to avoid redundant elements
*/
//Insert values into matrix
if (sqr(realVal) > sqrCutoff)
{
int r,c;
r = 2*globalRow; c = 2*globalCol;
indexArray(4*linearCount, 0) = r;
indexArray(4*linearCount, 1) = c;
epetraMatrix->InsertGlobalValues(r, 1, &realVal, &c);
r++; c++;
epetraMatrix->InsertGlobalValues(r, 1, &realVal, &c);
indexArray(4*linearCount+1, 0) = r;
indexArray(4*linearCount+1, 1) = c;
}
if (sqr(imagVal) > sqrCutoff)
{
int r,c;
//Upper row, A_i with minus sign
r = 2*globalRow; c = 2*globalCol+1;
indexArray(4*linearCount+2, 0) = r;
indexArray(4*linearCount+2, 1) = c;
imagVal = -imagVal;
epetraMatrix->InsertGlobalValues(r, 1, &imagVal, &c);
//Lower row, A_i without minus sign
imagVal = -imagVal;
epetraMatrix->InsertGlobalValues(c, 1, &imagVal, &r);
indexArray(4*linearCount+3, 0) = c;
indexArray(4*linearCount+3, 1) = r;
}
++it;
}
}