Browse Source

Fixed some bugs in GmmxxAdapter and added row-vector product to sparse matrix.

tempestpy_adaptions
dehnert 12 years ago
parent
commit
756cbd4ed1
  1. 9
      src/adapters/GmmxxAdapter.h
  2. 37
      src/storage/SparseMatrix.h

9
src/adapters/GmmxxAdapter.h

@ -31,15 +31,16 @@ public:
LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros to gmm++ format."); LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros to gmm++ format.");
// 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.colCount);
// Copy Row Indications // Copy Row Indications
std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), std::back_inserter(result->jc));
std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), result->jc.begin());
// Copy Columns Indications // Copy Columns Indications
result->ir.resize(realNonZeros); result->ir.resize(realNonZeros);
std::copy(matrix.columnIndications.begin(), matrix.columnIndications.end(), std::back_inserter(result->ir));
std::copy(matrix.columnIndications.begin(), matrix.columnIndications.end(), result->ir.begin());
// And do the same thing with the actual values. // And do the same thing with the actual values.
std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), std::back_inserter(result->pr));
result->pr.resize(realNonZeros);
std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), result->pr.begin());
LOG4CPLUS_DEBUG(logger, "Done converting matrix to gmm++ format."); LOG4CPLUS_DEBUG(logger, "Done converting matrix to gmm++ format.");

37
src/storage/SparseMatrix.h

@ -887,29 +887,16 @@ public:
return result; return result;
} }
void repeatedMultiply(std::vector<T>* vector, uint_fast64_t multiplications) {
std::vector<T>* originalVector = vector;
std::vector<T>* swap = nullptr;
std::vector<T>* temporaryResult = new std::vector<T>(vector->size());
for (uint_fast64_t iter = 0; iter < multiplications; ++iter) {
for (uint_fast64_t row = 0; row < rowCount; ++row) {
(*temporaryResult)[row] = 0;
for (uint_fast64_t col = columnIndications[row]; col < columnIndications[row + 1]; ++col) {
(*temporaryResult)[row] += valueStorage[col] * (*vector)[row];
}
}
swap = temporaryResult;
temporaryResult = vector;
vector = swap;
}
if (multiplications % 2 == 1) {
*originalVector = *temporaryResult;
delete vector;
} else {
delete temporaryResult;
T getRowVectorProduct(uint_fast64_t row, std::vector<T>& vector) {
T result = storm::utility::constGetZero<T>();;
auto valueIterator = valueStorage.begin() + rowIndications[row];
const auto valueIteratorEnd = valueStorage.begin() + rowIndications[row + 1];
auto columnIterator = columnIndications.begin() + rowIndications[row];
const auto columnIteratorEnd = columnIndications.begin() + rowIndications[row + 1];
for (; valueIterator != valueIteratorEnd; ++valueIterator, ++columnIterator) {
result += *valueIterator * vector[*columnIterator];
} }
return result;
} }
/*! /*!
@ -1008,11 +995,7 @@ public:
std::cout << "entries in (" << rowCount << "x" << colCount << " matrix):" << std::endl; std::cout << "entries in (" << rowCount << "x" << colCount << " matrix):" << std::endl;
std::cout << rowIndications << std::endl; std::cout << rowIndications << std::endl;
std::cout << columnIndications << std::endl; std::cout << columnIndications << std::endl;
for (uint_fast64_t i = 0; i < rowCount; ++i) {
for (uint_fast64_t j = rowIndications[i]; j < rowIndications[i + 1]; ++j) {
std::cout << "(" << i << "," << columnIndications[j] << ") = " << valueStorage[j] << std::endl;
}
}
std::cout << valueStorage << std::endl;
} }
private: private:

Loading…
Cancel
Save