00001 // This is core/vnl/algo/vnl_matrix_inverse.h 00002 #ifndef vnl_matrix_inverse_h_ 00003 #define vnl_matrix_inverse_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Calculates inverse of a matrix (wrapper around vnl_svd<double>) 00010 // \author Andrew W. Fitzgibbon, Oxford RRG 00011 // \date 22 Nov 96 00012 // 00013 // \verbatim 00014 // Modifications 00015 // dac (Manchester) 28/03/2001: tidied up documentation 00016 // \endverbatim 00017 00018 #include <vnl/algo/vnl_svd.h> 00019 00020 //: Calculates inverse of a matrix (wrapper around vnl_svd<double>) 00021 // vnl_matrix_inverse is a wrapper around vnl_svd<double> that allows 00022 // you to write 00023 // \code 00024 // x = vnl_matrix_inverse<double>(A) * b; 00025 // \endcode 00026 // This is exactly equivalent to 00027 // \code 00028 // x = vnl_svd<double>(A).solve(b); 00029 // \endcode 00030 // but is arguably clearer, and also allows for the vnl_matrix_inverse 00031 // class to be changed to use vnl_qr, say. 00032 00033 template <class T> 00034 struct vnl_matrix_inverse : public vnl_svd<T> 00035 { 00036 vnl_matrix_inverse(vnl_matrix<T> const & M): vnl_svd<T>(M) { } 00037 ~vnl_matrix_inverse() {} 00038 00039 operator vnl_matrix<T> () const { return this->inverse(); } 00040 }; 00041 00042 template <class T> 00043 inline 00044 vnl_vector<T> operator*(vnl_matrix_inverse<T> const & i, 00045 vnl_vector<T> const & B) 00046 { 00047 return i.solve(B); 00048 } 00049 00050 template <class T> 00051 inline 00052 vnl_matrix<T> operator*(vnl_matrix_inverse<T> const & i, 00053 vnl_matrix<T> const & B) 00054 { 00055 return i.solve(B); 00056 } 00057 00058 #endif // vnl_matrix_inverse_h_