Browse Source

permutations for vectors

tempestpy_adaptions
Sebastian Junges 5 years ago
parent
commit
a58ec3fd5f
  1. 10
      src/storm/utility/vector.h
  2. 10
      src/test/storm/utility/VectorTest.cpp

10
src/storm/utility/vector.h

@ -1170,6 +1170,16 @@ namespace storm {
return result;
}
template<typename T>
std::vector<T> applyInversePermutation(std::vector<uint64_t> const& inversePermutation, std::vector<T> const& source) {
std::vector<T> result;
result.reserve(source.size());
for (uint64_t sourceIndex : inversePermutation) {
result.push_back(source[sourceIndex]);
}
return result;
}
/*!
* Output vector as string.
*

10
src/test/storm/utility/VectorTest.cpp

@ -31,3 +31,13 @@ TEST(VectorTest, min_if) {
ASSERT_EQ(16.0, storm::utility::vector::min_if(a, f1));
ASSERT_EQ(8.0, storm::utility::vector::min_if(a, f2));
}
TEST(VectorTest, permute) {
std::vector<double> a = {1.0, 2.0, 3.0, 4.0};
std::vector<uint64_t> inversePermutation = {0, 3, 1, 2};
std::vector<double> aperm = storm::utility::vector::applyInversePermutation(inversePermutation, a);
EXPECT_EQ(aperm[0], a[0]);
EXPECT_EQ(aperm[1], a[3]);
EXPECT_EQ(aperm[2], a[1]);
EXPECT_EQ(aperm[3], a[2]);
}
Loading…
Cancel
Save