shared_ptr<Epetra_CrsMatrix> sparseCholesky(const Epetra_CrsMatrix &mat) { // Note: we assume the matrix mat is symmetric and positive-definite size_t size = mat.NumGlobalCols(); if (mat.NumGlobalRows() != size) throw std::invalid_argument("sparseCholesky(): matrix must be square"); int *rowOffsets = 0; int *colIndices = 0; double *values = 0; mat.ExtractCrsDataPointers(rowOffsets, colIndices, values); Epetra_SerialComm comm; Epetra_LocalMap rowMap(static_cast<int>(size), 0 /* index_base */, comm); Epetra_LocalMap columnMap(static_cast<int>(size), 0 /* index_base */, comm); shared_ptr<Epetra_CrsMatrix> result = boost::make_shared<Epetra_CrsMatrix>( Copy, rowMap, columnMap, mat.GlobalMaxNumEntries()); arma::Mat<double> localMat; arma::Mat<double> localCholesky; std::vector<bool> processed(size, false); for (size_t r = 0; r < size; ++r) { if (processed[r]) continue; int localSize = rowOffsets[r + 1] - rowOffsets[r]; localMat.set_size(localSize, localSize); localMat.fill(0.); localCholesky.set_size(localSize, localSize); for (int s = 0; s < localSize; ++s) { int row = colIndices[rowOffsets[r] + s]; for (int c = 0; c < localSize; ++c) { int col = colIndices[rowOffsets[row] + c]; if (col != colIndices[rowOffsets[r] + c]) throw std::invalid_argument("sparseCholesky(): matrix is not " "block-diagonal"); localMat(s, c) = values[rowOffsets[row] + c]; } } assert(arma::norm(localMat - localMat.t(), "fro") < 1e-12 * arma::norm(localMat, "fro")); localCholesky = arma::chol(localMat); // localCholesky: U for (int s = 0; s < localSize; ++s) { int row = colIndices[rowOffsets[r] + s]; processed[row] = true; #ifndef NDEBUG int errorCode = #endif result->InsertGlobalValues(row, s + 1 /* number of values */, localCholesky.colptr(s), colIndices + rowOffsets[r]); assert(errorCode == 0); } } result->FillComplete(columnMap, rowMap); return result; }
MediaModel::MediaModel(QString rootPath, QObject *parent) : QSortFilterProxyModel(parent), QFileSystemProxyModelMixin(this) { this->rootPath = rootPath; QVector<int> columnMap(4); columnMap[0] = 0; columnMap[1] = 1; columnMap[2] = 1; columnMap[3] = 3; this->fsModel = new QFileSystemModelWithMappedColumns(columnMap); this->fsModel->setRootPath(this->rootPath); this->setSourceModel(this->fsModel); this->setSourceFileSystemModel(this->fsModel); this->setDynamicSortFilter(true); connect(&MediaDb::getInstance(), SIGNAL(keyChangedForPath(QString, QString)), this, SLOT(onMediaDbKeyChangedForPath(QString, QString))); }
int CalendarItemModel::columnCount( const QModelIndex & ) const { return columnMap().keyCount(); }
int ChartItemModel::columnCount( const QModelIndex &/*parent*/ ) const { return columnMap().keyCount(); }