IT++ Logo

cholesky.cpp

Go to the documentation of this file.
00001 
00030 #ifndef _MSC_VER
00031 #  include <itpp/config.h>
00032 #else
00033 #  include <itpp/config_msvc.h>
00034 #endif
00035 
00036 #if defined(HAVE_LAPACK)
00037 #  include <itpp/base/algebra/lapack.h>
00038 #endif
00039 
00040 #include <itpp/base/algebra/cholesky.h>
00041 
00042 
00043 namespace itpp
00044 {
00045 
00046 #if defined(HAVE_LAPACK)
00047 
00048 bool chol(const mat &X, mat &F)
00049 {
00050 
00051   char uplo = 'U';
00052   int n, lda, info;
00053   n = lda = X.rows();
00054 
00055   F = X; // input matrix is overwritten
00056 
00057   dpotrf_(&uplo, &n, F._data(), &lda, &info);
00058 
00059   // Set lower part to zero
00060   for (int i = 0; i < n; i++)
00061     for (int j = i + 1; j < n; j++)
00062       F(j, i) = 0;
00063 
00064   return (info == 0);
00065 }
00066 
00067 bool chol(const cmat &X, cmat &F)
00068 {
00069   char uplo = 'U';
00070   int n, lda, info;
00071   n = lda = X.rows();
00072 
00073   F = X; // input matrix is overwritten
00074 
00075   zpotrf_(&uplo, &n, F._data(), &lda, &info);
00076 
00077   // Set lower part to zero
00078   for (int i = 0; i < n; i++)
00079     for (int j = i + 1; j < n; j++)
00080       F(j, i) = 0;
00081 
00082   return (info == 0);
00083 }
00084 
00085 #else // HAVE_LAPACK
00086 
00087 bool chol(const mat &X, mat &F)
00088 {
00089   it_error("LAPACK library is needed to use chol() function");
00090   return false;
00091 }
00092 
00093 bool chol(const cmat &X, cmat &F)
00094 {
00095 
00096   it_error("LAPACK library is needed to use chol() function");
00097   return false;
00098 }
00099 
00100 #endif // HAVE_LAPACK
00101 
00102 cmat chol(const cmat &X)
00103 {
00104   cmat F;
00105   if (!chol(X, F)) {
00106     it_warning("cholesky factorization didn't succeed");
00107   }
00108 
00109   return F;
00110 }
00111 
00112 mat chol(const mat &X)
00113 {
00114   mat F;
00115   if (!chol(X, F)) {
00116     it_warning("cholesky factorization didn't succeed");
00117   }
00118 
00119   return F;
00120 }
00121 
00122 } // namespace itpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Wed Mar 2 2011 22:04:50 for IT++ by Doxygen 1.7.3