Browse Source
Finished reworking the sparse matrix implementation. Adapted all other classes to the (partially) new API of the matrix.
Finished reworking the sparse matrix implementation. Adapted all other classes to the (partially) new API of the matrix.
Former-commit-id: 2c3b5a5bc3
main
36 changed files with 428 additions and 1486 deletions
-
66src/adapters/EigenAdapter.h
-
31src/adapters/ExplicitModelAdapter.h
-
10src/adapters/GmmxxAdapter.h
-
25src/adapters/StormAdapter.h
-
75src/counterexamples/MILPMinimalLabelSetGenerator.h
-
12src/counterexamples/PathBasedSubsystemGenerator.h
-
94src/counterexamples/SMTMinimalCommandSetGenerator.h
-
11src/modelchecker/csl/SparseMarkovAutomatonCslModelChecker.h
-
7src/modelchecker/prctl/SparseDtmcPrctlModelChecker.h
-
2src/modelchecker/prctl/SparseMdpPrctlModelChecker.h
-
19src/models/AbstractDeterministicModel.h
-
24src/models/AbstractModel.h
-
37src/models/AbstractNondeterministicModel.h
-
48src/models/Dtmc.h
-
42src/models/MarkovAutomaton.h
-
10src/models/Mdp.h
-
7src/parser/DeterministicSparseTransitionParser.cpp
-
3src/parser/MarkovAutomatonSparseTransitionParser.h
-
8src/parser/NondeterministicSparseTransitionParser.cpp
-
11src/solver/AbstractNondeterministicLinearEquationSolver.h
-
14src/storage/MaximalEndComponentDecomposition.cpp
-
332src/storage/SparseMatrix.cpp
-
20src/storage/SparseMatrix.h
-
4src/storage/StronglyConnectedComponentDecomposition.cpp
-
16src/utility/counterexamples.h
-
105src/utility/graph.h
-
6src/utility/matrix.h
-
17src/utility/vector.h
-
79test/functional/eigen/EigenSparseMatrixTest.cpp
-
1test/functional/modelchecker/GmmxxDtmcPrctlModelCheckerTest.cpp
-
77test/functional/parser/ReadTraFileTest.cpp
-
386test/functional/storage/SparseMatrixTest.cpp
-
100test/functional/storage/adapters/EigenAdapterTest.cpp
-
111test/functional/storage/adapters/GmmAdapterTest.cpp
-
104test/functional/storage/adapters/StormAdapterTest.cpp
-
BINutil/checklist/storage.ods
@ -1,66 +0,0 @@ |
|||||
/* |
|
||||
* EigenAdapter.h |
|
||||
* |
|
||||
* Created on: 21.01.2013 |
|
||||
* Author: Philipp Berger |
|
||||
*/ |
|
||||
|
|
||||
#ifndef STORM_ADAPTERS_EIGENADAPTER_H_ |
|
||||
#define STORM_ADAPTERS_EIGENADAPTER_H_ |
|
||||
|
|
||||
#include "src/storage/SparseMatrix.h" |
|
||||
#include "Eigen/Sparse" |
|
||||
|
|
||||
#include "log4cplus/logger.h" |
|
||||
#include "log4cplus/loggingmacros.h" |
|
||||
|
|
||||
#include "src/utility/OsDetection.h" |
|
||||
|
|
||||
extern log4cplus::Logger logger; |
|
||||
|
|
||||
namespace storm { |
|
||||
|
|
||||
namespace adapters { |
|
||||
|
|
||||
class EigenAdapter { |
|
||||
public: |
|
||||
/*! |
|
||||
* Converts a sparse matrix into the sparse matrix in the eigen format. |
|
||||
* @return A pointer to a row-major sparse matrix in eigen format. |
|
||||
*/ |
|
||||
template<class T> |
|
||||
static Eigen::SparseMatrix<T, Eigen::RowMajor, int_fast32_t>* toEigenSparseMatrix(storm::storage::SparseMatrix<T> const& matrix) { |
|
||||
uint_fast64_t realNonZeros = matrix.getNonZeroEntryCount(); |
|
||||
LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros to Eigen format."); |
|
||||
|
|
||||
// Prepare the resulting matrix. |
|
||||
Eigen::SparseMatrix<T, Eigen::RowMajor, int_fast32_t>* result = new Eigen::SparseMatrix<T, Eigen::RowMajor, int_fast32_t>(static_cast<int>(matrix.rowCount), static_cast<int>(matrix.colCount)); |
|
||||
|
|
||||
result->resizeNonZeros(static_cast<int>(realNonZeros)); |
|
||||
//result->reserve(realNonZeros); |
|
||||
#ifdef WINDOWS |
|
||||
# pragma warning(push) |
|
||||
# pragma warning(disable: 4244) // possible loss of data |
|
||||
#endif |
|
||||
// Copy Row Indications |
|
||||
std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), (result->outerIndexPtr())); |
|
||||
// Copy Columns Indications |
|
||||
std::copy(matrix.columnIndications.begin(), matrix.columnIndications.end(), (result->innerIndexPtr())); |
|
||||
// And do the same thing with the actual values. |
|
||||
std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), (result->valuePtr())); |
|
||||
|
|
||||
#ifdef WINDOWS |
|
||||
# pragma warning(pop) |
|
||||
#endif |
|
||||
|
|
||||
LOG4CPLUS_DEBUG(logger, "Done converting matrix to Eigen format."); |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
} //namespace adapters |
|
||||
|
|
||||
} //namespace storm |
|
||||
|
|
||||
#endif /* STORM_ADAPTERS_EIGENADAPTER_H_ */ |
|
@ -1,79 +0,0 @@ |
|||||
#include "gtest/gtest.h"
|
|
||||
|
|
||||
#include "Eigen/Sparse"
|
|
||||
#include "src/exceptions/InvalidArgumentException.h"
|
|
||||
#include <cstdint>
|
|
||||
|
|
||||
TEST(EigenSparseMatrixTest, BasicReadWriteTest) { |
|
||||
// 25 rows, 50 non zero entries
|
|
||||
Eigen::SparseMatrix<int, 1> esm(25, 25); |
|
||||
|
|
||||
int values[50] = { |
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
|
||||
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, |
|
||||
40, 41, 42, 43, 44, 45, 46, 47, 48, 49 |
|
||||
}; |
|
||||
int position_row[50] = { |
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
|
||||
2, 2, 2, 2, /* first row empty, one full row 25 minus the diagonal entry */ |
|
||||
4, 4, /* one empty row, then first and last column */ |
|
||||
13, 13, 13, 13, /* a few empty rows, middle columns */ |
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24 /* second to last row */ |
|
||||
}; |
|
||||
int position_col[50] = { |
|
||||
1, 3, 4, 5, 6, 7, 8, 9, 10, |
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
|
||||
21, 22, 23, 24, 25, /* first row empty, one full row a 25 */ |
|
||||
1, 25, /* one empty row, then first and last column */ |
|
||||
16, 17, 18, 19, /* a few empty rows, middle columns */ |
|
||||
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23 /* second to last row */ |
|
||||
}; |
|
||||
|
|
||||
typedef Eigen::Triplet<double> ETd; |
|
||||
std::vector<ETd> tripletList; |
|
||||
tripletList.reserve(50); |
|
||||
|
|
||||
for (int i = 0; i < 50; ++i) { |
|
||||
ASSERT_NO_THROW(tripletList.push_back(ETd(position_row[i] - 1, position_col[i] - 1, values[i]))); |
|
||||
} |
|
||||
|
|
||||
ASSERT_NO_THROW(esm.setFromTriplets(tripletList.begin(), tripletList.end())); |
|
||||
|
|
||||
for (int i = 0; i < 50; ++i) { |
|
||||
Eigen::SparseMatrix<int, 1>::InnerIterator it(esm, position_row[i] - 1); |
|
||||
ASSERT_EQ(values[i], esm.coeff(position_row[i] - 1, position_col[i] - 1)); |
|
||||
} |
|
||||
|
|
||||
// test for a few of the empty rows
|
|
||||
for (int row = 15; row < 24; ++row) { |
|
||||
for (int col = 1; col <= 25; ++col) { |
|
||||
ASSERT_EQ(0, esm.coeff(row - 1, col - 1)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
TEST(EigenSparseMatrixTest, BoundaryTest) { |
|
||||
Eigen::SparseMatrix<int, 1> esm(10, 10); |
|
||||
esm.reserve(100); |
|
||||
int values[100]; |
|
||||
for (uint_fast32_t i = 0; i < 100; ++i) { |
|
||||
values[i] = i; |
|
||||
} |
|
||||
|
|
||||
for (uint_fast32_t row = 0; row < 10; ++row) { |
|
||||
for (uint_fast32_t col = 0; col < 10; ++col) { |
|
||||
ASSERT_NO_THROW(esm.insert(row, col) = values[row * 10 + col]); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
for (uint_fast32_t row = 0; row < 10; ++row) { |
|
||||
for (uint_fast32_t col = 0; col < 10; ++col) { |
|
||||
ASSERT_EQ(values[row * 10 + col], esm.coeff(row, col)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,77 +0,0 @@ |
|||||
/*
|
|
||||
* ReadTraFileTest.cpp |
|
||||
* |
|
||||
* Created on: 16.08.2012 |
|
||||
* Author: Thomas Heinemann |
|
||||
*/ |
|
||||
|
|
||||
#include "gtest/gtest.h"
|
|
||||
#include "storm-config.h"
|
|
||||
#include "src/storage/SparseMatrix.h"
|
|
||||
#include "src/parser/DeterministicSparseTransitionParser.h"
|
|
||||
#include "src/exceptions/FileIoException.h"
|
|
||||
#include "src/exceptions/WrongFormatException.h"
|
|
||||
|
|
||||
TEST(ReadTraFileTest, NonExistingFileTest) { |
|
||||
//No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-)
|
|
||||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException); |
|
||||
} |
|
||||
|
|
||||
/* The following test case is based on one of the original MRMC test cases
|
|
||||
*/ |
|
||||
TEST(ReadTraFileTest, ParseFileTest1) { |
|
||||
storm::storage::SparseMatrix<double> result = storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/csl_general_input_01.tra"); |
|
||||
|
|
||||
double val = 0.0; |
|
||||
ASSERT_TRUE(result.getValue(0, 0, &val)); |
|
||||
ASSERT_EQ(val, 0.0); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(0, 1, &val)); |
|
||||
ASSERT_EQ(val, 1.0); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(1, 1, &val)); |
|
||||
ASSERT_EQ(val, 0.080645161290322580645161290322581); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(1, 2, &val)); |
|
||||
ASSERT_EQ(val, 0.080645161290322580645161290322581); |
|
||||
|
|
||||
//Transition 1->3 was not set in the file, so it is not to appear in the matrix!
|
|
||||
ASSERT_FALSE(result.getValue(1, 3, &val)); |
|
||||
ASSERT_EQ(val, 0); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(2, 1, &val)); |
|
||||
ASSERT_EQ(val, 0.04032258064516129032258064516129); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(2, 2, &val)); |
|
||||
ASSERT_EQ(val, 0.04032258064516129032258064516129); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(2, 3, &val)); |
|
||||
ASSERT_EQ(val, 0.04032258064516129032258064516129); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(2, 4, &val)); |
|
||||
ASSERT_EQ(val, 0.04032258064516129032258064516129); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(3, 2, &val)); |
|
||||
ASSERT_EQ(val, 0.0806451612903225806451612903225812); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(3, 3, &val)); |
|
||||
ASSERT_EQ(val, 0.0); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(3, 4, &val)); |
|
||||
ASSERT_EQ(val, 0.080645161290322580645161290322581); |
|
||||
|
|
||||
ASSERT_TRUE(result.getValue(4, 4, &val)); |
|
||||
ASSERT_EQ(val, 0.0); |
|
||||
} |
|
||||
|
|
||||
TEST(ReadTraFileTest, WrongFormatTestHeader1) { |
|
||||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/wrong_format_header1.tra"), storm::exceptions::WrongFormatException); |
|
||||
} |
|
||||
|
|
||||
TEST(ReadTraFileTest, WrongFormatTestHeader2) { |
|
||||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/wrong_format_header2.tra"), storm::exceptions::WrongFormatException); |
|
||||
} |
|
||||
|
|
||||
TEST(ReadTraFileTest, WrongFormatTestTransition) { |
|
||||
ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/wrong_format_transition.tra"), storm::exceptions::WrongFormatException); |
|
||||
} |
|
@ -1,386 +0,0 @@ |
|||||
#include "gtest/gtest.h"
|
|
||||
#include "src/storage/SparseMatrix.h"
|
|
||||
#include "src/exceptions/InvalidArgumentException.h"
|
|
||||
#include "src/exceptions/OutOfRangeException.h"
|
|
||||
#include "src/adapters/EigenAdapter.h"
|
|
||||
#include "src/adapters/StormAdapter.h"
|
|
||||
|
|
||||
TEST(SparseMatrixTest, ZeroRowsTest) { |
|
||||
storm::storage::SparseMatrix<int> *ssm = new storm::storage::SparseMatrix<int>(0); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::UnInitialized); |
|
||||
|
|
||||
ASSERT_THROW(ssm->initialize(50), storm::exceptions::InvalidArgumentException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, TooManyEntriesTest) { |
|
||||
storm::storage::SparseMatrix<int> *ssm = new storm::storage::SparseMatrix<int>(2); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::UnInitialized); |
|
||||
|
|
||||
ASSERT_THROW(ssm->initialize(10), storm::exceptions::InvalidArgumentException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, addNextValueTest) { |
|
||||
storm::storage::SparseMatrix<int> *ssm = new storm::storage::SparseMatrix<int>(5); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::UnInitialized); |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->initialize(1)); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
ASSERT_THROW(ssm->addNextValue(-1, 1, 1), storm::exceptions::OutOfRangeException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
ASSERT_THROW(ssm->addNextValue(1, -1, 1), storm::exceptions::OutOfRangeException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
ASSERT_THROW(ssm->addNextValue(6, 1, 1), storm::exceptions::OutOfRangeException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
ASSERT_THROW(ssm->addNextValue(1, 6, 1), storm::exceptions::OutOfRangeException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, finalizeTest) { |
|
||||
storm::storage::SparseMatrix<int> *ssm = new storm::storage::SparseMatrix<int>(5); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::UnInitialized); |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->initialize(5)); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->addNextValue(1, 2, 1)); |
|
||||
ASSERT_NO_THROW(ssm->addNextValue(1, 3, 1)); |
|
||||
ASSERT_NO_THROW(ssm->addNextValue(1, 4, 1)); |
|
||||
ASSERT_NO_THROW(ssm->addNextValue(1, 5, 1)); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
ASSERT_THROW(ssm->finalize(), storm::exceptions::InvalidStateException); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Error); |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, Test) { |
|
||||
// 25 rows, 50 non zero entries
|
|
||||
storm::storage::SparseMatrix<int> *ssm = new storm::storage::SparseMatrix<int>(25); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::UnInitialized); |
|
||||
|
|
||||
int values[50] = { |
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
|
||||
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, |
|
||||
40, 41, 42, 43, 44, 45, 46, 47, 48, 49 |
|
||||
}; |
|
||||
int position_row[50] = { |
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
|
||||
2, 2, 2, 2, /* first row empty, one full row 25 minus the diagonal entry */ |
|
||||
4, 4, /* one empty row, then first and last column */ |
|
||||
13, 13, 13, 13, /* a few empty rows, middle columns */ |
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24 /* second to last row */ |
|
||||
}; |
|
||||
int position_col[50] = { |
|
||||
1, 3, 4, 5, 6, 7, 8, 9, 10, |
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
|
||||
21, 22, 23, 24, 25, /* first row empty, one full row a 25 */ |
|
||||
1, 25, /* one empty row, then first and last column */ |
|
||||
16, 17, 18, 19, /* a few empty rows, middle columns */ |
|
||||
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23 /* second to last row */ |
|
||||
}; |
|
||||
int row_sums[25] = {}; |
|
||||
for (int i = 0; i < 50; ++i) { |
|
||||
row_sums[position_row[i]] += values[i]; |
|
||||
} |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->initialize(50)); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
for (int i = 0; i < 50; ++i) { |
|
||||
ASSERT_NO_THROW(ssm->addNextValue(position_row[i], position_col[i], values[i])); |
|
||||
} |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->finalize()); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
int target; |
|
||||
for (int i = 0; i < 50; ++i) { |
|
||||
ASSERT_TRUE(ssm->getValue(position_row[i], position_col[i], &target)); |
|
||||
ASSERT_EQ(values[i], target); |
|
||||
} |
|
||||
|
|
||||
// test for a few of the empty rows
|
|
||||
for (int row = 15; row < 24; ++row) { |
|
||||
for (int col = 1; col <= 25; ++col) { |
|
||||
target = 1; |
|
||||
ASSERT_FALSE(ssm->getValue(row, col, &target)); |
|
||||
|
|
||||
ASSERT_EQ(0, target); |
|
||||
} |
|
||||
} |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
// Test Row Sums
|
|
||||
for (int row = 0; row < 25; ++row) { |
|
||||
ASSERT_EQ(row_sums[row], ssm->getRowSum(row)); |
|
||||
} |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) { |
|
||||
// 10 rows, 100 non zero entries
|
|
||||
Eigen::SparseMatrix<int> esm(10, 10); |
|
||||
for (int row = 0; row < 10; ++row) { |
|
||||
for (int col = 0; col < 10; ++col) { |
|
||||
esm.insert(row, col) = row * 10 + col; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// make compressed, important for initialize()
|
|
||||
esm.makeCompressed(); |
|
||||
|
|
||||
storm::storage::SparseMatrix<int> *ssm = nullptr; |
|
||||
ASSERT_NO_THROW(ssm = storm::adapters::StormAdapter::toStormSparseMatrix(esm)); |
|
||||
|
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
int target = -1; |
|
||||
for (int row = 0; row < 10; ++row) { |
|
||||
for (int col = 0; col < 10; ++col) { |
|
||||
ASSERT_TRUE(ssm->getValue(row, col, &target)); |
|
||||
ASSERT_EQ(target, row * 10 + col); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) { |
|
||||
// 10 rows, 100 non zero entries
|
|
||||
Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10); |
|
||||
for (int row = 0; row < 10; ++row) { |
|
||||
for (int col = 0; col < 10; ++col) { |
|
||||
esm.insert(row, col) = row * 10 + col; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// make compressed, important for initialize()
|
|
||||
esm.makeCompressed(); |
|
||||
|
|
||||
storm::storage::SparseMatrix<int> *ssm = nullptr; |
|
||||
ASSERT_NO_THROW(ssm = storm::adapters::StormAdapter::toStormSparseMatrix(esm)); |
|
||||
|
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
int target = -1; |
|
||||
for (int row = 0; row < 10; ++row) { |
|
||||
for (int col = 0; col < 10; ++col) { |
|
||||
ASSERT_TRUE(ssm->getValue(row, col, &target)); |
|
||||
ASSERT_EQ(target, row * 10 + col); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest) { |
|
||||
// 10 rows, 15 non zero entries
|
|
||||
Eigen::SparseMatrix<int> esm(10, 10); |
|
||||
|
|
||||
typedef Eigen::Triplet<int> IntTriplet; |
|
||||
std::vector<IntTriplet> tripletList; |
|
||||
tripletList.reserve(15); |
|
||||
tripletList.push_back(IntTriplet(1, 0, 0)); |
|
||||
tripletList.push_back(IntTriplet(1, 1, 1)); |
|
||||
tripletList.push_back(IntTriplet(1, 2, 2)); |
|
||||
tripletList.push_back(IntTriplet(1, 3, 3)); |
|
||||
tripletList.push_back(IntTriplet(1, 4, 4)); |
|
||||
tripletList.push_back(IntTriplet(1, 5, 5)); |
|
||||
tripletList.push_back(IntTriplet(1, 6, 6)); |
|
||||
tripletList.push_back(IntTriplet(1, 7, 7)); |
|
||||
tripletList.push_back(IntTriplet(1, 8, 8)); |
|
||||
tripletList.push_back(IntTriplet(1, 9, 9)); |
|
||||
|
|
||||
tripletList.push_back(IntTriplet(4, 3, 10)); |
|
||||
tripletList.push_back(IntTriplet(4, 6, 11)); |
|
||||
tripletList.push_back(IntTriplet(4, 9, 12)); |
|
||||
|
|
||||
tripletList.push_back(IntTriplet(6, 0, 13)); |
|
||||
tripletList.push_back(IntTriplet(8, 9, 14)); |
|
||||
|
|
||||
esm.setFromTriplets(tripletList.begin(), tripletList.end()); |
|
||||
|
|
||||
// make compressed, important for initialize()
|
|
||||
esm.makeCompressed(); |
|
||||
|
|
||||
storm::storage::SparseMatrix<int> *ssm = nullptr; |
|
||||
ASSERT_NO_THROW(ssm = storm::adapters::StormAdapter::toStormSparseMatrix(esm)); |
|
||||
|
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
int target = -1; |
|
||||
|
|
||||
for (auto &coeff: tripletList) { |
|
||||
ASSERT_TRUE(ssm->getValue(coeff.row(), coeff.col(), &target)); |
|
||||
ASSERT_EQ(target, coeff.value()); |
|
||||
} |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest) { |
|
||||
// 10 rows, 15 non zero entries
|
|
||||
Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10); |
|
||||
|
|
||||
typedef Eigen::Triplet<int> IntTriplet; |
|
||||
std::vector<IntTriplet> tripletList; |
|
||||
tripletList.reserve(15); |
|
||||
tripletList.push_back(IntTriplet(1, 0, 15)); |
|
||||
tripletList.push_back(IntTriplet(1, 1, 1)); |
|
||||
tripletList.push_back(IntTriplet(1, 2, 2)); |
|
||||
tripletList.push_back(IntTriplet(1, 3, 3)); |
|
||||
tripletList.push_back(IntTriplet(1, 4, 4)); |
|
||||
tripletList.push_back(IntTriplet(1, 5, 5)); |
|
||||
tripletList.push_back(IntTriplet(1, 6, 6)); |
|
||||
tripletList.push_back(IntTriplet(1, 7, 7)); |
|
||||
tripletList.push_back(IntTriplet(1, 8, 8)); |
|
||||
tripletList.push_back(IntTriplet(1, 9, 9)); |
|
||||
|
|
||||
tripletList.push_back(IntTriplet(4, 3, 10)); |
|
||||
tripletList.push_back(IntTriplet(4, 6, 11)); |
|
||||
tripletList.push_back(IntTriplet(4, 9, 12)); |
|
||||
|
|
||||
tripletList.push_back(IntTriplet(6, 0, 13)); |
|
||||
tripletList.push_back(IntTriplet(8, 9, 14)); |
|
||||
|
|
||||
esm.setFromTriplets(tripletList.begin(), tripletList.end()); |
|
||||
|
|
||||
// make compressed, important for initialize()
|
|
||||
esm.makeCompressed(); |
|
||||
|
|
||||
storm::storage::SparseMatrix<int> *ssm = nullptr; |
|
||||
ASSERT_NO_THROW(ssm = storm::adapters::StormAdapter::toStormSparseMatrix(esm)); |
|
||||
|
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
int target = -1; |
|
||||
for (auto &coeff: tripletList) { |
|
||||
bool retVal = ssm->getValue(coeff.row(), coeff.col(), &target); |
|
||||
ASSERT_TRUE(retVal); |
|
||||
ASSERT_EQ(target, coeff.value()); |
|
||||
} |
|
||||
|
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, ConversionToSparseEigen_RowMajor_SparseMatrixTest) { |
|
||||
int values[100]; |
|
||||
storm::storage::SparseMatrix<int> *ssm = new storm::storage::SparseMatrix<int>(10); |
|
||||
|
|
||||
for (uint_fast32_t i = 0; i < 100; ++i) { |
|
||||
values[i] = i; |
|
||||
} |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->initialize(100)); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
for (uint_fast32_t row = 0; row < 10; ++row) { |
|
||||
for (uint_fast32_t col = 0; col < 10; ++col) { |
|
||||
ASSERT_NO_THROW(ssm->addNextValue(row, col, values[row * 10 + col])); |
|
||||
} |
|
||||
} |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::Initialized); |
|
||||
|
|
||||
ASSERT_NO_THROW(ssm->finalize()); |
|
||||
ASSERT_EQ(ssm->getState(), storm::storage::SparseMatrix<int>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
Eigen::SparseMatrix<int, Eigen::RowMajor, int_fast32_t>* esm = storm::adapters::EigenAdapter::toEigenSparseMatrix<int>(*ssm); |
|
||||
|
|
||||
for (uint_fast32_t row = 0; row < 10; ++row) { |
|
||||
for (uint_fast32_t col = 0; col < 10; ++col) { |
|
||||
ASSERT_EQ(values[row * 10 + col], esm->coeff(row, col)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
delete esm; |
|
||||
delete ssm; |
|
||||
} |
|
||||
|
|
||||
#ifdef STORM_USE_TBB
|
|
||||
TEST(SparseMatrixTest, TBBMatrixMultTest) { |
|
||||
storm::storage::SparseMatrix<double> matrix(10, 10); |
|
||||
ASSERT_NO_THROW(matrix.initialize(100)); |
|
||||
double values[100]; |
|
||||
std::vector<double> x; |
|
||||
x.resize(10); |
|
||||
for (uint_fast64_t i = 0; i < 100; ++i) { |
|
||||
values[i] = i + 1.0; |
|
||||
if (i < 10) { |
|
||||
x[i] = 1.0; |
|
||||
} |
|
||||
matrix.addNextValue(i / 10, i % 10, values[i]); |
|
||||
} |
|
||||
ASSERT_NO_THROW(matrix.finalize()); |
|
||||
ASSERT_EQ(matrix.getState(), storm::storage::SparseMatrix<double>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
std::vector<double> result; |
|
||||
result.resize(10); |
|
||||
|
|
||||
matrix.multiplyWithVector(x, result); |
|
||||
|
|
||||
for (uint_fast64_t i = 0; i < 10; ++i) { |
|
||||
double rowSum = 0.0; |
|
||||
for (uint_fast64_t j = 0; j < 10; ++j) { |
|
||||
rowSum += values[10 * i + j]; |
|
||||
} |
|
||||
ASSERT_EQ(rowSum, result.at(i)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
TEST(SparseMatrixTest, TBBSparseMatrixMultTest) { |
|
||||
storm::storage::SparseMatrix<double> matrix(10, 10); |
|
||||
ASSERT_NO_THROW(matrix.initialize(50)); |
|
||||
double values[100]; |
|
||||
std::vector<double> x; |
|
||||
x.resize(10); |
|
||||
for (uint_fast64_t i = 0; i < 100; ++i) { |
|
||||
if (i % 2 == 0) { |
|
||||
values[i] = i + 1.0; |
|
||||
matrix.addNextValue(i / 10, i % 10, i + 1.0); |
|
||||
} else { |
|
||||
values[i] = 0.0; |
|
||||
} |
|
||||
|
|
||||
if (i < 10) { |
|
||||
x[i] = 1.0; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
ASSERT_NO_THROW(matrix.finalize()); |
|
||||
ASSERT_EQ(matrix.getState(), storm::storage::SparseMatrix<double>::MatrixStatus::ReadReady); |
|
||||
|
|
||||
std::vector<double> result; |
|
||||
result.resize(10); |
|
||||
|
|
||||
matrix.multiplyWithVector(x, result); |
|
||||
|
|
||||
for (uint_fast64_t i = 0; i < 10; ++i) { |
|
||||
double rowSum = 0.0; |
|
||||
for (uint_fast64_t j = 0; j < 10; ++j) { |
|
||||
rowSum += values[10 * i + j]; |
|
||||
} |
|
||||
ASSERT_EQ(rowSum, result.at(i)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
#endif // STORM_USE_TBB
|
|
@ -1,100 +0,0 @@ |
|||||
#include "gtest/gtest.h"
|
|
||||
|
|
||||
#include "Eigen/Sparse"
|
|
||||
#include "src/adapters/EigenAdapter.h"
|
|
||||
#include "src/exceptions/InvalidArgumentException.h"
|
|
||||
#include <cstdint>
|
|
||||
|
|
||||
#define STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE 5
|
|
||||
#define STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE 5
|
|
||||
|
|
||||
TEST(EigenAdapterTest, SimpleDenseSquareCopy) { |
|
||||
// 5 rows
|
|
||||
storm::storage::SparseMatrix<double> sm(STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
|
|
||||
double values[STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE]; |
|
||||
sm.initialize(STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
|
|
||||
int row = 0; |
|
||||
int col = 0; |
|
||||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|
||||
values[i] = static_cast<double>(i + 1); |
|
||||
|
|
||||
sm.addNextValue(row, col, values[i]); |
|
||||
++col; |
|
||||
if (col == STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
sm.finalize(); |
|
||||
|
|
||||
auto esm = storm::adapters::EigenAdapter::toEigenSparseMatrix(sm); |
|
||||
|
|
||||
ASSERT_EQ(esm->rows(), STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(esm->cols(), STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(esm->nonZeros(), STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
|
|
||||
row = 0; |
|
||||
col = 0; |
|
||||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|
||||
ASSERT_EQ(values[i], esm->coeff(row, col)); |
|
||||
++col; |
|
||||
if (col == STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
delete esm; |
|
||||
} |
|
||||
|
|
||||
TEST(EigenAdapterTest, SimpleSparseSquareCopy) { |
|
||||
// 5 rows
|
|
||||
storm::storage::SparseMatrix<double> sm(STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
|
|
||||
double values[STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE]; |
|
||||
sm.initialize((STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|
||||
|
|
||||
int row = 0; |
|
||||
int col = 0; |
|
||||
|
|
||||
bool everySecondElement = true; |
|
||||
|
|
||||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|
||||
values[i] = static_cast<double>(i + 1); |
|
||||
if (everySecondElement) { |
|
||||
sm.addNextValue(row, col, values[i]); |
|
||||
} |
|
||||
everySecondElement = !everySecondElement; |
|
||||
++col; |
|
||||
if (col == STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
sm.finalize(); |
|
||||
|
|
||||
auto esm = storm::adapters::EigenAdapter::toEigenSparseMatrix(sm); |
|
||||
|
|
||||
ASSERT_EQ(esm->rows(), STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(esm->cols(), STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(esm->nonZeros(), (STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|
||||
|
|
||||
row = 0; |
|
||||
col = 0; |
|
||||
everySecondElement = true; |
|
||||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|
||||
if (everySecondElement) { |
|
||||
ASSERT_EQ(values[i], esm->coeff(row, col)); |
|
||||
} |
|
||||
everySecondElement = !everySecondElement; |
|
||||
++col; |
|
||||
if (col == STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
delete esm; |
|
||||
} |
|
@ -1,111 +0,0 @@ |
|||||
#include "gtest/gtest.h"
|
|
||||
|
|
||||
#include "gmm/gmm_matrix.h"
|
|
||||
#include "src/adapters/GmmxxAdapter.h"
|
|
||||
#include "src/exceptions/InvalidArgumentException.h"
|
|
||||
#include <cstdint>
|
|
||||
|
|
||||
#define STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE 5
|
|
||||
#define STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE 5
|
|
||||
|
|
||||
double getValue(gmm::csr_matrix<double> const& gmmSparseMatrix, uint_fast64_t row, uint_fast64_t col) { |
|
||||
uint_fast64_t rowStart = gmmSparseMatrix.jc.at(row); |
|
||||
uint_fast64_t rowEnd = gmmSparseMatrix.jc.at(row + 1); |
|
||||
while (rowStart < rowEnd) { |
|
||||
if (gmmSparseMatrix.ir.at(rowStart) == col) { |
|
||||
return gmmSparseMatrix.pr.at(rowStart); |
|
||||
} |
|
||||
if (gmmSparseMatrix.ir.at(rowStart) > col) { |
|
||||
break; |
|
||||
} |
|
||||
++rowStart; |
|
||||
} |
|
||||
|
|
||||
return 0.0; |
|
||||
} |
|
||||
|
|
||||
TEST(GmmAdapterTest, SimpleDenseSquareCopy) { |
|
||||
// 5 rows
|
|
||||
storm::storage::SparseMatrix<double> sm(STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
|
|
||||
double values[STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE]; |
|
||||
sm.initialize(STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
|
|
||||
int row = 0; |
|
||||
int col = 0; |
|
||||
for (int i = 0; i < STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|
||||
values[i] = static_cast<double>(i + 1); |
|
||||
|
|
||||
sm.addNextValue(row, col, values[i]); |
|
||||
++col; |
|
||||
if (col == STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
sm.finalize(); |
|
||||
|
|
||||
auto gsm = storm::adapters::GmmxxAdapter::toGmmxxSparseMatrix(sm); |
|
||||
|
|
||||
ASSERT_EQ(gsm->nrows(), STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(gsm->ncols(), STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(gmm::nnz(*gsm), STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
row = 0; |
|
||||
col = 0; |
|
||||
for (int i = 0; i < STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|
||||
ASSERT_EQ(values[i], getValue(*gsm, row, col)); |
|
||||
++col; |
|
||||
if (col == STORM_GMMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
TEST(GmmAdapterTest, SimpleSparseSquareCopy) { |
|
||||
// 5 rows
|
|
||||
storm::storage::SparseMatrix<double> sm(STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
|
|
||||
double values[STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE]; |
|
||||
sm.initialize((STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|
||||
|
|
||||
int row = 0; |
|
||||
int col = 0; |
|
||||
|
|
||||
bool everySecondElement = true; |
|
||||
|
|
||||
for (int i = 0; i < STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|
||||
values[i] = static_cast<double>(i + 1); |
|
||||
if (everySecondElement) { |
|
||||
sm.addNextValue(row, col, values[i]); |
|
||||
} |
|
||||
everySecondElement = !everySecondElement; |
|
||||
++col; |
|
||||
if (col == STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
sm.finalize(); |
|
||||
|
|
||||
auto gsm = storm::adapters::GmmxxAdapter::toGmmxxSparseMatrix(sm); |
|
||||
|
|
||||
ASSERT_EQ(gsm->nrows(), STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(gsm->ncols(), STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(gmm::nnz(*gsm), (STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|
||||
|
|
||||
row = 0; |
|
||||
col = 0; |
|
||||
everySecondElement = true; |
|
||||
for (int i = 0; i < STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|
||||
if (everySecondElement) { |
|
||||
ASSERT_EQ(values[i], getValue(*gsm, row, col)); |
|
||||
} |
|
||||
everySecondElement = !everySecondElement; |
|
||||
++col; |
|
||||
if (col == STORM_GMMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,104 +0,0 @@ |
|||||
#include "gtest/gtest.h"
|
|
||||
|
|
||||
#include "gmm/gmm_matrix.h"
|
|
||||
#include "src/adapters/StormAdapter.h"
|
|
||||
#include "src/exceptions/InvalidArgumentException.h"
|
|
||||
#include <cstdint>
|
|
||||
|
|
||||
#define STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE 5
|
|
||||
#define STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE 5
|
|
||||
|
|
||||
TEST(StormAdapterTest, SimpleDenseSquareCopy) { |
|
||||
// 5 rows
|
|
||||
gmm::csr_matrix<double> gmmSparseMatrix; |
|
||||
|
|
||||
/*
|
|
||||
* As CSR_Matrix is read-only we have to prepare the data in this row_matrix and then do a copy. |
|
||||
*/ |
|
||||
gmm::row_matrix<gmm::wsvector<double>> gmmPreMatrix(STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE, STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
|
|
||||
double values[STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE]; |
|
||||
|
|
||||
int row = 0; |
|
||||
int col = 0; |
|
||||
for (int i = 0; i < STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|
||||
values[i] = static_cast<double>(i + 1); |
|
||||
|
|
||||
gmmPreMatrix(row, col) = values[i]; |
|
||||
++col; |
|
||||
if (col == STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
gmm::copy(gmmPreMatrix, gmmSparseMatrix); |
|
||||
|
|
||||
auto stormSparseMatrix = storm::adapters::StormAdapter::toStormSparseMatrix(gmmSparseMatrix); |
|
||||
|
|
||||
ASSERT_EQ(stormSparseMatrix->getRowCount(), STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(stormSparseMatrix->getColumnCount(), STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(stormSparseMatrix->getNonZeroEntryCount(), STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|
||||
row = 0; |
|
||||
col = 0; |
|
||||
for (int i = 0; i < STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|
||||
ASSERT_EQ(values[i], stormSparseMatrix->getValue(row, col)); |
|
||||
++col; |
|
||||
if (col == STORM_STORMADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
TEST(StormAdapterTest, SimpleSparseSquareCopy) { |
|
||||
// 5 rows
|
|
||||
gmm::csr_matrix<double> gmmSparseMatrix; |
|
||||
|
|
||||
/*
|
|
||||
* As CSR_Matrix is read-only we have to prepare the data in this row_matrix and then do a copy. |
|
||||
*/ |
|
||||
gmm::row_matrix<gmm::wsvector<double>> gmmPreMatrix(STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE, STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
|
|
||||
double values[STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE]; |
|
||||
|
|
||||
int row = 0; |
|
||||
int col = 0; |
|
||||
|
|
||||
bool everySecondElement = true; |
|
||||
|
|
||||
for (int i = 0; i < STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|
||||
values[i] = static_cast<double>(i + 1); |
|
||||
if (everySecondElement) { |
|
||||
gmmPreMatrix(row, col) = values[i]; |
|
||||
} |
|
||||
everySecondElement = !everySecondElement; |
|
||||
++col; |
|
||||
if (col == STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
gmm::copy(gmmPreMatrix, gmmSparseMatrix); |
|
||||
|
|
||||
auto stormSparseMatrix = storm::adapters::StormAdapter::toStormSparseMatrix(gmmSparseMatrix); |
|
||||
|
|
||||
ASSERT_EQ(stormSparseMatrix->getRowCount(), STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(stormSparseMatrix->getColumnCount(), STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|
||||
ASSERT_EQ(stormSparseMatrix->getNonZeroEntryCount(), (STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|
||||
|
|
||||
|
|
||||
row = 0; |
|
||||
col = 0; |
|
||||
everySecondElement = true; |
|
||||
for (int i = 0; i < STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|
||||
if (everySecondElement) { |
|
||||
ASSERT_EQ(values[i], stormSparseMatrix->getValue(row, col)); |
|
||||
} |
|
||||
everySecondElement = !everySecondElement; |
|
||||
++col; |
|
||||
if (col == STORM_STORMADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|
||||
++row; |
|
||||
col = 0; |
|
||||
} |
|
||||
} |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue