Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
EigenAdapter.cpp
Go to the documentation of this file.
2
4
5namespace storm {
6namespace adapters {
7
8template<typename ValueType>
9std::unique_ptr<Eigen::SparseMatrix<ValueType>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<ValueType> const& matrix) {
10 // Build a list of triplets and let Eigen care about the insertion.
11 std::vector<Eigen::Triplet<ValueType>> triplets;
12 triplets.reserve(matrix.getNonzeroEntryCount());
13
14 for (uint64_t row = 0; row < matrix.getRowCount(); ++row) {
15 for (auto const& element : matrix.getRow(row)) {
16 triplets.emplace_back(row, element.getColumn(), element.getValue());
17 }
18 }
19
20 std::unique_ptr<Eigen::SparseMatrix<ValueType>> result = std::make_unique<Eigen::SparseMatrix<ValueType>>(matrix.getRowCount(), matrix.getColumnCount());
21 result->setFromTriplets(triplets.begin(), triplets.end());
22 return result;
23}
24
25template<typename ValueType>
26std::vector<ValueType> EigenAdapter::toStdVector(Eigen::Matrix<ValueType, Eigen::Dynamic, 1> const& v) {
27 return std::vector<ValueType>(v.data(), v.data() + v.rows());
28}
29
30template<typename ValueType>
31Eigen::Matrix<ValueType, Eigen::Dynamic, 1> EigenAdapter::toEigenVector(std::vector<ValueType> const& v) {
32 return Eigen::Matrix<ValueType, Eigen::Dynamic, 1>::Map(v.data(), v.size());
33}
34
35template std::unique_ptr<Eigen::SparseMatrix<double>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<double> const& matrix);
36template std::vector<double> EigenAdapter::toStdVector(Eigen::Matrix<double, Eigen::Dynamic, 1> const& v);
37template Eigen::Matrix<double, Eigen::Dynamic, 1> EigenAdapter::toEigenVector(std::vector<double> const& v);
38
39template std::unique_ptr<Eigen::SparseMatrix<storm::RationalNumber>> EigenAdapter::toEigenSparseMatrix(
41template std::vector<storm::RationalNumber> EigenAdapter::toStdVector(Eigen::Matrix<storm::RationalNumber, Eigen::Dynamic, 1> const& v);
42template Eigen::Matrix<storm::RationalNumber, Eigen::Dynamic, 1> EigenAdapter::toEigenVector(std::vector<storm::RationalNumber> const& v);
43
44template std::unique_ptr<Eigen::SparseMatrix<storm::RationalFunction>> EigenAdapter::toEigenSparseMatrix(
46template std::vector<storm::RationalFunction> EigenAdapter::toStdVector(Eigen::Matrix<storm::RationalFunction, Eigen::Dynamic, 1> const& v);
47template Eigen::Matrix<storm::RationalFunction, Eigen::Dynamic, 1> EigenAdapter::toEigenVector(std::vector<storm::RationalFunction> const& v);
48} // namespace adapters
49} // namespace storm
static Eigen::Matrix< ValueType, Eigen::Dynamic, 1 > toEigenVector(std::vector< ValueType > const &v)
static std::unique_ptr< Eigen::SparseMatrix< ValueType > > toEigenSparseMatrix(storm::storage::SparseMatrix< ValueType > const &matrix)
Converts a sparse matrix into a sparse matrix in the gmm++ format.
static std::vector< ValueType > toStdVector(Eigen::Matrix< ValueType, Eigen::Dynamic, 1 > const &v)
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
index_type getColumnCount() const
Returns the number of columns of the matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
index_type getNonzeroEntryCount() const
Returns the cached number of nonzero entries in the matrix.