synaps/linalg/Svd.h

Go to the documentation of this file.
00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS kernel.        *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************
00005 History: 
00006 $Id: Svd.h,v 1.1 2005/07/11 08:33:34 mourrain Exp $
00007 **********************************************************************/
00008 #ifndef SYNAPS_LINALG_SVD_H
00009 #define SYNAPS_LINALG_SVD_H
00010 #include <synaps/init.h>
00011 #include <synaps/linalg/VectDse.h>
00012 #include <synaps/linalg/MATRIX.m>
00013 //--------------------------------------------------------------------
00014 __BEGIN_NAMESPACE_SYNAPS
00015 //====================================================================
00019 //--------------------------------------------------------------------
00021 template <class M> inline 
00022 VectDse<typename realof<typename M::value_type>::T> Svd(M & A)
00023 {
00024   using namespace MATRIX;
00025   typedef VectDse<typename realof<typename M::value_type>::T> VT;
00026   VT x(std::min(A.nbcol(),A.nbrow()));
00027   svd(x.rep(),A.rep());  
00028   return x;
00029 }
00030 //--------------------------------------------------------------------
00032 template <class M> inline 
00033 VectDse<typename realof<typename M::value_type>::T> Svd(M & A, M & U)
00034 {
00035   typedef VectDse<typename realof<typename M::value_type>::T> VT;
00036   unsigned int l = std::min(A.nbcol(),A.nbrow());
00037   VT x(l);
00038   U.rep().resize(A.nbrow(),A.nbrow());
00039   using namespace MATRIX;  svd(x.rep(),A.rep(), U.rep());
00040   return x;
00041 }
00042 //--------------------------------------------------------------------
00046 template <class M> inline
00047 VectDse<typename realof<typename M::value_type>::T> Svd(M & A, M & U, M & V)
00048 {
00049   typedef VectDse<typename realof<typename M::value_type>::T> VT;
00050   unsigned int  m = std::max(A.nbcol(),A.nbrow());
00051   VT x(m);
00052   U.rep().resize(A.nbrow(),A.nbrow());
00053   V.rep().resize(A.nbcol(),A.nbcol());
00054   using namespace MATRIX; svd(x.rep(),A.rep(), U.rep(), V.rep());
00055   return x;
00056 }
00057 
00058 //--------------------------------------------------------------------
00063 template <class M> inline 
00064 VectDse<typename realof<typename M::value_type>::T> Svdx(M & A, M & U, M & V)
00065 {
00066   typedef VectDse<realof<typename M::value_type> > VT;
00067   unsigned int l = std::max(A.nbcol(),A.nbrow());
00068   VT x(l);
00069   U.rep().resize(A.nbrow(),A.nbrow());
00070   V.rep().resize(A.nbcol(),A.nbcol());
00071    using namespace MATRIX; svdx(x.rep(), A.rep(), U.rep(), V.rep());
00072   return x;
00073 }
00074 
00075 //----------------------------------------------------------------------
00079 template <class M> 
00080 inline typename M::value_type Cond(M & A)
00081 {
00082   typedef typename linalg::rep1d<typename realof<typename M::value_type>::T> VT;
00083   unsigned int l = std::min(A.nbcol(),A.nbrow());
00084   VT S(l);
00085   using namespace MATRIX;  svd(S,A.rep());
00086   return (S[0]/S[l-1]);
00087 }
00088 //====================================================================
00089 __END_NAMESPACE_SYNAPS
00090 //--------------------------------------------------------------------
00091 #endif // SYNAPS_LINALG_SVD_H
00092 
00093 

SYNAPS DOCUMENTATION
logo