-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_case_cholesky_lapack.h
88 lines (63 loc) · 2.31 KB
/
test_case_cholesky_lapack.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
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef __TEST_CASE_CHOLESKY_LAPACK_H__
#define __TEST_CASE_CHOLESKY_LAPACK_H__
#include <Accelerate/Accelerate.h>
#include "test_case_cholesky.h"
template<class T, bool IS_COL_MAJOR>
class TestCaseCholesky_lapack : public TestCaseCholesky<T, IS_COL_MAJOR> {
T* m_lapA;
T* m_lapbx;
public:
TestCaseCholesky_lapack( const int dim )
:TestCaseCholesky<T, IS_COL_MAJOR>( dim )
,m_lapA ( new T[ dim * dim ] )
,m_lapbx( new T[ dim ] )
{
static_assert( std::is_same< float,T >::value || std::is_same< double,T >::value );
this->setImplementationType( LAPACK );
}
virtual ~TestCaseCholesky_lapack() {
delete[] m_lapA;
delete[] m_lapbx;
}
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_lapA[ i * this->m_dim + j ] = val;
if ( i != j ) {
m_lapA[ j * this->m_dim + i ] = val;
}
}
m_lapbx[ i ] = 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_lapbx[i];
for ( int j = 0; j <= i; j++ ) {
this->m_L[ lower_mat_index<IS_COL_MAJOR>( i, j, this->m_dim ) ] = m_lapA[ i + (this->m_dim * j) ];
}
}
TestCaseCholesky<T,IS_COL_MAJOR>::compareTruth( L_baseline, x_baseline );
}
void run() {
char uplo[2] = "L";
int n = this->m_dim;
int nrhs = 1;
int lda = this->m_dim;
int ldb = this->m_dim;
int info;
int r;
if constexpr ( std::is_same< float,T >::value ) {
r = sposv_( uplo, &n, &nrhs, m_lapA, &lda, m_lapbx, &ldb, &info );
}
else {
r = dposv_( uplo, &n, &nrhs, m_lapA, &lda, m_lapbx, &ldb, &info );
}
if ( r != 0 ) {
std::cerr << "sposv returned non zeror:" << r << " info:" << info << "\n";
}
}
};
#endif /*__TEST_CASE_CHOLESKY_LAPACK_H__*/