From 344b586a728d1aebb739aba932e38ae270aefd40 Mon Sep 17 00:00:00 2001 From: PBerger Date: Mon, 17 Sep 2012 18:49:23 +0200 Subject: [PATCH] Edited src/sparse/static_sparse_matrix.h to include a conversion routine for Eigen --- src/parser/read_lab_file.cpp | 3 +++ src/sparse/static_sparse_matrix.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) 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;