Browse Source

Refactored SparseMatrix, made references const.

Refactored Adapter to GMM to make use of new internal format
tempestpy_adaptions
PBerger 12 years ago
parent
commit
36e2f5f15b
  1. 45
      src/adapters/GmmxxAdapter.h
  2. 6
      src/storage/SquareSparseMatrix.h

45
src/adapters/GmmxxAdapter.h

@ -5,8 +5,8 @@
* Author: Christian Dehnert * Author: Christian Dehnert
*/ */
#ifndef GMMXXADAPTER_H_
#define GMMXXADAPTER_H_
#ifndef STORM_ADAPTERS_GMMXXADAPTER_H_
#define STORM_ADAPTERS_GMMXXADAPTER_H_
#include "src/storage/SquareSparseMatrix.h" #include "src/storage/SquareSparseMatrix.h"
@ -33,42 +33,13 @@ public:
// Prepare the resulting matrix. // Prepare the resulting matrix.
gmm::csr_matrix<T>* result = new gmm::csr_matrix<T>(matrix.rowCount, matrix.rowCount); gmm::csr_matrix<T>* result = new gmm::csr_matrix<T>(matrix.rowCount, matrix.rowCount);
// Reserve enough elements for the row indications.
result->jc.reserve(matrix.rowCount + 1);
// For the column indications and the actual values, we have to gather
// the values in a temporary array first, as we have to integrate
// the values from the diagonal. For the row indications, we can just count the number of
// inserted diagonal elements and add it to the previous value.
uint_fast64_t* tmpColumnIndicationsArray = new uint_fast64_t[realNonZeros];
T* tmpValueArray = new T[realNonZeros];
T zero(0);
uint_fast64_t currentPosition = 0;
for (uint_fast64_t i = 0; i < matrix.rowCount; ++i) {
// Compute correct start index of row.
result->jc[i] = matrix.rowIndications[i];
// Otherwise, we can just enumerate the non-zeros which are not on the diagonal
// and fit in the diagonal element where appropriate.
for (uint_fast64_t j = matrix.rowIndications[i]; j < matrix.rowIndications[i + 1]; ++j) {
tmpColumnIndicationsArray[currentPosition] = matrix.columnIndications[j];
tmpValueArray[currentPosition] = matrix.valueStorage[j];
++currentPosition;
}
}
// Fill in sentinel element at the end.
result->jc[matrix.rowCount] = static_cast<unsigned int>(realNonZeros);
// Now, we can copy the temporary array to the GMMXX format.
// FIXME Now everything can just be copied. No TMP needed anymore
// Copy Row Indications
std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), std::back_inserter(result->jc));
// Copy Columns Indications
result->ir.resize(realNonZeros); result->ir.resize(realNonZeros);
std::copy(tmpColumnIndicationsArray, tmpColumnIndicationsArray + realNonZeros, result->ir.begin());
delete[] tmpColumnIndicationsArray;
std::copy(matrix.columnIndications.begin(), matrix.columnIndications.end(), std::back_inserter(result->ir));
// And do the same thing with the actual values. // And do the same thing with the actual values.
result->pr.resize(realNonZeros);
std::copy(tmpValueArray, tmpValueArray + realNonZeros, result->pr.begin());
delete[] tmpValueArray;
std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), std::back_inserter(result->pr));
LOG4CPLUS_DEBUG(logger, "Done converting matrix to gmm++ format."); LOG4CPLUS_DEBUG(logger, "Done converting matrix to gmm++ format.");
@ -80,4 +51,4 @@ public:
} //namespace storm } //namespace storm
#endif /* GMMXXADAPTER_H_ */
#endif /* STORM_ADAPTERS_GMMXXADAPTER_H_ */

6
src/storage/SquareSparseMatrix.h

@ -470,7 +470,7 @@ public:
* Returns a pointer to the value storage of the matrix. * Returns a pointer to the value storage of the matrix.
* @return A pointer to the value storage of the matrix. * @return A pointer to the value storage of the matrix.
*/ */
std::vector<T>& getStoragePointer() {
std::vector<T> const & getStoragePointer() const {
return valueStorage; return valueStorage;
} }
@ -480,7 +480,7 @@ public:
* @return A pointer to the array that stores the start indices of non-zero * @return A pointer to the array that stores the start indices of non-zero
* entries in the value storage for each row. * entries in the value storage for each row.
*/ */
std::vector<uint_fast64_t>& getRowIndicationsPointer() {
std::vector<uint_fast64_t> const & getRowIndicationsPointer() const {
return rowIndications; return rowIndications;
} }
@ -490,7 +490,7 @@ public:
* @return A pointer to an array that stores the column of each non-zero * @return A pointer to an array that stores the column of each non-zero
* element. * element.
*/ */
std::vector<uint_fast64_t>& getColumnIndicationsPointer() {
std::vector<uint_fast64_t> const & getColumnIndicationsPointer() const {
return columnIndications; return columnIndications;
} }

Loading…
Cancel
Save