Browse Source

utility/vector: buildVectorForRange now gets the type of the vector as a template parameter.

tempestpy_adaptions
Tim Quatmann 6 years ago
parent
commit
3a21ce8009
  1. 4
      src/storm/storage/SparseMatrix.cpp
  2. 11
      src/storm/utility/vector.h

4
src/storm/storage/SparseMatrix.cpp

@ -598,7 +598,7 @@ namespace storm {
// If there is no current row grouping, we need to create it. // If there is no current row grouping, we need to create it.
if (!this->rowGroupIndices) { if (!this->rowGroupIndices) {
STORM_LOG_ASSERT(trivialRowGrouping, "Only trivial row-groupings can be constructed on-the-fly."); STORM_LOG_ASSERT(trivialRowGrouping, "Only trivial row-groupings can be constructed on-the-fly.");
this->rowGroupIndices = storm::utility::vector::buildVectorForRange(0, this->getRowGroupCount() + 1);
this->rowGroupIndices = storm::utility::vector::buildVectorForRange(static_cast<index_type>(0), this->getRowGroupCount() + 1);
} }
return rowGroupIndices.get(); return rowGroupIndices.get();
} }
@ -627,7 +627,7 @@ namespace storm {
template<typename ValueType> template<typename ValueType>
void SparseMatrix<ValueType>::makeRowGroupingTrivial() { void SparseMatrix<ValueType>::makeRowGroupingTrivial() {
if (trivialRowGrouping) { if (trivialRowGrouping) {
STORM_LOG_ASSERT(!rowGroupIndices || rowGroupIndices.get() == storm::utility::vector::buildVectorForRange(0, this->getRowGroupCount() + 1), "Row grouping is supposed to be trivial but actually it is not.");
STORM_LOG_ASSERT(!rowGroupIndices || rowGroupIndices.get() == storm::utility::vector::buildVectorForRange(static_cast<index_type>(0), this->getRowGroupCount() + 1), "Row grouping is supposed to be trivial but actually it is not.");
} else { } else {
trivialRowGrouping = true; trivialRowGrouping = true;
rowGroupIndices = boost::none; rowGroupIndices = boost::none;

11
src/storm/utility/vector.h

@ -103,10 +103,11 @@ namespace storm {
/*! /*!
* Constructs a vector [min, min+1, ...., max-1] * Constructs a vector [min, min+1, ...., max-1]
*/ */
inline std::vector<uint_fast64_t> buildVectorForRange(uint_fast64_t min, uint_fast64_t max) {
STORM_LOG_ASSERT(min < max, "Invalid range.");
uint_fast64_t diff = max - min;
std::vector<uint_fast64_t> v;
template<typename T>
inline std::vector<T> buildVectorForRange(T min, T max) {
STORM_LOG_ASSERT(min <= max, "Invalid range.");
T diff = max - min;
std::vector<T> v;
v.reserve(diff); v.reserve(diff);
iota_n(std::back_inserter(v), diff, min); iota_n(std::back_inserter(v), diff, min);
return v; return v;
@ -119,7 +120,7 @@ namespace storm {
*/ */
template<typename T> template<typename T>
std::vector<uint_fast64_t> getSortedIndices(std::vector<T> const& v){ std::vector<uint_fast64_t> getSortedIndices(std::vector<T> const& v){
std::vector<uint_fast64_t> res = buildVectorForRange(0, v.size());
std::vector<uint_fast64_t> res = buildVectorForRange<uint_fast64_t>(0, v.size());
std::sort(res.begin(), res.end(), [&v](uint_fast64_t index1, uint_fast64_t index2) { return v[index1] > v[index2];}); std::sort(res.begin(), res.end(), [&v](uint_fast64_t index1, uint_fast64_t index2) { return v[index1] > v[index2];});
return res; return res;
} }

Loading…
Cancel
Save