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
00026   (
00027   Col<typename T1::pod_type>& S,
00028   const Base<typename T1::elem_type,T1>& X,
00029   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00030   )
00031   {
00032   arma_extra_debug_sigprint();
00033 
00034   typedef typename T1::elem_type eT;
00035   
00036   // unwrap_check not used as T1::elem_type and T1::pod_type may not be the same.
00037   // furthermore, it doesn't matter if A is an alias of S, as auxlib::svd() makes a copy of A
00038   
00039   const unwrap<T1> tmp(X.get_ref());
00040   const Mat<eT>& A = tmp.M;
00041   
00042   const bool status = auxlib::svd(S, A);
00043     
00044   if(status == false)
00045     {
00046     arma_print("svd(): singular value decomposition failed");
00047     }
00048   
00049   return status;
00050   }
00051 
00052 
00053 
00054 template<typename T1>
00055 inline
00056 Col<typename T1::pod_type>
00057 svd
00058   (
00059   const Base<typename T1::elem_type,T1>& X,
00060   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00061   )
00062   {
00063   arma_extra_debug_sigprint();
00064   
00065   Col<typename T1::pod_type> out;
00066   
00067   const bool status = svd(out, X);
00068   
00069   if(status == false)
00070     {
00071     out.set_size(0);
00072     }
00073   
00074   return out;
00075   }
00076 
00077 
00078 
00079 template<typename T1>
00080 inline
00081 bool
00082 svd
00083   (
00084          Mat<typename T1::elem_type>&    U,
00085          Col<typename T1::pod_type>&     S,
00086          Mat<typename T1::elem_type>&    V,
00087   const Base<typename T1::elem_type,T1>& X,
00088   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00089   )
00090   {
00091   arma_extra_debug_sigprint();
00092   
00093   typedef typename T1::elem_type eT;
00094   
00095   arma_debug_check( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svd(): two or more output objects are the same object" );
00096   
00097   const unwrap<T1>   tmp(X.get_ref());
00098   const Mat<eT>& A = tmp.M;
00099   
00100   // auxlib::svd() makes an internal copy of A
00101   const bool status = auxlib::svd(U, S, V, A);
00102   
00103   if(status == false)
00104     {
00105     arma_print("svd(): singular value decomposition failed");
00106     }
00107   
00108   return status;
00109   }
00110 
00111 
00112 
00113 //! @}