Changeset 2558 in Sophya for trunk/SophyaProg/Tests/tsttminv.cc


Ignore:
Timestamp:
Jul 22, 2004, 3:38:05 PM (21 years ago)
Author:
cmv
Message:

add test of svd decomposition (cmv 22/07/04)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/tsttminv.cc

    r2557 r2558  
    2626#define ALSO_LAPACK_EV
    2727#define ALSO_LAPACK_EV_SYM
     28#define ALSO_LAPACK_SVD
    2829
    2930//////////////////////////////////////////////////
     
    7980void Hermitian(TMatrix< TYPE >& A);
    8081r_8  Check_Mat_Ident(TMatrix< TYPE >& A);
     82r_8  Check_Mat_Zero(TMatrix< TYPE >& A);
    8183r_8  Check_Mat_VecCol_0(TMatrix< TYPE >& A);
    8284void  Check_Mat_VecCol_2(TMatrix< complex<TYPER> >& A);
     
    271273cout<<"Compute AiA = A * InvA"<<endl;
    272274TMatrix< TYPE > AiA(N,N); AiA = Ainput * InvA;
    273 cout<<"------------ TMatrix AiA = A * InvA:"<<endl;
    274275if(nprline>0) {cout<<AiA; cout<<endl;}
    275276//-- Check
     
    321322cout<<"Compute AiA = A * InvA"<<endl;
    322323TMatrix< TYPE > AiA(N,N); AiA = Ainput * InvA;
    323 cout<<"------------ TMatrix AiA = A * InvA:"<<endl;
    324324if(nprline>0) {cout<<AiA; cout<<endl;}
    325325//-- Check
     
    426426
    427427
     428////////////////////////////////////////////////
     429///////////// Test avec Lapack SVD /////////////
     430////////////////////////////////////////////////
     431#if defined(USE_LAPACK) && defined(ALSO_LAPACK_SVD)
     432{
     433cout<<"\n=========================================="<<endl;
     434cout<<"------------ SVD decompositon LapackSVD "<<endl;
     435A=Ainput;
     436TVector< TYPE > S(N,N); TMatrix< TYPE > U(N,N); TMatrix< TYPE > VT(N,N);
     437//-- Decompositon
     438int_4 info = LapackSVD(A,S,U,VT);
     439cout<<"info="<<info<<endl;
     440PrtTim("--- End of LapackSVD decompositon ---");
     441if(nprline>0) {cout<<S; cout<<endl;}
     442double smax = ABS_VAL(S(0)), smin = ABS_VAL(S(N-1));
     443cout<<" Smin = |"<<S(N-1)<<"| = "<<smin<<", "
     444    <<" Smax = |"<<S(0)<<"| = "<<smax<<", "
     445    <<" --> Smin/Smax = "<<smin/smax<<endl;
     446//-- A = U*S*VT
     447cout<<"Compute A = U*S*VT"<<endl;
     448TMatrix< TYPE > AmUSVt(N,N); AmUSVt = U;
     449for(int i=0;i<N;i++) for(int j=0;j<N;j++) AmUSVt(i,j) *= S(j);
     450AmUSVt *= VT; AmUSVt -= Ainput;
     451if(nprline>0) {cout<<AmUSVt; cout<<endl;}
     452//-- Check
     453Check_Mat_Zero(AmUSVt);
     454PrtTim("--- End of LapackSVD Test ---");
     455}
     456#endif
     457
     458
    428459///////////////////////////////////////////////
    429460///////// Test Inversion avec GausPiv /////////
     
    493524 cout<<"Ecart maximum par rapport a 0 hors diagonale = "<<vmaxh<<endl;
    494525 return (vmaxd>vmaxh)? vmaxd: vmaxh;
     526}
     527
     528////-------------------------------------------------------
     529r_8  Check_Mat_Zero(TMatrix< TYPE >& A)
     530// Compute the biggest difference element by element of A / Zero matrix
     531{
     532 int_4 N = A.NRows();
     533 r_8 vmax = -1.;
     534 for(int i=0;i<N;i++) for(int j=0;j<N;j++)
     535   if( ABS_VAL(A(i,j)) > vmax ) vmax = ABS_VAL(A(i,j));
     536 cout<<"Ecart maximum par rapport a zero = "<<vmax<<endl;
     537 return vmax;
    495538}
    496539
Note: See TracChangeset for help on using the changeset viewer.