Browse Source

added function to check whether a matrix is the identity matrix

main
TimQu 7 years ago
parent
commit
8e7d3107ca
  1. 29
      src/storm/storage/SparseMatrix.cpp
  2. 3
      src/storm/storage/SparseMatrix.h

29
src/storm/storage/SparseMatrix.cpp

@ -2015,6 +2015,35 @@ namespace storm {
return true;
}
template<typename ValueType>
bool SparseMatrix<ValueType>::isIdentityMatrix() const {
if (this->getRowCount() != this->getColumnCount()) {
return false;
}
if (this->getNonzeroEntryCount() != this->getRowCount()) {
return false;
}
for (uint64_t row = 0; row < this->getRowCount(); ++row) {
bool rowHasEntry = false;
for (auto const& entry : this->getRow(row)) {
if (entry.getColumn() == row) {
if (!storm::utility::isOne(entry.getValue())) {
return false;
}
rowHasEntry = true;
} else {
if (!storm::utility::isZero(entry.getValue())) {
return false;
}
}
}
if (!rowHasEntry) {
return false;
}
}
return true;
}
template<typename ValueType>
std::ostream& operator<<(std::ostream& out, SparseMatrix<ValueType> const& matrix) {
// Print column numbers in header.

3
src/storm/storage/SparseMatrix.h

@ -929,6 +929,9 @@ namespace storm {
template<typename OtherValueType>
bool isSubmatrixOf(SparseMatrix<OtherValueType> const& matrix) const;
// Returns true if the matrix is the identity matrix
bool isIdentityMatrix() const;
template<typename TPrime>
friend std::ostream& operator<<(std::ostream& out, SparseMatrix<TPrime> const& matrix);

|||||||
100:0
Loading…
Cancel
Save