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

Generated on Wed Jul 27 2011 16:27:04 for IT++ by Doxygen 1.7.4