From 5acaed6048e7ad832b7c107cd6e80f02b8e5885a Mon Sep 17 00:00:00 2001 From: David_Korzeniewski Date: Thu, 7 May 2015 13:07:00 +0200 Subject: [PATCH] Added flag to keep zeros when transposing. Former-commit-id: 811f6824cfebc45c1a5b9560bdc65a3201f3350b --- src/storage/SparseMatrix.cpp | 9 +++++---- src/storage/SparseMatrix.h | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/storage/SparseMatrix.cpp b/src/storage/SparseMatrix.cpp index 880d15d82..25beb4093 100644 --- a/src/storage/SparseMatrix.cpp +++ b/src/storage/SparseMatrix.cpp @@ -603,10 +603,11 @@ namespace storm { } template - SparseMatrix SparseMatrix::transpose(bool joinGroups) const { + SparseMatrix SparseMatrix::transpose(bool joinGroups, bool keepZeros) const { index_type rowCount = this->getColumnCount(); index_type columnCount = joinGroups ? this->getRowGroupCount() : this->getRowCount(); - index_type entryCount = this->getEntryCount(); + //index_type entryCount = keepZeros ? this->getEntryCount() : this->getNonzeroEntryCount(); this wont work if someone modified the matrix after creation... + index_type entryCount = this->getEntryCount(); std::vector rowIndications(rowCount + 1); std::vector> columnsAndValues(entryCount); @@ -614,7 +615,7 @@ namespace storm { // First, we need to count how many entries each column has. for (index_type group = 0; group < columnCount; ++group) { for (auto const& transition : joinGroups ? this->getRowGroup(group) : this->getRow(group)) { - if (transition.getValue() != storm::utility::zero()) { + if (transition.getValue() != storm::utility::zero() || keepZeros) { ++rowIndications[transition.getColumn() + 1]; } } @@ -633,7 +634,7 @@ namespace storm { // Now we are ready to actually fill in the values of the transposed matrix. for (index_type group = 0; group < columnCount; ++group) { for (auto const& transition : joinGroups ? this->getRowGroup(group) : this->getRow(group)) { - if (transition.getValue() != storm::utility::zero()) { + if (transition.getValue() != storm::utility::zero() || keepZeros) { columnsAndValues[nextIndices[transition.getColumn()]] = std::make_pair(group, transition.getValue()); nextIndices[transition.getColumn()]++; } diff --git a/src/storage/SparseMatrix.h b/src/storage/SparseMatrix.h index 8eded966b..bf0193c7e 100644 --- a/src/storage/SparseMatrix.h +++ b/src/storage/SparseMatrix.h @@ -574,12 +574,13 @@ namespace storm { /*! * Transposes the matrix. - * - * @param joinGroups A flag indicating whether the row groups are supposed to be treated as single rows. + * + * @param joinGroups A flag indicating whether the row groups are supposed to be treated as single rows. + * @param keepZeros A flag indicating whether entries with value zero should be kept. * * @return A sparse matrix that represents the transpose of this matrix. */ - storm::storage::SparseMatrix transpose(bool joinGroups = false) const; + storm::storage::SparseMatrix transpose(bool joinGroups = false, bool keepZeros = false) const; /*! * Transforms the matrix into an equation system. That is, it transforms the matrix A into a matrix (1-A).