source: Sophya/trunk/SophyaProg/Tests/tsttminv.cc@ 2558

Last change on this file since 2558 was 2558, checked in by cmv, 21 years ago

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

File size: 19.2 KB
RevLine 
[2555]1// Test de l'inversion de matrices et valeurs propres (avec Lapack) (cmv 21/07/04)
2// cmvtminv -a 1234 -l 0 -s 1 -b 25,10000 -n 50 -S
[995]3
[2555]4///////////////////////////////////////////////////
5///////////////////////////////////////////////////
6// PARTIE POUVANT ETRE CHANGEE PAR L'UTILISATEUR //
7///////////////////////////////////////////////////
8///////////////////////////////////////////////////
9
10// --- Choix de travailler avec des matrices complexes ?
[995]11//#define COMPLEX
12
[2555]13//////////////////////////////////////////////////
14// --- Choix de travailler en simple precision ?
15//#define PRECIS32
16
17//////////////////////////////////////////////////
18// --- Choix GausPiv + Lapack ?
19#define USE_GAUSPIV
20#define USE_LAPACK
21
22// --- Choix de ce que doit faire Lapack
23#define ALSO_LAPACK_INV
24#define ALSO_LAPACK_INV_SYM
25#define ALSO_LAPACK_INV_LSS
26#define ALSO_LAPACK_EV
27#define ALSO_LAPACK_EV_SYM
[2558]28#define ALSO_LAPACK_SVD
[2555]29
30//////////////////////////////////////////////////
31//////////////////////////////////////////////////
32// NE RIEN CHANGER CI-APRES //
33//////////////////////////////////////////////////
34//////////////////////////////////////////////////
35
36//////////////////////////////////////////////////
[934]37#include "machdefs.h"
[2322]38#include <iostream>
[934]39#include <stdlib.h>
40#include <stdio.h>
41#include <string.h>
42#include <math.h>
43#include <unistd.h>
[1008]44#include "timing.h"
[934]45#include "ntoolsinit.h"
46#include "pexceptions.h"
47#include "array.h"
48#include "srandgen.h"
[2555]49#if defined(USE_LAPACK)
[995]50#include "intflapack.h"
51#endif
[934]52
[2555]53//////////////////////////////////////////////////
[934]54#if defined(COMPLEX)
[975]55 #if defined(PRECIS32)
56 #define TYPE complex<r_4>
[2555]57 #define TYPER r_4
[975]58 #else
59 #define TYPE complex<r_8>
[2555]60 #define TYPER r_8
[975]61 #endif
[2555]62 #define REAL_PART(_x_) (TYPE((_x_).real(),0.))
63 #define CONJ_VAL(_x_) (TYPE((_x_).real(),-(_x_).imag()))
64 #define ABS_VAL(_x_) sqrt((double)((_x_).real()*(_x_).real() + (_x_).imag()*(_x_).imag()))
[934]65#else
[975]66 #if defined(PRECIS32)
67 #define TYPE r_4
[2555]68 #define TYPER r_4
[975]69 #else
70 #define TYPE r_8
[2555]71 #define TYPER r_8
[975]72 #endif
[2555]73 #define REAL_PART(_x_) (_x_)
74 #define CONJ_VAL(_x_) (_x_)
75 #define ABS_VAL(_x_) fabs((double)_x_)
[934]76#endif
77
[2555]78//////////////////////////////////////////////////
79void Symetrize(TMatrix< TYPE >& A);
80void Hermitian(TMatrix< TYPE >& A);
81r_8 Check_Mat_Ident(TMatrix< TYPE >& A);
[2558]82r_8 Check_Mat_Zero(TMatrix< TYPE >& A);
[2555]83r_8 Check_Mat_VecCol_0(TMatrix< TYPE >& A);
84void Check_Mat_VecCol_2(TMatrix< complex<TYPER> >& A);
85#if defined(USE_LAPACK)
86/*
87-- Pour faire ce test il faut passer la methode ilaenv_en_C()
88 de LapackServer en methode "public" (dans intflapack.h)
89 et recompiler la librairie externe sophya
90*/
91// void TestIlaEnv(int_4 n);
92#endif
93
94
95//////////////////////////////////////////////////
[934]96int main(int narg,char *arg[])
97{
98//--------------------------------------------------------
[2555]99//-- Initialisation
100//--------------------------------------------------------
[934]101// number of lines/columns
[975]102uint_4 N = 5;
[934]103// scale of the value (if =1 values between -1 and 1)
104r_8 scale = 1.;
105// number of values change by +/- vbig
[975]106uint_4 nbig = N;
[2555]107r_8 vbig = 100.;
[975]108// Nombre de lignes de matrice a imprimer
[2555]109uint_4 nprline = N;
[975]110// Initialisation du pauvre de l'aleatoire
[1008]111uint_4 nalea = 0;
112// data scaling for gauss pivoting and determinant
113int tscal = 1;
114bool detok=false;
[2555]115// Please symetrize the input matrice
116bool symetok=false;
117// Please symetrize the input matrice
118bool gaussok=false;
119
[934]120//--------------------------------------------------------
121//-- Decodage arguments
[2555]122//--------------------------------------------------------
[934]123char c;
[2555]124while((c = getopt(narg,arg,"Sdgn:s:b:l:a:t:h")) != -1) {
[934]125 switch (c) {
[2555]126 case 'S' :
127 symetok = true;
[934]128 break;
[2555]129 case 'd' :
130 detok = true;
131 break;
132 case 'g' :
133 gaussok = true;
134 break;
135 case 'n' :
136 sscanf(optarg,"%d",&N);
137 break;
138 case 's' :
139 sscanf(optarg,"%lf",&scale);
140 break;
141 case 'b' :
142 sscanf(optarg,"%d,%lf",&nbig,&vbig);
143 break;
[934]144 case 'l' :
145 sscanf(optarg,"%d",&nprline);
146 break;
[975]147 case 'a' :
148 sscanf(optarg,"%d",&nalea);
149 break;
[2555]150 case 't' :
[1008]151 sscanf(optarg,"%d",&tscal);
152 break;
[934]153 case 'h' :
[2555]154 cout<<"tsttminv [-h] [-n N] [-S] [-s scale] [-b nbig,vbig] [-g]"<<endl
155 <<" [-l nprline] [-a nalea] [-t tscal] [-d]"<<endl
156 <<"-- matrix A(N,N) filled with {[-1,1] +/- vbig(nbig time)}*scale --"<<endl
157 <<"-g : instead of flat [-1,1] use normal gaussian distribution for A(i,j)"<<endl
158 <<"-S : symetrize the input matrix"<<endl
159 <<"-l : print nprline of input and test matrices"<<endl
160 <<"-a : for random (pseudo) changing"<<endl
161 <<"-- Only GausPiv --"<<endl
162 <<"-t 0/1/2 : data scaling 0=no, 1=global (def), 2=row-by-row"<<endl
[2557]163 <<"-d : also compute determinant (ne pas utiliser si N est grand)"<<endl;
[2555]164 return(-1);
[934]165 }
166}
167if(N<=1) N = 1;
[975]168cout<<"Taille matrice NxN, N = "<<N<<endl;
[2555]169if(gaussok) cout<<"Elements gaussian normal * scale = "<<scale<<endl;
170 else cout<<"Elements entre +/- 1 * scale = "<<scale<<endl;
[975]171cout<<"Nombre de valeurs hors standard nbig = "<<nbig<<endl;
[2555]172cout<<"Valeurs hors standard (+/- vbig = "<<vbig<<" ) * scale = "<<vbig*scale<<endl;
[934]173cout<<"Nombre de lignes de matrice a imprimer "<<nprline<<endl;
[975]174cout<<"Initialisation de l aleatoire par "<<nalea<<" tirages"<<endl;
[2555]175cout<<"Data scaling "<<tscal<<" determinant="<<detok<<endl;
176if(symetok) cout<<"Input matrix has been symetrized "<<symetok<<endl;
[934]177cout<<endl;
178
[2555]179//--------------------------------------------------------
180// TestIlaEnv(N); return -41;
181//--------------------------------------------------------
182
183//--------------------------------------------------------
[934]184//-- Initialization arrays
[2555]185//--------------------------------------------------------
[934]186SophyaInit();
[2555]187InitTim();
188#if defined(USE_LAPACK)
[995]189 BaseArray::SetDefaultMemoryMapping(BaseArray::FortranMemoryMapping);
190#endif
[2555]191if(nalea>0) for(int i=0;i<nalea;i++) drand01();
192BaseArray::SetMaxPrint(nprline*N,0);
[934]193
[2555]194//--------------------------------------------------------
195//-- Definition global arrays
196//--------------------------------------------------------
197TMatrix< TYPE > Ainput(N,N); Ainput = (TYPE) 0;
198TMatrix< TYPE > A(N,N); A = (TYPE) 0;
199Ainput.Show();
[934]200
[2555]201//--------------------------------------------------------
202//-- Fill matrices with flat random
203//--------------------------------------------------------
204if(gaussok) Ainput = RandomSequence(RandomSequence::Gaussian,0.,1.);
205 else Ainput = RandomSequence(RandomSequence::Flat,0.,1.);
206#if defined(COMPLEX)
207if(gaussok) A = RandomSequence(RandomSequence::Gaussian,0.,1.);
208 else A = RandomSequence(RandomSequence::Flat,0.,1.);
209Ainput += TYPE(0.,1.)*A;
210#endif
[1008]211
[2555]212//--------------------------------------------------------
213//-- Fill matrices with big values
214//--------------------------------------------------------
215if(nbig>0) {
216#if defined(COMPLEX)
217 nbig = (nbig+1)/2;
218#endif
219 TMatrix< uint_2 > Vind(N,N); Vind = 0;
220 // for real part
221 uint_4 nbr=0;
222 for(int k=0;k<nbig;k++) {
223 int i = (int) (drand01()*N); int j = (int) (drand01()*N);
224 double s=(drand01()>0.5)?1.:-1.;
225 if(Vind(i,j)==0) {Ainput(i,j) += (TYPER) s*vbig; Vind(i,j)+=1; nbr++;}
226 }
227 cout<<"Nombre de valeurs BIG reelles = "<<nbr<<endl;
228#if defined(COMPLEX)
229 // for imaginary part
230 uint_4 nbi=0;
231 for(int k=0;k<nbig;k++) {
232 int i = (int) (drand01()*N); int j = (int) (drand01()*N);
233 double s=(drand01()>0.5)?1.:-1.;
234 if(Vind(i,j)<=1) {Ainput(i,j) += TYPE(0.,(TYPER)s*vbig); Vind(i,j)+=2; nbi++;}
235 }
236 cout<<"Nombre de valeurs BIG imaginaires = "<<nbi<<endl;
237 cout<<"Nombre de valeurs BIG = "<<nbr+nbi<<endl;
238#endif
239}
[934]240
[2555]241//--------------------------------------------------------
242//-- Scale matrix for machine precision tests
243//--------------------------------------------------------
244Ainput *= (TYPE) scale;
245
246//--------------------------------------------------------
247//-- Create symetric matrix for all A if requested
248//--------------------------------------------------------
249if(symetok) Symetrize(Ainput);
250
251//--------------------------------------------------------
252//-- Print matrice Ainput
253//--------------------------------------------------------
254cout<<"------------ TMatrix Ainput :"<<endl;
255if(nprline>0) {cout<<Ainput; cout<<endl;}
256PrtTim("--- End of Matrix filling ---");
257
258
[2557]259//////////////////////////////////////////////
260///////// Test Inversion avec Lapack /////////
261//////////////////////////////////////////////
262#if defined(USE_LAPACK) && defined(ALSO_LAPACK_INV)
[2555]263{
264cout<<"\n=========================================="<<endl;
265cout<<"------------ Inversion LAPACK"<<endl;
266A = Ainput;
267//-- Inversion
268TMatrix< TYPE > InvA(N,N); InvA = IdentityMatrix(1.,N);
269int_4 info = LapackLinSolve(A,InvA);
270cout<<"info="<<info<<endl;
271PrtTim("--- End of LapackLinSolve Inversion ---");
272//-- AiA = A * InvA
273cout<<"Compute AiA = A * InvA"<<endl;
274TMatrix< TYPE > AiA(N,N); AiA = Ainput * InvA;
275if(nprline>0) {cout<<AiA; cout<<endl;}
276//-- Check
277Check_Mat_Ident(AiA);
278PrtTim("--- End of LapackLinSolve Test ---");
[975]279}
[2555]280#endif
281
282
[2557]283//////////////////////////////////////////////////
284///////// Test Inversion avec Lapack sym /////////
285//////////////////////////////////////////////////
286#if defined(USE_LAPACK) && defined(ALSO_LAPACK_INV_SYM)
[2555]287{
288cout<<"\n=========================================="<<endl;
289cout<<"------------ Inversion LAPACK sym"<<endl;
290TMatrix< TYPE > Asym(N,N); Asym=Ainput; Symetrize(Asym); A=Asym;
291//-- Inversion
292TMatrix< TYPE > InvA(N,N); InvA = IdentityMatrix(1.,N);
293int_4 info = LapackLinSolveSym(A,InvA);
294cout<<"info="<<info<<endl;
295PrtTim("--- End of LapackLinSolveSym Inversion ---");
296//-- AiA = A * InvA
297cout<<"Compute AiA = A * InvA"<<endl;
298TMatrix< TYPE > AiA(N,N); AiA = Asym * InvA;
299cout<<"------------ TMatrix AiA = A * InvA:"<<endl;
300if(nprline>0) {cout<<AiA; cout<<endl;}
301//-- Check
302Check_Mat_Ident(AiA);
303PrtTim("--- End of LapackLinSolveSym Test ---");
[975]304}
[934]305#endif
306
307
[2555]308////////////////////////////////////////////////
309///////// Test avec Lapack LeastSquare /////////
310////////////////////////////////////////////////
[2557]311#if defined(USE_LAPACK) && defined(ALSO_LAPACK_INV_LSS)
[2555]312{
313cout<<"\n=========================================="<<endl;
314cout<<"------------ Inversion LAPACK LeastSquare"<<endl;
315A = Ainput;
[934]316//-- Inversion
[2555]317TMatrix< TYPE > InvA(N,N); InvA = IdentityMatrix(1.,N);
318int_4 info = LapackLeastSquareSolve(A,InvA);
319cout<<"info="<<info<<endl;
320PrtTim("--- End of LapackLeastSquareSolve Inversion ---");
321//-- AiA = A * InvA
322cout<<"Compute AiA = A * InvA"<<endl;
323TMatrix< TYPE > AiA(N,N); AiA = Ainput * InvA;
324if(nprline>0) {cout<<AiA; cout<<endl;}
325//-- Check
326Check_Mat_Ident(AiA);
327PrtTim("--- End of LapackLeastSquareSolve Test ---");
328}
329#endif
330
331
332////////////////////////////////////////////////
333///////// Test avec Lapack pour EV /////////
334////////////////////////////////////////////////
[2557]335#if defined(USE_LAPACK) && defined(ALSO_LAPACK_EV)
[2555]336{
337cout<<"\n=========================================="<<endl;
338cout<<"------------ Eigen decompositon LapackEigen "<<endl;
339A=Ainput;
340TMatrix< TYPE > Evec(N,N); Evec = (TYPE) 0;
341TVector< complex<r_8> > Eval(N); Eval = complex<r_8>(0,0);
342//-- Decompositon
343int_4 info = LapackEigen(A,Eval,Evec,true);
344cout<<"info="<<info<<endl;
345PrtTim("--- End of LapackEigen decompositon ---");
346if(nprline>0) {cout<<Eval; cout<<endl; cout<<Evec; cout<<endl;}
347//-- Find the complex conjugate pairs
[2557]348#if !defined(COMPLEX)
[2555]349TVector< uint_2 > Evalconj(N); Evalconj = 0;
350int_4 nconj=0;
351for(int i=0;i<N-1;i++) {
352 if(Evalconj(i)!=0) continue; // deja traite
353 if(Eval(i).imag()==0.) continue; // real eigenvalue
354 if(fabs(Eval(i).imag()+Eval(i+1).imag())>1e-150) continue; // les 2 consecutives ne sont pas conjuguees
355 if(Eval(i).imag()<0.) continue; // first conjugate have positive imaginary part
356 if(Eval(i+1).imag()>0.) continue;
357 Evalconj(i) = 1; Evalconj(i+1) = 2; nconj++;
358}
359//cout<<Evalconj<<endl;
360cout<<"Number of conjugate eigen values: "<<nconj<<" *2 = "<<2*nconj<<" / "<<N<<endl;
361#endif
362//-- Azmlz = A*z(l) - l*z(l)
363cout<<"Compute Azmlz(l) = A*z(l) - l*z(l)"<<endl;
364TMatrix< complex<TYPER> > Azmlz(N,N); Azmlz = (complex<TYPER>) 0;
365for(int l=0;l<N;l++) { // eigen value
366 complex<TYPER> Eval_l = complex<TYPER>(Eval(l).real(),Eval(l).imag());
367 for(int i=0;i<N;i++) {
368 complex<TYPER> Evec_il;
[2557]369 #if defined(COMPLEX)
[2555]370 Evec_il = Evec(i,l);
371 #else
372 Evec_il = complex<TYPER>(Evec(i,l),0.);
373 if(Evalconj(l)==1) Evec_il = complex<TYPER>(Evec(i,l),Evec(i,l+1));
374 else if(Evalconj(l)==2) Evec_il = complex<TYPER>(Evec(i,l-1),-Evec(i,l));
375 #endif
376 for(int j=0;j<N;j++) {
377 complex<TYPER> Evec_jl;
[2557]378 #if defined(COMPLEX)
[2555]379 Evec_jl = Evec(j,l);
380 #else
381 Evec_jl = complex<TYPER>(Evec(j,l),0.);
382 if(Evalconj(l)==1) Evec_jl = complex<TYPER>(Evec(j,l),Evec(j,l+1));
383 else if(Evalconj(l)==2) Evec_jl = complex<TYPER>(Evec(j,l-1),-Evec(j,l));
384 #endif
385 Azmlz(i,l) += Ainput(i,j) * Evec_jl;
386 }
387 Azmlz(i,l) -= Eval_l*Evec_il;
388 }
389}
390if(nprline>0) {cout<<Azmlz; cout<<endl;}
391//-- Check
392Check_Mat_VecCol_2(Azmlz);
393PrtTim("--- End of LapackEigen Test ---");
394}
395#endif
396
397
398////////////////////////////////////////////////
399///////// Test avec Lapack sym pour EV /////////
400////////////////////////////////////////////////
[2557]401#if defined(USE_LAPACK) && defined(ALSO_LAPACK_EV_SYM)
[2555]402{
403cout<<"\n=========================================="<<endl;
404cout<<"------------ Eigen decompositon LapackEigenSym "<<endl;
405TMatrix< TYPE > Aher(N,N); Aher=Ainput; Hermitian(Aher); A=Aher;
406TVector<r_8> Eval;
407//-- Decompositon
408int_4 info = LapackEigenSym(A,Eval,true);
409cout<<"info="<<info<<endl;
410PrtTim("--- End of LapackEigenSym decompositon ---");
411if(nprline>0) {cout<<Eval; cout<<endl; cout<<A; cout<<endl;}
412//-- Azmlz = A*z(l) - l*z(l)
413// le vecteur propre z pour la l-ieme valeur propre est dans A(.,l):
414// z_i = A(i,l) ou "l" est la l-ieme valeur propre
415cout<<"Compute Azmlz(l) = A*z(l) - l*z(l)"<<endl;
416TMatrix< TYPE > Azmlz(N,N); Azmlz = (TYPE) 0;
417for(int l=0;l<N;l++) // eigen value
418 for(int i=0;i<N;i++)
419 {for(int j=0;j<N;j++) Azmlz(i,l)+=Aher(i,j)*A(j,l); Azmlz(i,l)-=(TYPER)Eval(l)*A(i,l);}
420if(nprline>0) {cout<<Azmlz; cout<<endl;}
421//-- Check
422Check_Mat_VecCol_0(Azmlz);
423PrtTim("--- End of LapackEigenSym Test ---");
424}
425#endif
426
427
[2558]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
[2557]459///////////////////////////////////////////////
460///////// Test Inversion avec GausPiv /////////
461///////////////////////////////////////////////
462#if defined(USE_GAUSPIV)
[2555]463{
464cout<<"\n==========================================\n"
465 <<"------------ Inversion GausPiv"<<endl;
466SimpleMatrixOperation< TYPE >::SetGausPivScal(tscal);
467A = Ainput;
468//-- Inversion
469TMatrix< TYPE > InvA(N,N); InvA = IdentityMatrix(1.,N);
[1008]470TYPE det = GausPiv(A,InvA,detok);
[2555]471PrtTim("--- End of GausPiv Inversion ---");
[1008]472cout<<"Det = "<<det<<endl;
[934]473cout<<"------------ TMatrix InvA = A^(-1):"<<endl;
474//-- AiA = A * InvA
[2555]475cout<<"Compute AiA = A * InvA"<<endl;
476TMatrix< TYPE > AiA(N,N); AiA = Ainput * InvA;
[934]477cout<<"------------ TMatrix AiA = A * InvA:"<<endl;
478if(nprline>0) {cout<<AiA; cout<<endl;}
479//-- Check
[2555]480Check_Mat_Ident(AiA);
481PrtTim("--- End of GausPiv Test ---");
[934]482}
[2555]483#endif
484
485
486PrtTim("--- End of Job ---");
487exit(0);
[934]488}
489
[995]490
[2555]491
492////////////////////////////////////////////////////////////
493////-------------------------------------------------------
494void Symetrize(TMatrix< TYPE >& A)
495// Symetrize A
496{
497 int_4 N = A.NRows();
498 for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++) A(j,i) = A(i,j);
[995]499}
[2555]500
501////-------------------------------------------------------
502void Hermitian(TMatrix< TYPE >& A)
503// Put A hermitian
504{
505 int_4 N = A.NRows();
506 for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++) A(j,i) = CONJ_VAL(A(i,j));
507 for(int i=0;i<N;i++) A(i,i) = REAL_PART(A(i,i));
[995]508}
509
[2555]510////-------------------------------------------------------
511r_8 Check_Mat_Ident(TMatrix< TYPE >& A)
512// Compute the biggest difference element by element of A / Identity
513{
514 int_4 N = A.NRows();
515 r_8 vmaxd=-1.;
516 for(int i=0;i<N;i++)
517 if( ABS_VAL((TYPER)1.-A(i,i)) > vmaxd ) vmaxd = ABS_VAL((TYPER)1.-A(i,i));
518 cout<<"Ecart maximum par rapport a 1 sur diagonale = "<<vmaxd<<endl;
519 r_8 vmaxh = -1.;
520 for(int i=0;i<N;i++) for(int j=0;j<N;j++) {
521 if(i==j) continue;
522 if( ABS_VAL(A(i,j)) > vmaxh ) vmaxh = ABS_VAL(A(i,j));
523 }
524 cout<<"Ecart maximum par rapport a 0 hors diagonale = "<<vmaxh<<endl;
525 return (vmaxd>vmaxh)? vmaxd: vmaxh;
526}
[995]527
[2555]528////-------------------------------------------------------
[2558]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;
538}
539
540////-------------------------------------------------------
[2555]541r_8 Check_Mat_VecCol_0(TMatrix< TYPE >& A)
542// Return the biggest norm of the N vectors column of matrix
543{
544 int_4 N = A.NRows();
545 r_8 vmax=-1.;
546 for(int l=0;l<N;l++) {
547 r_8 absv = 0.;
548 for(int i=0;i<N;i++) absv += ABS_VAL(A(i,l)) * ABS_VAL(A(i,l));
549 if( absv > vmax ) vmax = absv;
550 }
551 vmax = sqrt(vmax);
552 cout<<"Longueur max de ||A*z-l*z|| pour tous l = "<<vmax<<endl;
553 return vmax;
[934]554}
[2555]555
556////-------------------------------------------------------
557void Check_Mat_VecCol_2(TMatrix< complex<TYPER> >& A)
558// Return the biggest norm of :
559// - the real part of the N vectors column of matrix
560// - the imaginary part of the N vectors column of matrix
561// - the module of the N vectors column of matrix
562{
563 int_4 N = A.NRows();
564 r_8 vmaxr=-1., vmaxi=-1., vmaxn=-1.;
565 for(int l=0;l<N;l++) {
566 double absvr = 0., absvi = 0., absvn = 0.;
567 for(int i=0;i<N;i++) {
568 absvr += A(i,l).real()*A(i,l).real();
569 absvi += A(i,l).imag()*A(i,l).imag();
570 absvn += A(i,l).real()*A(i,l).real() + A(i,l).imag()*A(i,l).imag();
571 }
572 if( absvr > vmaxr ) vmaxr = absvr;
573 if( absvi > vmaxi ) vmaxi = absvi;
574 if( absvn > vmaxn ) vmaxn = absvn;
575 }
576 vmaxr=sqrt(vmaxr); vmaxi=sqrt(vmaxi); vmaxn=sqrt(vmaxn);
577 cout<<"Longueur max de ||A*z-l*z|| pour tous l, reel = "<<vmaxr
578 <<", imag = "<<vmaxi<<", module = "<<vmaxn<<endl;
579}
580
581
582/*
583void TestIlaEnv(int_4 n)
584{
585LapackServer<TYPE> lps;
586cout<<"TestIlaEnv n="<<n<<endl;
587cout<<lps.ilaenv_en_C(1,"SSYTRF","U",n,-1,-1,-1)<<endl;
588cout<<lps.ilaenv_en_C(1,"DSYTRF","U",n,-1,-1,-1)<<endl;
589cout<<lps.ilaenv_en_C(1,"CSYTRF","U",n,-1,-1,-1)<<endl;
590cout<<lps.ilaenv_en_C(1,"ZSYTRF","U",n,-1,-1,-1)<<endl;
591cout<<lps.ilaenv_en_C(1,"SSYTRF","L",n,-1,-1,-1)<<endl;
592cout<<lps.ilaenv_en_C(1,"DSYTRF","L",n,-1,-1,-1)<<endl;
593cout<<lps.ilaenv_en_C(1,"CSYTRF","L",n,-1,-1,-1)<<endl;
594cout<<lps.ilaenv_en_C(1,"ZSYTRF","L",n,-1,-1,-1)<<endl;
595}
596*/
Note: See TracBrowser for help on using the repository browser.