diff --git a/src/parser/read_lab_file.cpp b/src/parser/read_lab_file.cpp index 0d89b3935..1e180fab5 100644 --- a/src/parser/read_lab_file.cpp +++ b/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 { diff --git a/src/sparse/static_sparse_matrix.h b/src/sparse/static_sparse_matrix.h index 9fd7cd389..83a46872a 100644 --- a/src/sparse/static_sparse_matrix.h +++ b/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 toEigenSparseMatrix() { + typedef Eigen::Triplet ETd; + std::vector 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;