Browse Source

Performed renaming of static_sparse_matrix.h to SquareSparseMatrix.h, renamed the class accordingly and adapted the tests and includes.

tempestpy_adaptions
dehnert 12 years ago
parent
commit
8806dc6592
  1. 4
      src/models/backward_transitions.h
  2. 8
      src/models/dtmc.h
  3. 4
      src/mrmc.cpp
  4. 6
      src/parser/read_tra_file.cpp
  5. 4
      src/parser/read_tra_file.h
  6. 40
      src/storage/SquareSparseMatrix.h
  7. 17
      src/utility/utility.cpp
  8. 4
      test/parser/read_tra_file_test.cpp
  9. 0
      test/storage/BitVectorTest.cpp
  10. 102
      test/storage/SquareSparseMatrixTest.cpp

4
src/models/backward_transitions.h

@ -9,7 +9,7 @@
#define BACKWARD_TRANSITIONS_H_
#include <iostream>
#include "src/sparse/static_sparse_matrix.h"
#include "src/storage/SquareSparseMatrix.h"
namespace mrmc {
@ -35,7 +35,7 @@ public:
* @param transition_matrix The (0-based) matrix representing the transition
* relation.
*/
BackwardTransitions(mrmc::sparse::StaticSparseMatrix<T>* transitionMatrix) {
BackwardTransitions(mrmc::sparse::SquareSparseMatrix<T>* transitionMatrix) {
numberOfNonZeroTransitions = transitionMatrix->getNonZeroEntryCount();
this->predecessor_list = new uint_fast64_t[numberOfNonZeroTransitions];

8
src/models/dtmc.h

@ -12,7 +12,7 @@
#include "atomic_propositions_labeling.h"
#include "backward_transitions.h"
#include "src/sparse/static_sparse_matrix.h"
#include "src/storage/SquareSparseMatrix.h"
namespace mrmc {
@ -35,7 +35,7 @@ public:
* @param state_labeling The labeling that assigns a set of atomic
* propositions to each state.
*/
Dtmc(mrmc::sparse::StaticSparseMatrix<T>* probability_matrix, mrmc::models::AtomicPropositionsLabeling* state_labeling)
Dtmc(mrmc::sparse::SquareSparseMatrix<T>* probability_matrix, mrmc::models::AtomicPropositionsLabeling* state_labeling)
: backward_transitions(probability_matrix) {
this->probability_matrix = probability_matrix;
this->state_labeling = state_labeling;
@ -84,7 +84,7 @@ public:
* @return A pointer to the matrix representing the transition probability
* function.
*/
mrmc::sparse::StaticSparseMatrix<T>* getTransitionProbabilityMatrix() {
mrmc::sparse::SquareSparseMatrix<T>* getTransitionProbabilityMatrix() {
return this->probability_matrix;
}
@ -111,7 +111,7 @@ public:
private:
/*! A matrix representing the transition probability function of the DTMC. */
mrmc::sparse::StaticSparseMatrix<T>* probability_matrix;
mrmc::sparse::SquareSparseMatrix<T>* probability_matrix;
/*! The labeling of the states of the DTMC. */
mrmc::models::AtomicPropositionsLabeling* state_labeling;

4
src/mrmc.cpp

@ -17,7 +17,7 @@
#include "mrmc-config.h"
#include "src/models/dtmc.h"
#include "src/sparse/static_sparse_matrix.h"
#include "src/storage/SquareSparseMatrix.h"
#include "src/models/atomic_propositions_labeling.h"
#include "src/parser/read_lab_file.h"
#include "src/parser/read_tra_file.h"
@ -77,7 +77,7 @@ int main(const int argc, const char* argv[]) {
return 0;
}
mrmc::sparse::StaticSparseMatrix<double>* probMatrix = mrmc::parser::read_tra_file(s->getString("trafile").c_str());
mrmc::sparse::SquareSparseMatrix<double>* probMatrix = mrmc::parser::read_tra_file(s->getString("trafile").c_str());
mrmc::models::AtomicPropositionsLabeling* labeling = mrmc::parser::read_lab_file(probMatrix->getRowCount(), s->getString("labfile").c_str());
mrmc::models::Dtmc<double> dtmc(probMatrix, labeling);

6
src/parser/read_tra_file.cpp

@ -90,12 +90,12 @@ static uint_fast32_t make_first_pass(FILE* p) {
* @return a pointer to the created sparse matrix.
*/
sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
sparse::SquareSparseMatrix<double> * read_tra_file(const char * filename) {
FILE *p = NULL;
char s[BUFFER_SIZE];
uint_fast64_t non_zero = 0;
int rows = 0;
sparse::StaticSparseMatrix<double> *sp = NULL;
sparse::SquareSparseMatrix<double> *sp = NULL;
p = fopen(filename, "r");
if(p == NULL) {
@ -129,7 +129,7 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
* Memory for diagonal elements is automatically allocated, hence only the number of non-diagonal
* non-zero elements has to be specified (which is non_zero, computed by make_first_pass)
*/
sp = new sparse::StaticSparseMatrix<double>(static_cast<uint_fast64_t>(rows) + 1);
sp = new sparse::SquareSparseMatrix<double>(static_cast<uint_fast64_t>(rows) + 1);
if ( NULL == sp ) {
throw std::bad_alloc();
return NULL;

4
src/parser/read_tra_file.h

@ -7,11 +7,11 @@
#ifndef READ_TRA_FILE_H_
#define READ_TRA_FILE_H_
#include "src/sparse/static_sparse_matrix.h"
#include "src/storage/SquareSparseMatrix.h"
namespace mrmc{
namespace parser {
mrmc::sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename);
mrmc::sparse::SquareSparseMatrix<double> * read_tra_file(const char * filename);
}
}

40
src/sparse/static_sparse_matrix.h → src/storage/SquareSparseMatrix.h

@ -29,7 +29,7 @@ namespace sparse {
* where rows is the first argument to the constructor.
*/
template<class T>
class StaticSparseMatrix {
class SquareSparseMatrix {
public:
/*!
@ -56,24 +56,24 @@ public:
* Constructs a sparse matrix object with the given number of rows.
* @param rows The number of rows of the matrix
*/
StaticSparseMatrix(uint_fast64_t rows)
: rowCount(rows), nonZeroEntryCount(0), valueStorage(nullptr), diagonalStorage(nullptr), columnIndications(nullptr), rowIndications(nullptr), internalStatus(MatrixStatus::UnInitialized), currentSize(0), lastRow(0) { }
SquareSparseMatrix(uint_fast64_t rows)
: rowCount(rows), nonZeroEntryCount(0), valueStorage(nullptr),
diagonalStorage(nullptr),columnIndications(nullptr), rowIndications(nullptr),
internalStatus(MatrixStatus::UnInitialized), currentSize(0), lastRow(0) { }
//! Copy Constructor
/*!
* Copy Constructor. Performs a deep copy of the given sparse matrix.
* @param ssm A reference to the matrix to be copied.
*/
StaticSparseMatrix(const StaticSparseMatrix<T> &ssm)
: internalStatus(ssm.internalStatus),
currentSize(ssm.currentSize), lastRow(ssm.lastRow),
rowCount(ssm.rowCount),
nonZeroEntryCount(ssm.nonZeroEntryCount) {
SquareSparseMatrix(const SquareSparseMatrix<T> &ssm)
: internalStatus(ssm.internalStatus), currentSize(ssm.currentSize), lastRow(ssm.lastRow),
rowCount(ssm.rowCount), nonZeroEntryCount(ssm.nonZeroEntryCount) {
LOG4CPLUS_WARN(logger, "Invoking copy constructor.");
// Check whether copying the matrix is safe.
if (!ssm.hasError()) {
LOG4CPLUS_ERROR(logger, "Trying to copy sparse matrix in error state.");
throw mrmc::exceptions::invalid_argument();
throw mrmc::exceptions::invalid_argument("Trying to copy sparse matrix in error state.");
} else {
// Try to prepare the internal storage and throw an error in case
// of a failure.
@ -107,7 +107,7 @@ public:
/*!
* Destructor. Performs deletion of the reserved storage arrays.
*/
~StaticSparseMatrix() {
~SquareSparseMatrix() {
setState(MatrixStatus::UnInitialized);
if (valueStorage != NULL) {
//free(value_storage);
@ -141,15 +141,15 @@ public:
if (internalStatus != MatrixStatus::UnInitialized) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to initialize matrix that is not uninitialized.");
throw mrmc::exceptions::invalid_state("StaticSparseMatrix::initialize: Invalid state for status flag != 0 - Already initialized?");
throw mrmc::exceptions::invalid_state("Trying to initialize matrix that is not uninitialized.");
} else if (rowCount == 0) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to create initialize a matrix with 0 rows.");
throw mrmc::exceptions::invalid_argument("mrmc::StaticSparseMatrix::initialize: Matrix with 0 rows is not reasonable");
throw mrmc::exceptions::invalid_argument("Trying to create initialize a matrix with 0 rows.");
} else if (((rowCount * rowCount) - rowCount) < nonZeroEntries) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to initialize a matrix with more non-zero entries than there can be.");
throw mrmc::exceptions::invalid_argument("mrmc::StaticSparseMatrix::initialize: More non-zero entries than entries in target matrix");
throw mrmc::exceptions::invalid_argument("Trying to initialize a matrix with more non-zero entries than there can be.");
} else {
// If it is safe, initialize necessary members and prepare the
// internal storage.
@ -180,7 +180,7 @@ public:
if (!eigenSparseMatrix.isCompressed()) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to initialize from an Eigen matrix that is not in compressed form.");
throw mrmc::exceptions::invalid_argument("StaticSparseMatrix::initialize: Throwing invalid_argument: eigen_sparse_matrix is not in Compressed form.");
throw mrmc::exceptions::invalid_argument("Trying to initialize from an Eigen matrix that is not in compressed form.");
}
// Compute the actual (i.e. non-diagonal) number of non-zero entries.
@ -273,7 +273,7 @@ public:
if ((row > rowCount) || (col > rowCount)) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to add a value at illegal position (" << row << ", " << col << ").");
throw mrmc::exceptions::out_of_range("StaticSparseMatrix::addNextValue: row or col not in 0 .. rows");
throw mrmc::exceptions::out_of_range("Trying to add a value at illegal position.");
}
if (row == col) { // Set a diagonal element.
@ -306,11 +306,11 @@ public:
if (!isInitialized()) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to finalize an uninitialized matrix.");
throw mrmc::exceptions::invalid_state("StaticSparseMatrix::finalize: Invalid state for internal state not Initialized - Already finalized?");
throw mrmc::exceptions::invalid_state("Trying to finalize an uninitialized matrix.");
} else if (currentSize != nonZeroEntryCount) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to finalize a matrix that was initialized with more non-zero entries than given.");
throw mrmc::exceptions::invalid_state("StaticSparseMatrix::finalize: Wrong call count for addNextValue");
throw mrmc::exceptions::invalid_state("Trying to finalize a matrix that was initialized with more non-zero entries than given.");
} else {
// Fill in the missing entries in the row_indications array.
// (Can happen because of empty rows at the end.)
@ -344,7 +344,7 @@ public:
// Check for illegal access indices.
if ((row > rowCount) || (col > rowCount)) {
LOG4CPLUS_ERROR(logger, "Trying to read a value from illegal position (" << row << ", " << col << ").");
throw mrmc::exceptions::out_of_range("StaticSparseMatrix::getValue: row or col not in 0 .. rows");
throw mrmc::exceptions::out_of_range("Trying to read a value from illegal position.");
return false;
}
@ -468,7 +468,7 @@ public:
if (!isReadReady()) {
triggerErrorState();
LOG4CPLUS_ERROR(logger, "Trying to convert a matrix that is not in a readable state to an Eigen matrix.");
throw mrmc::exceptions::invalid_state("StaticSparseMatrix::toEigenSparseMatrix: Invalid state for internal state not ReadReady.");
throw mrmc::exceptions::invalid_state("Trying to convert a matrix that is not in a readable state to an Eigen matrix.");
} else {
// Create a
int_fast32_t eigenRows = static_cast<int_fast32_t>(rowCount);
@ -574,7 +574,7 @@ public:
// Check whether the accessed state exists.
if (row > rowCount) {
LOG4CPLUS_ERROR(logger, "Trying to make an illegal row " << row << " absorbing.");
throw mrmc::exceptions::out_of_range("StaticSparseMatrix::makeStateFinal: state not in 0 .. rows");
throw mrmc::exceptions::out_of_range("Trying to make an illegal row absorbing.");
return false;
}

17
src/utility/utility.cpp

@ -9,10 +9,6 @@
#include "src/parser/read_tra_file.h"
#include "src/parser/read_lab_file.h"
#include "src/sparse/static_sparse_matrix.h"
#include "src/models/dtmc.h"
#include "src/models/atomic_propositions_labeling.h"
namespace mrmc {
namespace utility {
@ -77,19 +73,6 @@ void dtmcToDot(mrmc::models::Dtmc<double>* dtmc, const char* filename) {
fclose(P); */
}
mrmc::models::Dtmc<double>* parseDTMC(const char* tra_file, const char* lab_file) {
mrmc::sparse::StaticSparseMatrix<double>* transition_matrix =
mrmc::parser::read_tra_file(tra_file);
uint_fast64_t node_count = transition_matrix->getRowCount();
mrmc::models::AtomicPropositionsLabeling* labeling =
mrmc::parser::read_lab_file(node_count, lab_file);
mrmc::models::Dtmc<double>* result =
new mrmc::models::Dtmc<double>(transition_matrix, labeling);
return result;
}
}
}

4
test/parser/read_tra_file_test.cpp

@ -7,7 +7,7 @@
#include "gtest/gtest.h"
#include "mrmc-config.h"
#include "src/sparse/static_sparse_matrix.h"
#include "src/storage/SquareSparseMatrix.h"
#include "src/parser/read_tra_file.h"
#include "src/exceptions/file_IO_exception.h"
#include "src/exceptions/wrong_file_format.h"
@ -20,7 +20,7 @@ TEST(ReadTraFileTest, NonExistingFileTest) {
/* The following test case is based on one of the original MRMC test cases
*/
TEST(ReadTraFileTest, ParseFileTest1) {
mrmc::sparse::StaticSparseMatrix<double> *result = NULL;
mrmc::sparse::SquareSparseMatrix<double> *result = NULL;
ASSERT_NO_THROW(result = mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/csl_general_input_01.tra"));
if (result != NULL) {

0
test/vector/bitvector_test.cpp → test/storage/BitVectorTest.cpp

102
test/sparse/static_sparse_matrix_test.cpp → test/storage/SquareSparseMatrixTest.cpp

@ -1,72 +1,72 @@
#include "gtest/gtest.h"
#include "src/sparse/static_sparse_matrix.h"
#include "src/storage/SquareSparseMatrix.h"
#include "src/exceptions/invalid_argument.h"
TEST(StaticSparseMatrixTest, ZeroRowsTest) {
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(0);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
TEST(SquareSparseMatrixTest, ZeroRowsTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(0);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_THROW(ssm->initialize(50), mrmc::exceptions::invalid_argument);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm;
}
TEST(StaticSparseMatrixTest, TooManyEntriesTest) {
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(2);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
TEST(SquareSparseMatrixTest, TooManyEntriesTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(2);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_THROW(ssm->initialize(10), mrmc::exceptions::invalid_argument);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm;
}
TEST(StaticSparseMatrixTest, addNextValueTest) {
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
TEST(SquareSparseMatrixTest, addNextValueTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_NO_THROW(ssm->initialize(1));
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_THROW(ssm->addNextValue(-1, 1, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_THROW(ssm->addNextValue(1, -1, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_THROW(ssm->addNextValue(6, 1, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
ASSERT_THROW(ssm->addNextValue(1, 6, 1), mrmc::exceptions::out_of_range);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm;
}
TEST(StaticSparseMatrixTest, finalizeTest) {
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
TEST(SquareSparseMatrixTest, finalizeTest) {
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(5);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
ASSERT_NO_THROW(ssm->initialize(5));
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<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(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_THROW(ssm->finalize(), mrmc::exceptions::invalid_state);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Error);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Error);
delete ssm;
}
TEST(StaticSparseMatrixTest, Test) {
TEST(SquareSparseMatrixTest, Test) {
// 25 rows, 50 non zero entries
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(25);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(25);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
int values[50] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
@ -95,15 +95,15 @@ TEST(StaticSparseMatrixTest, Test) {
};
ASSERT_NO_THROW(ssm->initialize(50));
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<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(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target;
for (int i = 0; i < 50; ++i) {
@ -124,15 +124,15 @@ TEST(StaticSparseMatrixTest, Test) {
ASSERT_EQ(0, target);
}
}
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
delete ssm;
}
TEST(StaticSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) {
TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest) {
// 10 rows, 100 non zero entries
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int> esm(10, 10);
for (int row = 0; row < 10; ++row) {
@ -148,7 +148,7 @@ TEST(StaticSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest)
ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1;
for (int row = 0; row < 10; ++row) {
@ -159,10 +159,10 @@ TEST(StaticSparseMatrixTest, ConversionFromDenseEigen_ColMajor_SparseMatrixTest)
}
}
TEST(StaticSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) {
TEST(SquareSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest) {
// 10 rows, 100 non zero entries
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10);
for (int row = 0; row < 10; ++row) {
@ -178,7 +178,7 @@ TEST(StaticSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest)
ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1;
for (int row = 0; row < 10; ++row) {
@ -189,10 +189,10 @@ TEST(StaticSparseMatrixTest, ConversionFromDenseEigen_RowMajor_SparseMatrixTest)
}
}
TEST(StaticSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest) {
TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest) {
// 10 rows, 15 non zero entries
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int> esm(10, 10);
@ -226,7 +226,7 @@ TEST(StaticSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest
ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1;
@ -236,10 +236,10 @@ TEST(StaticSparseMatrixTest, ConversionFromSparseEigen_ColMajor_SparseMatrixTest
}
}
TEST(StaticSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest) {
TEST(SquareSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest) {
// 10 rows, 15 non zero entries
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::UnInitialized);
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::UnInitialized);
Eigen::SparseMatrix<int, Eigen::RowMajor> esm(10, 10);
@ -273,7 +273,7 @@ TEST(StaticSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest
ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
int target = -1;
@ -283,26 +283,26 @@ TEST(StaticSparseMatrixTest, ConversionFromSparseEigen_RowMajor_SparseMatrixTest
}
}
TEST(StaticSparseMatrixTest, ConversionToSparseEigen_RowMajor_SparseMatrixTest) {
TEST(SquareSparseMatrixTest, ConversionToSparseEigen_RowMajor_SparseMatrixTest) {
int values[100];
mrmc::sparse::StaticSparseMatrix<int> *ssm = new mrmc::sparse::StaticSparseMatrix<int>(10);
mrmc::sparse::SquareSparseMatrix<int> *ssm = new mrmc::sparse::SquareSparseMatrix<int>(10);
for (uint_fast32_t i = 0; i < 100; ++i) {
values[i] = i;
}
ASSERT_NO_THROW(ssm->initialize(100 - 10));
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<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(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::Initialized);
ASSERT_NO_THROW(ssm->finalize());
ASSERT_EQ(ssm->getState(), mrmc::sparse::StaticSparseMatrix<int>::MatrixStatus::ReadReady);
ASSERT_EQ(ssm->getState(), mrmc::sparse::SquareSparseMatrix<int>::MatrixStatus::ReadReady);
Eigen::SparseMatrix<int, Eigen::RowMajor, int_fast32_t>* esm = ssm->toEigenSparseMatrix();
Loading…
Cancel
Save