Browse Source

Added flag to keep zeros when transposing.

Former-commit-id: 811f6824cf
tempestpy_adaptions
David_Korzeniewski 10 years ago
parent
commit
5acaed6048
  1. 7
      src/storage/SparseMatrix.cpp
  2. 3
      src/storage/SparseMatrix.h

7
src/storage/SparseMatrix.cpp

@ -603,9 +603,10 @@ namespace storm {
}
template <typename ValueType>
SparseMatrix<ValueType> SparseMatrix<ValueType>::transpose(bool joinGroups) const {
SparseMatrix<ValueType> SparseMatrix<ValueType>::transpose(bool joinGroups, bool keepZeros) const {
index_type rowCount = this->getColumnCount();
index_type columnCount = joinGroups ? this->getRowGroupCount() : this->getRowCount();
//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<index_type> rowIndications(rowCount + 1);
@ -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<ValueType>()) {
if (transition.getValue() != storm::utility::zero<ValueType>() || 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<ValueType>()) {
if (transition.getValue() != storm::utility::zero<ValueType>() || keepZeros) {
columnsAndValues[nextIndices[transition.getColumn()]] = std::make_pair(group, transition.getValue());
nextIndices[transition.getColumn()]++;
}

3
src/storage/SparseMatrix.h

@ -576,10 +576,11 @@ namespace storm {
* Transposes the matrix.
*
* @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<value_type> transpose(bool joinGroups = false) const;
storm::storage::SparseMatrix<value_type> 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).

Loading…
Cancel
Save