From ec640c12b756bae6d16639b2159cbddc72f2641f Mon Sep 17 00:00:00 2001 From: dehnert Date: Sat, 18 Jun 2016 10:32:04 +0200 Subject: [PATCH] minor fixes to Eigen adapter Former-commit-id: 9095bbc9d459624ccfb6536e7f247a07114db9fa --- src/adapters/EigenAdapter.cpp | 26 +++++++++++++++++++++++++- src/adapters/EigenAdapter.h | 15 +-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/adapters/EigenAdapter.cpp b/src/adapters/EigenAdapter.cpp index 35aa9188c..aebdcd0ef 100644 --- a/src/adapters/EigenAdapter.cpp +++ b/src/adapters/EigenAdapter.cpp @@ -1 +1,25 @@ -#include "src/adapters/EigenAdapter.h" \ No newline at end of file +#include "src/adapters/EigenAdapter.h" + +namespace storm { + namespace adapters { + + template + static std::unique_ptr> toEigenSparseMatrix(storm::storage::SparseMatrix const& matrix) { + // Build a list of triplets and let Eigen care about the insertion. + std::vector> triplets; + triplets.reserve(matrix.getNonzeroEntryCount()); + + for (uint64_t row = 0; row < matrix.getRowCount(); ++row) { + for (auto const& element : matrix.getRow(row)) { + triplets.emplace_back(row, element.getColumn(), element.getValue()); + } + } + + std::unique_ptr> result = std::make_unique>(matrix.getRowCount(), matrix.getColumnCount()); + result->setFromTriplets(triplets.begin(), triplets.end()); + return result; + } + + template std::unique_ptr> toEigenSparseMatrix(storm::storage::SparseMatrix const& matrix); + } +} \ No newline at end of file diff --git a/src/adapters/EigenAdapter.h b/src/adapters/EigenAdapter.h index fc847094c..8f0f786ad 100644 --- a/src/adapters/EigenAdapter.h +++ b/src/adapters/EigenAdapter.h @@ -16,20 +16,7 @@ namespace storm { * @return A pointer to a row-major sparse matrix in gmm++ format. */ template - static std::unique_ptr> toEigenSparseMatrix(storm::storage::SparseMatrix const& matrix) { - std::vector> triplets; - triplets.reserve(matrix.getNonzeroEntryCount()); - - for (uint64_t row = 0; row < matrix.getRowCount(); ++row) { - for (auto const& element : matrix.getRow(row)) { - triplets.emplace_back(row, element.getColumn(), element.getValue()); - } - } - - std::unique_ptr> result = std::make_unique>(matrix.getRowCount(), matrix.getColumnCount()); - result->setFromTriplets(triplets.begin(), triplets.end()); - return result; - } + static std::unique_ptr> toEigenSparseMatrix(storm::storage::SparseMatrix const& matrix); }; }