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