Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
itpp
base
algebra
cholesky.cpp
Go to the documentation of this file.
1
29
#ifndef _MSC_VER
30
# include <itpp/config.h>
31
#else
32
# include <itpp/config_msvc.h>
33
#endif
34
35
#if defined(HAVE_LAPACK)
36
# include <itpp/base/algebra/lapack.h>
37
#endif
38
39
#include <
itpp/base/algebra/cholesky.h
>
40
41
42
namespace
itpp
43
{
44
45
#if defined(HAVE_LAPACK)
46
47
bool
chol
(
const
mat &X, mat &F)
48
{
49
50
char
uplo =
'U'
;
51
int
n, lda, info;
52
n = lda = X.rows();
53
54
F = X;
// input matrix is overwritten
55
56
dpotrf_(&uplo, &n, F._data(), &lda, &info);
57
58
// Set lower part to zero
59
for
(
int
i = 0; i < n; i++)
60
for
(
int
j = i + 1; j < n; j++)
61
F(j, i) = 0;
62
63
return
(info == 0);
64
}
65
66
bool
chol
(
const
cmat &X, cmat &F)
67
{
68
char
uplo =
'U'
;
69
int
n, lda, info;
70
n = lda = X.rows();
71
72
F = X;
// input matrix is overwritten
73
74
zpotrf_(&uplo, &n, F._data(), &lda, &info);
75
76
// Set lower part to zero
77
for
(
int
i = 0; i < n; i++)
78
for
(
int
j = i + 1; j < n; j++)
79
F(j, i) = 0;
80
81
return
(info == 0);
82
}
83
84
#else // HAVE_LAPACK
85
86
bool
chol
(
const
mat &X, mat &F)
87
{
88
it_error
(
"LAPACK library is needed to use chol() function"
);
89
return
false
;
90
}
91
92
bool
chol
(
const
cmat &X, cmat &F)
93
{
94
95
it_error
(
"LAPACK library is needed to use chol() function"
);
96
return
false
;
97
}
98
99
#endif // HAVE_LAPACK
100
101
cmat
chol
(
const
cmat &X)
102
{
103
cmat F;
104
if
(!
chol
(X, F)) {
105
it_warning
(
"cholesky factorization didn't succeed"
);
106
}
107
108
return
F;
109
}
110
111
mat
chol
(
const
mat &X)
112
{
113
mat F;
114
if
(!
chol
(X, F)) {
115
it_warning
(
"cholesky factorization didn't succeed"
);
116
}
117
118
return
F;
119
}
120
121
}
// namespace itpp
Generated on Fri Mar 21 2014 17:14:12 for IT++ by
Doxygen
1.8.1.2