-
Notifications
You must be signed in to change notification settings - Fork 9
/
MatrixWrapper.h
69 lines (56 loc) · 1.5 KB
/
MatrixWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef __MATRIX_WRAPPER_H__
#define __MATRIX_WRAPPER_H__
#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() = default;
DenseMatrixWrapper(int row, int col)
{
m_dense_matrix = MatrixXd::Zero(row, col);
}
void setNum(int row, int col, double value)
{
m_dense_matrix(row, col) = value;
}
MatrixXd& getMatrix()
{
return m_dense_matrix;
}
DenseMatrixWrapper& operator=(DenseMatrixWrapper&& rhs)
{
if(this != &rhs)
m_dense_matrix = std::move(rhs.m_dense_matrix);
return *this;
}
};
class SparseMatrixWrapper : public MatrixInterface
{
private:
SparseMatrix<double> m_sparse_matrix;
public:
SparseMatrixWrapper() = default;
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;
}
SparseMatrixWrapper& operator=(SparseMatrixWrapper&& rhs)
{
if(this != &rhs)
m_sparse_matrix = std::move(rhs.m_sparse_matrix);
return *this;
}
};
#endif