IT++ Logo
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
40
41
42namespace itpp
43{
44
45#if defined(HAVE_LAPACK)
46
47bool 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
66bool 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
86bool chol(const mat &X, mat &F)
87{
88 it_error("LAPACK library is needed to use chol() function");
89 return false;
90}
91
92bool 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
101cmat 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
111mat 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
Definitions of Cholesky factorisation functions.
#define it_error(s)
Abort unconditionally.
Definition itassert.h:126
#define it_warning(s)
Display a warning message.
Definition itassert.h:173
bool chol(const mat &X, mat &F)
Cholesky factorisation of real symmetric and positive definite matrix.
Definition cholesky.cpp:86
itpp namespace
Definition itmex.h:37

Generated on Tue Mar 26 2024 19:08:31 for IT++ by Doxygen 1.9.8