Browse Source

Edited src/sparse/static_sparse_matrix.h to include a conversion routine for Eigen

tempestpy_adaptions
PBerger 12 years ago
parent
commit
344b586a72
  1. 3
      src/parser/read_lab_file.cpp
  2. 28
      src/sparse/static_sparse_matrix.h

3
src/parser/read_lab_file.cpp

@ -25,6 +25,9 @@
# define STRTOK_FUNC strtok_r
#endif
// Disable C4996 - This function or variable may be unsafe.
#pragma warning(disable:4996)
namespace mrmc {

28
src/sparse/static_sparse_matrix.h

@ -12,6 +12,8 @@
#include "src/exceptions/invalid_argument.h"
#include "src/exceptions/out_of_range.h"
#include "Eigen/Sparse"
namespace mrmc {
namespace sparse {
@ -192,6 +194,32 @@ class StaticSparseMatrix {
return value_storage;
}
Eigen::SparseMatrix<T> toEigenSparseMatrix() {
typedef Eigen::Triplet<double> ETd;
std::vector<ETd> tripletList;
triplets.reserve(non_zero_entry_count + row_count);
uint_fast32_t row_start;
uint_fast32_t row_end;
for (uint_fast32_t row = 1; row <= row_count; ++row) {
row_start = row_indications[row - 1];
row_end = row_indications[row];
while (row_start < row_end) {
tripletList.push_back(ETd(row - 1, column_indications[row_start] - 1, value_storage[row_start]));
++row_start;
}
}
for (uint_fast32_t i = 1; i <= row_count; ++i) {
tripletList .push_back(ETd(i, i, diagonal_storage[i]));
}
SparseMatrixType mat(row_count, row_count);
mat.setFromTriplets(tripletList.begin(), tripletList.end());
mat.makeCompressed();
return mat;
}
private:
uint_fast32_t storage_size;
uint_fast32_t current_size;

Loading…
Cancel
Save