cholesky.cpp
Go to the documentation of this file.
#ifndef _MSC_VER
# include <itpp/config.h>
#else
# include <itpp/config_msvc.h>
#endif
#if defined(HAVE_LAPACK)
# include <itpp/base/algebra/lapack.h>
#endif
#include <itpp/base/algebra/cholesky.h>
namespace itpp
{
#if defined(HAVE_LAPACK)
bool chol(const mat &X, mat &F)
{
char uplo = 'U';
int n, lda, info;
n = lda = X.rows();
F = X; // input matrix is overwritten
dpotrf_(&uplo, &n, F._data(), &lda, &info);
// Set lower part to zero
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
F(j, i) = 0;
return (info == 0);
}
bool chol(const cmat &X, cmat &F)
{
char uplo = 'U';
int n, lda, info;
n = lda = X.rows();
F = X; // input matrix is overwritten
zpotrf_(&uplo, &n, F._data(), &lda, &info);
// Set lower part to zero
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
F(j, i) = 0;
return (info == 0);
}
#else // HAVE_LAPACK
bool chol(const mat &X, mat &F)
{
it_error("LAPACK library is needed to use chol() function");
return false;
}
bool chol(const cmat &X, cmat &F)
{
it_error("LAPACK library is needed to use chol() function");
return false;
}
#endif // HAVE_LAPACK
cmat chol(const cmat &X)
{
cmat F;
if (!chol(X, F)) {
it_warning("cholesky factorization didn't succeed");
}
return F;
}
mat chol(const mat &X)
{
mat F;
if (!chol(X, F)) {
it_warning("cholesky factorization didn't succeed");
}
return F;
}
} // namespace itpp
cholesky.h
Definitions of Cholesky factorisation functions.
it_error
#define it_error(s)
Abort unconditionally.
Definition itassert.h:126
it_warning
#define it_warning(s)
Display a warning message.
Definition itassert.h:173
itpp::chol
bool chol(const mat &X, mat &F)
Cholesky factorisation of real symmetric and positive definite matrix.
Definition cholesky.cpp:86
itpp
itpp namespace
Definition itmex.h:37

Generated on Mon Jun 10 2024 11:49:16 for IT++ by Doxygen 1.9.8