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.

54 lines
1.5 KiB

  1. /*
  2. * GmmxxAdapter.h
  3. *
  4. * Created on: 24.12.2012
  5. * Author: Christian Dehnert
  6. */
  7. #ifndef STORM_ADAPTERS_GMMXXADAPTER_H_
  8. #define STORM_ADAPTERS_GMMXXADAPTER_H_
  9. #include "src/storage/SparseMatrix.h"
  10. #include "log4cplus/logger.h"
  11. #include "log4cplus/loggingmacros.h"
  12. extern log4cplus::Logger logger;
  13. namespace storm {
  14. namespace adapters {
  15. class GmmxxAdapter {
  16. public:
  17. /*!
  18. * Converts a sparse matrix into the sparse matrix in the gmm++ format.
  19. * @return A pointer to a column-major sparse matrix in gmm++ format.
  20. */
  21. template<class T>
  22. static gmm::csr_matrix<T>* toGmmxxSparseMatrix(storm::storage::SparseMatrix<T> const& matrix) {
  23. uint_fast64_t realNonZeros = matrix.getNonZeroEntryCount();
  24. LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros to gmm++ format.");
  25. // Prepare the resulting matrix.
  26. gmm::csr_matrix<T>* result = new gmm::csr_matrix<T>(matrix.rowCount, matrix.rowCount);
  27. // Copy Row Indications
  28. std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), std::back_inserter(result->jc));
  29. // Copy Columns Indications
  30. result->ir.resize(realNonZeros);
  31. std::copy(matrix.columnIndications.begin(), matrix.columnIndications.end(), std::back_inserter(result->ir));
  32. // And do the same thing with the actual values.
  33. std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), std::back_inserter(result->pr));
  34. LOG4CPLUS_DEBUG(logger, "Done converting matrix to gmm++ format.");
  35. return result;
  36. }
  37. };
  38. } //namespace adapters
  39. } //namespace storm
  40. #endif /* STORM_ADAPTERS_GMMXXADAPTER_H_ */