fn_svd.hpp

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