IT++ Logo Newcom Logo

inv.cpp

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

Generated on Sat Aug 25 23:40:02 2007 for IT++ by Doxygen 1.5.2