fn_svd.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup fn_svd
00017 //! @{
00018 
00019 
00020 
00021 template<typename T1>
00022 inline
00023 bool
00024 svd(Col<typename T1::pod_type>& S, const Base<typename T1::elem_type,T1>& X)
00025   {
00026   arma_extra_debug_sigprint();
00027 
00028   typedef typename T1::elem_type eT;
00029   
00030   // unwrap_check not used as T1::elem_type and T1::pod_type may not be the same.
00031   // furthermore, it doesn't matter if A is an alias of S, as auxlib::svd() makes a copy of A
00032   
00033   const unwrap<T1> tmp(X.get_ref());
00034   const Mat<eT>& A = tmp.M;
00035   
00036   const bool status = auxlib::svd(S, A);
00037     
00038   if(status == false)
00039     {
00040     arma_print("svd(): singular value decomposition failed");
00041     }
00042   
00043   return status;
00044   }
00045 
00046 
00047 
00048 template<typename T1>
00049 inline
00050 Col<typename T1::pod_type>
00051 svd(const Base<typename T1::elem_type,T1>& X)
00052   {
00053   arma_extra_debug_sigprint();
00054   
00055   Col<typename T1::pod_type> out;
00056   svd(out, X);
00057   
00058   return out;
00059   }
00060 
00061 
00062 
00063 template<typename T1>
00064 inline
00065 bool
00066 svd
00067   (
00068   Mat<typename T1::elem_type>& U,
00069   Col<typename T1::pod_type>& S,
00070   Mat<typename T1::elem_type>& V,
00071   const Base<typename T1::elem_type,T1>& X
00072   )
00073   {
00074   arma_extra_debug_sigprint();
00075   
00076   typedef typename T1::elem_type eT;
00077   
00078   const unwrap<T1> tmp(X.get_ref());
00079   const Mat<eT>& A = tmp.M;
00080   
00081   const bool status = auxlib::svd(U, S, V, A);
00082     
00083   if(status == false)
00084     {
00085     arma_print("svd(): singular value decomposition failed");
00086     }
00087   
00088   return status;
00089   }
00090 
00091 
00092 
00093 //! @}