Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
VectorTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
5#include "test/storm_gtest.h"
6
7TEST(VectorTest, sum_if) {
8 std::vector<double> a = {1.0, 2.0, 4.0, 8.0, 16.0};
9 storm::storage::BitVector f1(5, {2, 4});
10 storm::storage::BitVector f2(5, {3, 4});
11
12 ASSERT_EQ(20.0, storm::utility::vector::sum_if(a, f1));
13 ASSERT_EQ(24.0, storm::utility::vector::sum_if(a, f2));
14}
15
16TEST(VectorTest, max_if) {
17 std::vector<double> a = {1.0, 2.0, 34.0, 8.0, 16.0};
18 storm::storage::BitVector f1(5, {2, 4});
19 storm::storage::BitVector f2(5, {3, 4});
20
21 ASSERT_EQ(34.0, storm::utility::vector::max_if(a, f1));
22 ASSERT_EQ(16.0, storm::utility::vector::max_if(a, f2));
23}
24
25TEST(VectorTest, min_if) {
26 std::vector<double> a = {1.0, 2.0, 34.0, 8.0, 16.0};
27 storm::storage::BitVector f1(5, {2, 4});
28 storm::storage::BitVector f2(5, {3, 4});
29
30 ASSERT_EQ(16.0, storm::utility::vector::min_if(a, f1));
31 ASSERT_EQ(8.0, storm::utility::vector::min_if(a, f2));
32}
33
34TEST(VectorTest, inverse_permute) {
35 std::vector<double> a = {1.0, 2.0, 3.0, 4.0};
36 std::vector<uint64_t> inversePermutation = {0, 3, 1, 2};
37 std::vector<double> aperm = storm::utility::vector::applyInversePermutation(inversePermutation, a);
38 EXPECT_EQ(aperm[0], a[0]);
39 EXPECT_EQ(aperm[1], a[3]);
40 EXPECT_EQ(aperm[2], a[1]);
41 EXPECT_EQ(aperm[3], a[2]);
42}
43
44TEST(VectorTest, grouped_inverse_permute) {
45 std::vector<double> a = {1.0, 2.0, 3.0, 4.0, 5.0};
46 std::vector<uint64_t> groupIndices = {0, 3, 5, 5}; // last group empty
47 std::vector<uint64_t> inversePermutation = {1, 2, 0};
48 std::vector<double> aperm = storm::utility::vector::applyInversePermutationToGroupedVector(inversePermutation, a, groupIndices);
49 std::vector<double> expected = {4.0, 5.0, 1.0, 2.0, 3.0};
50 EXPECT_EQ(aperm, expected);
51}
TEST(VectorTest, sum_if)
Definition VectorTest.cpp:7
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
VT min_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Computes the minimum of the entries from the values that are selected by the (non-empty) filter.
Definition vector.h:635
VT max_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Computes the maximum of the entries from the values that are selected by the (non-empty) filter.
Definition vector.h:612
VT sum_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Sum the entries from values that are set to one in the filter vector.
Definition vector.h:596
std::vector< T > applyInversePermutation(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source)
Definition vector.h:1267
std::vector< T > applyInversePermutationToGroupedVector(std::vector< uint64_t > const &inversePermutation, std::vector< T > const &source, std::vector< uint64_t > const &rowGroupIndices)
Definition vector.h:1277