Changeset 2566 in Sophya for trunk/SophyaProg/Tests


Ignore:
Timestamp:
Jul 27, 2004, 9:58:18 AM (21 years ago)
Author:
cmv
Message:

add test inversion with LeastSquareSVD_DC cmv 27/7/04

File:
1 edited

Legend:

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

    r2562 r2566  
    2424#define ALSO_LAPACK_INV_SYM
    2525#define ALSO_LAPACK_INV_LSS
     26#define ALSO_LAPACK_INV_LSS_SVD
    2627#define ALSO_LAPACK_EV
    2728#define ALSO_LAPACK_EV_SYM
     
    264265{
    265266cout<<"\n=========================================="<<endl;
    266 cout<<"------------ Inversion LAPACK"<<endl;
     267cout<<"------------ Inversion LAPACK (LU factorization)"<<endl;
    267268A = Ainput;
    268269//-- Inversion
     
    288289{
    289290cout<<"\n=========================================="<<endl;
    290 cout<<"------------ Inversion LAPACK sym"<<endl;
     291cout<<"------------ Inversion LAPACK symetric (LU factorization)"<<endl;
    291292TMatrix< TYPE > Asym(N,N); Asym=Ainput; Symetrize(Asym); A=Asym;
    292293//-- Inversion
     
    313314{
    314315cout<<"\n=========================================="<<endl;
    315 cout<<"------------ Inversion LAPACK LeastSquare"<<endl;
     316cout<<"------------ Inversion LAPACK LeastSquare (QR or LQ factorization)"<<endl;
    316317A = Ainput;
    317318//-- Inversion
     
    327328Check_Mat_Ident(AiA);
    328329PrtTim("--- End of LapackLeastSquareSolve Test ---");
     330}
     331#endif
     332
     333
     334////////////////////////////////////////////////
     335///////// Test avec Lapack LeastSquare /////////
     336////////////////////////////////////////////////
     337#if defined(USE_LAPACK) && defined(ALSO_LAPACK_INV_LSS_SVD)
     338{
     339cout<<"\n=========================================="<<endl;
     340cout<<"------------ Inversion LAPACK LeastSquare (SVD decomposition)"<<endl;
     341A = Ainput;
     342//-- Inversion
     343TMatrix< TYPE > InvA(N,N); InvA = IdentityMatrix(1.,N);
     344TVector<r_8> S;
     345int_4 rank;
     346r_8 rcond = -1.;
     347int_4 info = LapackLeastSquareSolveSVD_DC(A,InvA,S,rank,rcond);
     348cout<<"info="<<info<<"  (rank="<<rank<<")"<<endl;
     349PrtTim("--- End of LapackLeastSquareSolveSVD_DC Inversion ---");
     350if(nprline>0) {cout<<S; cout<<endl;}
     351double smax = fabs(S(0)), smin = fabs(S(S.Size()-1));
     352cout<<" Smin = |"<<S(S.Size()-1)<<"| = "<<smin<<", "
     353    <<" Smax = |"<<S(0)<<"| = "<<smax<<", "
     354    <<" --> Smin/Smax = "<<smin/smax<<endl;
     355//-- AiA = A * InvA
     356cout<<"Compute AiA = A * InvA"<<endl;
     357TMatrix< TYPE > AiA(N,N); AiA = Ainput * InvA;
     358if(nprline>0) {cout<<AiA; cout<<endl;}
     359//-- Check
     360Check_Mat_Ident(AiA);
     361PrtTim("--- End of LapackLeastSquareSolveSVD_DC Test ---");
    329362}
    330363#endif
     
    466499cout<<"------------ SVD decompositon LapackSVD_DC "<<endl;
    467500A=Ainput;
    468 TVector< TYPE > S; TMatrix< TYPE > U; TMatrix< TYPE > VT;
     501TVector< r_8 > S; TMatrix< TYPE > U; TMatrix< TYPE > VT;
    469502//-- Decompositon
    470503int_4 info = LapackSVD_DC(A,S,U,VT);
     
    472505PrtTim("--- End of LapackSVD_DC decompositon ---");
    473506if(nprline>0) {cout<<S; cout<<endl;}
    474 double smax = ABS_VAL(S(0)), smin = ABS_VAL(S(N-1));
     507double smax = fabs(S(0)), smin = fabs(S(N-1));
    475508cout<<" Smin = |"<<S(N-1)<<"| = "<<smin<<", "
    476509    <<" Smax = |"<<S(0)<<"| = "<<smax<<", "
     
    479512cout<<"Compute A = U*S*VT"<<endl;
    480513TMatrix< TYPE > AmUSVt(N,N); AmUSVt = U;
    481 for(int i=0;i<N;i++) for(int j=0;j<N;j++) AmUSVt(i,j) *= S(j);
     514for(int i=0;i<N;i++) for(int j=0;j<N;j++) AmUSVt(i,j) *= (TYPE) S(j);
    482515AmUSVt *= VT; AmUSVt -= Ainput;
    483516if(nprline>0) {cout<<AmUSVt; cout<<endl;}
Note: See TracChangeset for help on using the changeset viewer.