-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_case_cholesky_eigen3.h
75 lines (50 loc) · 1.96 KB
/
test_case_cholesky_eigen3.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
70
71
72
73
74
75
#ifndef __TEST_CASE_CHOLESKY_EIGEN3_H__
#define __TEST_CASE_CHOLESKY_EIGEN3_H__
#include "test_case_cholesky.h"
#include <Eigen/Cholesky>
template<class T, bool IS_COL_MAJOR>
class TestCaseCholesky_eigen3 : public TestCaseCholesky<T, IS_COL_MAJOR> {
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> m_eA;
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> m_eL;
Eigen::Matrix<T, Eigen::Dynamic, 1> m_ex;
Eigen::Matrix<T, Eigen::Dynamic, 1> m_eb;
public:
TestCaseCholesky_eigen3( const int dim )
:TestCaseCholesky<T, IS_COL_MAJOR>( dim )
{
m_eA.resize( dim, dim );
m_eL.resize( dim, dim );
m_ex.resize( dim, 1 );
m_eb.resize( dim, 1 );
this->setImplementationType(EIGEN3 );
}
virtual ~TestCaseCholesky_eigen3(){;}
virtual void setInitialStates( T* A, T* b ) {
for ( int i = 0; i < this->m_dim; i++ ) {
for ( int j = 0; j <= i; j++ ) {
const T val = A[ lower_mat_index<IS_COL_MAJOR>( i, j, this->m_dim ) ];
m_eA( i, j ) = val;
if ( i != j ) {
m_eA( j, i ) = val;
}
}
m_eb( i, 0 ) = b[i];
}
TestCaseCholesky<T,IS_COL_MAJOR>::setInitialStates( A, b );
}
virtual void compareTruth( const T* const L_baseline, const T* const x_baseline ) {
for ( int i = 0; i < this->m_dim; i++ ) {
this->m_x[i] = m_ex(i);
for ( int j = 0; j <= i; j++ ) {
this->m_L[ lower_mat_index<IS_COL_MAJOR>( i, j, this->m_dim ) ] = m_eL( i, j );
}
}
return TestCaseCholesky<T,IS_COL_MAJOR>::compareTruth( L_baseline, x_baseline );
}
void run() {
Eigen::LLT< Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> , Eigen::Lower > llt( m_eA );
m_eL = llt.matrixL();
m_ex = llt.solve( m_eb );
}
};
#endif /*__TEST_CASE_CHOLESKY_EIGEN3_H__*/