IT++ Logo

inv.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/inv.h>
00041 
00042 
00043 namespace itpp
00044 {
00045 
00046 #if defined(HAVE_LAPACK)
00047 
00048 bool inv(const mat &X, mat &Y)
00049 {
00050   it_assert_debug(X.rows() == X.cols(), "inv: matrix is not square");
00051 
00052   int m = X.rows(), info, lwork;
00053   lwork = m; // may be choosen better
00054 
00055   ivec p(m);
00056   Y = X;
00057   vec work(lwork);
00058 
00059   dgetrf_(&m, &m, Y._data(), &m, p._data(), &info); // LU-factorization
00060   if (info != 0)
00061     return false;
00062 
00063   dgetri_(&m, Y._data(), &m, p._data(), work._data(), &lwork, &info);
00064   return (info == 0);
00065 }
00066 
00067 bool inv(const cmat &X, cmat &Y)
00068 {
00069   it_assert_debug(X.rows() == X.cols(), "inv: matrix is not square");
00070 
00071   int m = X.rows(), info, lwork;
00072   lwork = m; // may be choosen better
00073 
00074   ivec p(m);
00075   Y = X;
00076   cvec work(lwork);
00077 
00078   zgetrf_(&m, &m, Y._data(), &m, p._data(), &info); // LU-factorization
00079   if (info != 0)
00080     return false;
00081 
00082   zgetri_(&m, Y._data(), &m, p._data(), work._data(), &lwork, &info);
00083   return (info == 0);
00084 }
00085 
00086 #else
00087 
00088 bool inv(const mat &X, mat &Y)
00089 {
00090   it_error("LAPACK library is needed to use inv() function");
00091   return false;
00092 }
00093 
00094 bool inv(const cmat &X, cmat &Y)
00095 {
00096   it_error("LAPACK library is needed to use inv() function");
00097   return false;
00098 }
00099 
00100 #endif // HAVE_LAPACK
00101 
00102 cmat inv(const cmat &X)
00103 {
00104   cmat Y;
00105   inv(X, Y);
00106   return Y;
00107 }
00108 
00109 
00110 mat inv(const mat &X)
00111 {
00112   mat Y;
00113   inv(X, Y);
00114   return Y;
00115 }
00116 
00117 } // namespace itpp
SourceForge Logo

Generated on Sun Jul 26 08:36:49 2009 for IT++ by Doxygen 1.5.9