Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
EigenAdapter.cpp
Go to the documentation of this file.
3
4namespace storm {
5namespace adapters {
6
7template<typename ValueType>
8std::unique_ptr<Eigen::SparseMatrix<ValueType>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<ValueType> const& matrix) {
9 // Build a list of triplets and let Eigen care about the insertion.
10 std::vector<Eigen::Triplet<ValueType>> triplets;
11 triplets.reserve(matrix.getNonzeroEntryCount());
12
13 for (uint64_t row = 0; row < matrix.getRowCount(); ++row) {
14 for (auto const& element : matrix.getRow(row)) {
15 triplets.emplace_back(row, element.getColumn(), element.getValue());
16 }
17 }
18
19 std::unique_ptr<Eigen::SparseMatrix<ValueType>> result = std::make_unique<Eigen::SparseMatrix<ValueType>>(matrix.getRowCount(), matrix.getColumnCount());
20 result->setFromTriplets(triplets.begin(), triplets.end());
21 return result;
22}
23
24template<typename ValueType>
25std::vector<ValueType> EigenAdapter::toStdVector(Eigen::Matrix<ValueType, Eigen::Dynamic, 1> const& v) {
26 return std::vector<ValueType>(v.data(), v.data() + v.rows());
27}
28
29template<typename ValueType>
30Eigen::Matrix<ValueType, Eigen::Dynamic, 1> EigenAdapter::toEigenVector(std::vector<ValueType> const& v) {
31 return Eigen::Matrix<ValueType, Eigen::Dynamic, 1>::Map(v.data(), v.size());
32}
33
34template std::unique_ptr<Eigen::SparseMatrix<double>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<double> const& matrix);
35template std::vector<double> EigenAdapter::toStdVector(Eigen::Matrix<double, Eigen::Dynamic, 1> const& v);
36template Eigen::Matrix<double, Eigen::Dynamic, 1> EigenAdapter::toEigenVector(std::vector<double> const& v);
37
38#ifdef STORM_HAVE_CARL
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#endif
49} // namespace adapters
50} // 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.
LabParser.cpp.
Definition cli.cpp:18