-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
285 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "MatrixInterface.h" | ||
|
||
// 纯虚析构函数必须保留一个类外实现,因为子类在析构的时候会调用父类的析构函数,如果不定义会编译报错 | ||
MatrixInterface::~MatrixInterface() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __MATRIX_INTERFACE__ | ||
#define __MATRIX_INTERFACE__ | ||
|
||
class MatrixInterface | ||
{ | ||
public: | ||
virtual void setNum(int row, int col, double value) = 0; | ||
virtual ~MatrixInterface() = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef __MATRIX_WRAPPER__ | ||
#define __MATRIX_WRAPPER__ | ||
|
||
#include <iostream> | ||
#include <Eigen/Sparse> | ||
#include "MatrixInterface.h" | ||
|
||
using Eigen::MatrixXd; | ||
using Eigen::SparseMatrix; | ||
|
||
class DenseMatrixWrapper : public MatrixInterface | ||
{ | ||
private: | ||
MatrixXd m_dense_matrix; | ||
public: | ||
DenseMatrixWrapper(int row, int col) : m_dense_matrix(row, col) { } | ||
|
||
void setNum(int row, int col, double value) | ||
{ | ||
m_dense_matrix(row, col) = value; | ||
} | ||
|
||
MatrixXd& getMatrix() | ||
{ | ||
return m_dense_matrix; | ||
} | ||
}; | ||
|
||
class SparseMatrixWrapper : public MatrixInterface | ||
{ | ||
private: | ||
SparseMatrix<double> m_sparse_matrix; | ||
public: | ||
SparseMatrixWrapper(int row, int col) : m_sparse_matrix(row, col) { } | ||
|
||
void setNum(int row, int col, double value) | ||
{ | ||
// ref. http://eigen.tuxfamily.org/dox/group__TutorialSparse.html - Filling a sparse matrix | ||
m_sparse_matrix.insert(row, col) = value; // alternative: A.coeffRef(i,j) += v_ij; | ||
} | ||
|
||
SparseMatrix<double>& getMatrix() | ||
{ | ||
return m_sparse_matrix; | ||
} | ||
}; | ||
|
||
#endif |
Oops, something went wrong.