本文整理汇总了C++中SparseMatrix::FastTranspose方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::FastTranspose方法的具体用法?C++ SparseMatrix::FastTranspose怎么用?C++ SparseMatrix::FastTranspose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix::FastTranspose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Multiply
SparseMatrix SparseMatrix::Multiply(SparseMatrix b)
//Multiply two sparse matrices @[email protected] (\(**\fBthis\fR) and @[email protected] producing @[email protected]
{
if (Cols != b.Rows) {
cout << "Incompatible matrices" << endl;
return EmptyMatrix();
}
if ((Terms == MaxTerms) || (b.Terms == MaxTerms))
{
cout << "One additional space in @[email protected] or @[email protected] needed" << endl;
return EmptyMatrix();
}
SparseMatrix bXpose = b.FastTranspose();
SparseMatrix result;
int currRowIndex = 0, LastD = -1, currRowBegin = 0, currRowA = smArray[0].row;
// set boundary conditions
smArray[Terms].row = Rows; bXpose.smArray[b.Terms].row = b.Cols;
bXpose.smArray[b.Terms].col = -1; int sum = 0;
while (currRowIndex < Terms) // generate row @[email protected] of @[email protected]
{
int currColB = bXpose.smArray[0].row; int currColIndex = 0;
while (currColIndex <= b.Terms) // multiply row @[email protected] of @[email protected] by column \fIcurrColB\fP of @[email protected]
{
// cout << "currRowIndex:" << currRowIndex << " currColIndex:" << currColIndex << " currRowA:" << currRowA << " currColB:" << currColB << endl;
if(smArray[currRowIndex].row != currRowA) // end of row @[email protected]
{
// cout << "1: new col" << endl;
result.StoreSum(sum, LastD,currRowA,currColB);
currRowIndex = currRowBegin;
// go to next column
while (bXpose.smArray[currColIndex].row == currColB) currColIndex++;
currColB = bXpose.smArray[currColIndex].row;
}
else if (bXpose.smArray[currColIndex].row != currColB) // end of column \fIcurrColB\fP of @[email protected]
{
// cout << "2: new row" << endl;
result.StoreSum(sum,LastD,currRowA,currColB);
// set to multiply row @[email protected] with next column
currRowIndex = currRowBegin; currColB = bXpose.smArray[currColIndex].row;
}
else
switch (compare (smArray[currRowIndex].col, bXpose.smArray[currColIndex].col)) {
case '<': // advance to next term in row.
// cout << "3a: next term in row" << endl;
currRowIndex++; break;
case '=': // add to \fIsum\fP
// cout << "3b: add to sum" << endl;
sum += smArray[currRowIndex].value * bXpose.smArray[currColIndex].value;
currRowIndex++; currColIndex++; break;
case '>': // advance to next term in column \fIc\fP
// cout << "3c: next term in col" << endl;
currColIndex++;
} // end of switch
} // of \fBwhile\fP (@[email protected] <= @b.Terms)@
while (smArray[currRowIndex].row == currRowA) // advance to next row
currRowIndex++;
currRowBegin = currRowIndex; currRowA = smArray[currRowIndex].row;
} //end of \fBwhile\fP (@[email protected] < @[email protected])
result.Rows = Rows; result.Cols = b.Cols; result.Terms = LastD+1;
return result;
} // of @[email protected]