Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NativeMultiplier.cpp
Go to the documentation of this file.
1#include "NativeMultiplier.h"
2
9
10namespace storm {
11namespace solver {
12
13template<typename ValueType>
15 // Intentionally left empty.
16}
17
18template<typename ValueType>
19void NativeMultiplier<ValueType>::multiply(Environment const& env, std::vector<ValueType> const& x, std::vector<ValueType> const* b,
20 std::vector<ValueType>& result) const {
21 std::vector<ValueType>* target = &result;
22 if (&x == &result) {
23 target = &this->provideCachedVector(x.size());
24 }
25 multAdd(x, b, *target);
26 if (&x == &result) {
27 std::swap(result, *target);
28 }
29}
30
31template<typename ValueType>
32void NativeMultiplier<ValueType>::multiplyGaussSeidel(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b,
33 bool backwards) const {
34 if (backwards) {
35 this->matrix.multiplyWithVectorBackward(x, x, b);
36 } else {
37 this->matrix.multiplyWithVectorForward(x, x, b);
38 }
39}
40
41template<typename ValueType>
42void NativeMultiplier<ValueType>::multiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
43 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
44 std::vector<uint_fast64_t>* choices) const {
45 std::vector<ValueType>* target = &result;
46 if (&x == &result) {
47 target = &this->provideCachedVector(x.size());
48 }
49 multAddReduce(dir, rowGroupIndices, x, b, *target, choices);
50 if (&x == &result) {
51 std::swap(result, *target);
52 }
53}
54
55template<typename ValueType>
57 std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x,
58 std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices, bool backwards) const {
59 if (backwards) {
60 this->matrix.multiplyAndReduceBackward(dir, rowGroupIndices, x, b, x, choices);
61 } else {
62 this->matrix.multiplyAndReduceForward(dir, rowGroupIndices, x, b, x, choices);
63 }
64}
65
66template<typename ValueType>
67void NativeMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const {
68 for (auto const& entry : this->matrix.getRow(rowIndex)) {
69 value += entry.getValue() * x[entry.getColumn()];
70 }
71}
72
73template<typename ValueType>
74void NativeMultiplier<ValueType>::multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2,
75 ValueType& val2) const {
76 for (auto const& entry : this->matrix.getRow(rowIndex)) {
77 val1 += entry.getValue() * x1[entry.getColumn()];
78 val2 += entry.getValue() * x2[entry.getColumn()];
79 }
80}
81
82template<typename ValueType>
83void NativeMultiplier<ValueType>::multAdd(std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const {
84 this->matrix.multiplyWithVector(x, result, b);
85}
86
87template<typename ValueType>
88void NativeMultiplier<ValueType>::multAddReduce(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
89 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
90 std::vector<uint64_t>* choices) const {
91 this->matrix.multiplyAndReduce(dir, rowGroupIndices, x, b, result, choices);
92}
93
94template class NativeMultiplier<double>;
95template class NativeMultiplier<storm::RationalNumber>;
96template class NativeMultiplier<storm::RationalFunction>;
97template class NativeMultiplier<storm::Interval>;
98
99} // namespace solver
100} // namespace storm
virtual void multiplyAndReduceGaussSeidel(Environment const &env, OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > &x, std::vector< ValueType > const *b, std::vector< uint_fast64_t > *choices=nullptr, bool backwards=true) const override
void multiplyRow(uint64_t const &rowIndex, std::vector< ValueType > const &x, ValueType &value) const
Multiplies the row with the given index with x and adds the result to the provided value.
NativeMultiplier(storm::storage::SparseMatrix< ValueType > const &matrix)
void multiplyRow2(uint64_t const &rowIndex, std::vector< ValueType > const &x1, ValueType &val1, std::vector< ValueType > const &x2, ValueType &val2) const
Multiplies the row with the given index with x1 and x2 and adds the given offset o1 and o2,...
virtual void multiplyAndReduce(Environment const &env, OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result, std::vector< uint_fast64_t > *choices=nullptr) const override
virtual void multiplyGaussSeidel(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const *b, bool backwards=true) const override
Performs a matrix-vector multiplication in gauss-seidel style.
virtual void multiply(Environment const &env, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result) const override
Performs a matrix-vector multiplication x' = A*x + b.
A class that holds a possibly non-square matrix in the compressed row storage format.