You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.5 KiB

  1. #include "src/adapters/EigenAdapter.h"
  2. namespace storm {
  3. namespace adapters {
  4. template<typename ValueType>
  5. std::unique_ptr<Eigen::SparseMatrix<ValueType>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<ValueType> const& matrix) {
  6. // Build a list of triplets and let Eigen care about the insertion.
  7. std::vector<Eigen::Triplet<ValueType>> triplets;
  8. triplets.reserve(matrix.getNonzeroEntryCount());
  9. for (uint64_t row = 0; row < matrix.getRowCount(); ++row) {
  10. for (auto const& element : matrix.getRow(row)) {
  11. triplets.emplace_back(row, element.getColumn(), element.getValue());
  12. }
  13. }
  14. std::unique_ptr<Eigen::SparseMatrix<ValueType>> result = std::make_unique<Eigen::SparseMatrix<ValueType>>(matrix.getRowCount(), matrix.getColumnCount());
  15. result->setFromTriplets(triplets.begin(), triplets.end());
  16. return result;
  17. }
  18. template std::unique_ptr<Eigen::SparseMatrix<double>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<double> const& matrix);
  19. template std::unique_ptr<Eigen::SparseMatrix<storm::RationalNumber>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<storm::RationalNumber> const& matrix);
  20. template std::unique_ptr<Eigen::SparseMatrix<storm::RationalFunction>> EigenAdapter::toEigenSparseMatrix(storm::storage::SparseMatrix<storm::RationalFunction> const& matrix);
  21. }
  22. }