本文整理汇总了C++中PackedVector::makeSparse方法的典型用法代码示例。如果您正苦于以下问题:C++ PackedVector::makeSparse方法的具体用法?C++ PackedVector::makeSparse怎么用?C++ PackedVector::makeSparse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PackedVector
的用法示例。
在下文中一共展示了PackedVector::makeSparse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solveInPlace
void BaseSpline::solveInPlace(PackedMatrix& mat, PackedVector& res) {
res = res.makeSparse();
// Current implementation requires a quadratic mat
int nCol = mat.numCols();
PackedVector nonEmpty;
int col, row, rowPos;
for (col = 0; col < nCol; col++) {
//int stop = 1;
//if(col==stop-1){
// cout << "*********************"<<endl;
// cout << col << endl;
// cout << "*********************"<<endl;
// mat.displayMatrix();
// cout << "RES: " <<res.values<<endl;
//}
// find the non-null elements in this column (below row "col")
nonEmpty = PackedVector();
int pivotPos(-1);
for (row = col; row < mat.numRows(); row++) {
int rowEntries = mat[row].numberEntries();
for (rowPos = rowEntries; rowPos--;) {
int entryIndex = mat[row].index(rowPos);
if (entryIndex == col) {
nonEmpty.packedAddElement(row, mat[row][rowPos]);
if (row == col) {
pivotPos = nonEmpty.numberEntries()-1;
}
}
}
}
// if(col==stop-1){
// cout<<"nonEmpty " << nonEmpty.values<< endl;
// cout<<"pivot " << pivotPos<< endl<<endl;
// }
//find most significant row
double maxVal(0.0);
int maxRow(-1), maxRowPos(-1);
for (rowPos = nonEmpty.numberEntries(); rowPos--;) {
double val = nonEmpty[rowPos];
assert(isfinite(val));
if (fabs(val) > fabs(maxVal)) {
maxVal = val;
maxRow = nonEmpty.index(rowPos);
maxRowPos = rowPos;
}
}
//int imaxRow = maxRow;
//int imaxRowPos = maxRowPos;
// if(col==stop-1){
// cout << "imaxRow " << imaxRow << endl;
// cout << "imaxRowPos " << imaxRowPos << endl<<endl;
// }
// Put the most significant row at row "col"
if (maxVal != 0.0) {
if (maxRow != col) {
swap(mat[col], mat[maxRow]);
res.swapElements(col, maxRow);
if (pivotPos >= 0) {
nonEmpty.swapElements(maxRowPos, pivotPos);
}
}
// if(col==stop-1){
// cout << "SWAP\n";
// mat.displayMatrix();
// }
// Divide the row with maxVal
mat[col].packedDiv(maxVal);
double value = res[col] / maxVal;
res.packedReplace(col,value);
// if(col==stop-1){
// cout << "\nDIVIDE ROW\n";
// mat.displayMatrix();
// cout << "res " << res.values<<endl;
// cout << "nonEmpty " << nonEmpty.values<<endl;
// cout << "\n\n";
// }
}
// subtract the row from other rows
for (rowPos = nonEmpty.numberEntries(); rowPos--;) {
row = nonEmpty.index(rowPos);
if (row == col) {
continue;
}
// If the pivotRow was empty (prior to swap) at col=row do not process this row
if (pivotPos < 0 && row == maxRow) {
continue;
}
double val = nonEmpty[rowPos];
PackedVector prodVector = mat[col];
mat[row] = mat[row].packedSubtract(prodVector.packedProd(val));
double value = res[row] - (val * res[col]);
res.packedReplace(row, value);
// if(col==stop-1){
// cout << "SUBTRACT ROW\n";
//.........这里部分代码省略.........