Changeset 812 in Sophya for trunk/SophyaProg/Tests
- Timestamp:
- Apr 5, 2000, 5:43:18 PM (25 years ago)
- Location:
- trunk/SophyaProg/Tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/Tests/arrt.cc
r807 r812 6 6 #include "nbrandom.h" 7 7 #include "tarrinit.h" 8 #include " tarray.h"9 #include "fioarr.h"10 #include "matharr.h"8 #include "array.h" 9 // #include "fioarr.h" 10 // #include "matharr.h" 11 11 #include "timing.h" 12 12 13 14 void tstioarr(TArray<int_4> & ia, TArray<int_4> & ib, TArray<int_4> & ic); 15 void tstmtx(); 13 static void tstarr(bool tio); 14 static void tstioarr(TArray<int_4> & ia, TArray<int_4> & ib, TArray<int_4> & ic); 15 static void tstmtx(int n); 16 void _ZZ_TestTMatrixRC_YY_(TMatrix<r_8> & m); 16 17 17 18 int main(int narg, char* arg[]) … … 22 23 23 24 25 if (narg < 2) { 26 cout << " arrt - TArray<T> Test - Usage arrt a/p/m/z [size=5] [prtlev=1] [nprt=50]\n" 27 << " a: Simple Array Test w: a+ PPersist Test (FIO_TArray<T>) \n" 28 << " m: Matrix and Vector Test \n" 29 << " z: Appel_ZZ_TestTMatrixRC_YY_ " << endl; 30 exit(0); 31 } 32 33 int opt = *(arg[1]); 24 34 int n = 5; 25 int i,j,k; 26 27 bool tio = false; 28 if (narg > 1) tio = true; 35 if (narg > 2) n = atoi(arg[2]); 36 uint_4 prtlev = 1; 37 uint_4 nprt = 50; 38 if (narg > 3) prtlev = atoi(arg[3]); 39 if (narg > 4) nprt = atoi(arg[4]); 40 41 BaseArray::SetMaxPrint(nprt, prtlev); 29 42 30 43 try { 44 if ((opt == 'w') || (opt == 'a')) tstarr((opt=='w')); 45 else if (opt == 'z') { 46 if (n<5) n = 5; 47 TMatrix<r_8> tza(n,n+3); 48 tza = Sequence(2.,1.5); 49 _ZZ_TestTMatrixRC_YY_(tza); 50 TMatrix<r_8> tza2 = tza(Range(1,3), Range(2,5)); 51 _ZZ_TestTMatrixRC_YY_(tza2); 52 } 53 else tstmtx(n); 54 } 55 catch (PThrowable exc) { 56 cerr << " catched Exception " << exc.Msg() << endl; 57 } 58 catch (...) { 59 cerr << " catched unknown (...) exception " << endl; 60 } 61 PrtTim("--- End of arrt ---"); 62 cout << " --------------- END of ArrayTest programme -------------- " << endl; 63 } 64 65 66 void tstmtx(int n) 67 { 68 TMatrix<r_4> ma(4,7); 69 ma = Sequence(10., 2.); 70 cout << "\n :::::: Testing TMatrix - TVector :::::: " << endl; 71 TMatrix<r_4> sma1 = ma(Range(1,2), Range(2,4)); 72 cout << " ----- Matrix ma = \n " << ma << endl; 73 sma1 = 3.14; 74 cout << " ----- Matrix ma (Avec sma1=ma(Range(1,2), Range(2,3))=3.14) = \n " << ma << endl; 75 TMatrix<r_4> mb(2,3); 76 mb = 50.; 77 TMatrix<r_4> mc = mb+sma1; 78 cout << " ----- Matrix mc = mb(=50.)+sma1(=3.14) = " << mc << endl; 79 TMatrix<r_4> md = (float)100+mc; 80 cout << " ----- Matrix md=100.+mc = " << md << endl; 81 cout << " ----- Matrix md-50 = " << md-(float)50. << endl; 82 83 TMatrix<int_4> ima(3,10); 84 ima = Sequence(0.01,1.); 85 cout << " ----- Matrix ima(3,10) = Sequence(0.01,1.) = " << ima << endl; 86 cout << " ----- Matrix ima.Column(3) = \n" << ima.Column(3) << endl; 87 TVector<int_4> vcol = ima.Column(7); 88 cout << " ----- Vector vcol=ima.Column(7) = \n" << vcol << endl; 89 cout << " ----- Matrix ima.Row(0) = \n" << ima.Row(0) << endl; 90 TVector<int_4> vlig = ima.Row(1); 91 cout << " ----- Vector vlig=ima.Row(1) = \n" << vlig << endl; 92 93 TMatrix<int_4> imb(3,10); 94 imb = Sequence(100.01,10.); 95 cout << " ----- Matrix imb(3,10) = Sequence(100.01,10.) = " << imb << endl; 96 TMatrix<int_4> imc = ima+imb; 97 cout << " ----- Matrix imc=ima+imb = " << imc << endl; 98 TMatrix<int_4> imd(3,10); 99 TMatrix<int_4> imd2(3,10); 100 imd += 25; 101 imd *= 2; 102 imd2 = 2; 103 imd.MulElt(imd2); 104 cout << " ----- Matrix imd (? = 100) " << imd << endl; 105 imb -= imd; 106 imc -= imd; 107 cout << " ----- Matrix ((imc-=imd)-(imb-=imd))-ima (== 0 ?) " 108 << (imc-imb)-ima << endl; 109 TVector<r_4> va(16, BaseArray::RowVector); 110 va = Sequence(0.,1.); 111 cout << " ----- Vector va = Sequence(0.,1.) = " << va << endl; 112 va(Range(2,0,6,2)) *= 10.; 113 cout << " ----- Vector va apres va(Range(2,0,6,2)) *= 10. " << va << endl; 114 va(Range(0,5)) += 100.; 115 cout << " ----- Vector va apres va(Range(0,6)) += 100. " << va << endl; 116 117 cout << "\n :::::: Testing Matrix operations :::::: " << endl; 118 TMatrix<r_4> ra(2,2), ira(2,2); 119 ra(0,0) = 2.; ra(0,1) = 1.; 120 ra(1,0) = 4.; ra(1,1) = 3.; 121 ira(0,0) = 1.5; ira(0,1) = -0.5; 122 ira(1,0) = -2.; ira(1,1) = 1.; 123 cout << " ----- Matrix ra = \n " << ra << endl; 124 cout << " ----- Matrix ira = \n " << ira << endl; 125 cout << " ----- Matrix ira*ra = (= Identity ?) " << ira*ra << endl; 126 127 128 cout << "\n ::::::: Testing Matrix Inversion ::::::: " << endl; 129 SimpleMatrixOperation<r_4> smr; 130 TMatrix<r_4> cira = smr.Inverse(ra); 131 cout << " ----- Matrix Inverse(ra) = " << cira << endl; 132 cout << " ----- ira-Inverse(ra) = " << ira-cira << endl; 133 134 Matrix a(n,n); 135 136 137 for(int i=0; i<n; i++) 138 for(int j=0; j<n; j++) a(j,i) = GauRnd(0., 1.); 139 cout << " ----- Matrix a = \n " << a << endl; 140 Vector x(n); 141 x = Sequence(1.,3.); 142 Vector b = a*x; 143 cout << " ----- Vector x = \n " << x << endl; 144 cout << " ----- Vector b = a*x = \n " << b << endl; 145 SimpleMatrixOperation<r_8> smo; 146 Matrix inva = smo.Inverse(a); 147 cout << " ----- Matrix Inverse(a) = \n " << inva << endl; 148 cout << " ----- Matrix a*Inverse(a) = \n " << inva*a << endl; 149 cout << " ----- Matrix Inverse(a)*b (=Inv(a)*a*x) = \n " << inva*b << endl; 150 cout << " ----- Matrix x-Inverse(a)*b = (=0 ?)\n " << x-inva*b << endl; 151 } 152 153 void tstarr(bool tio) 154 { 31 155 cout << "\n -----> Testing TArray <---- " << endl; 32 156 // We create a integer array SizeX=7, SizeY=5 … … 34 158 // We fill it with a sequence of numbers starting at 10., with step = 2. 35 159 ia = Sequence(10., 2.); 36 cout << " ----- matrixIA = \n " << ia << endl;37 // sub array extraction, Range(2, 3) : starting position=2 , size=338 TArray<int_4> ic = ia(Range(2,3),Range(1, 2),Range(0));39 cout << " ----- matrix IC IA(Range(2,3),Range(1,2)) = \n " << ic << endl;160 cout << " ----- Array IA = \n " << ia << endl; 161 // sub array extraction, Range(2,4) : starting position=2 , End=4 162 TArray<int_4> ic = ia(Range(2,3),Range(1,3),Range(0)); 163 cout << " ----- Array IC IA(Range(2,4),Range(1,2)) = \n " << ic << endl; 40 164 // we set the sub-array to zero, this should reflect in the original array 41 165 // sub-arrays share their data with parent array 42 166 ic = 0; 43 cout << " ----- matrixIC Apres (=0) = \n " << ic << endl;44 cout << " ----- matrixIA Apres IC=0 = \n " << ia << endl;167 cout << " ----- Array IC Apres (=0) = \n " << ic << endl; 168 cout << " ----- Array IA Apres IC=0 = \n " << ia << endl; 45 169 46 170 cout << " :::: 3 Dim arrays ::::: " << endl; … … 49 173 TArray<int_4> ib(8,7,2); 50 174 ib = 5; 51 cout << " ----- matrixIB = \n " << ib << endl;175 cout << " ----- Array IB = \n " << ib << endl; 52 176 // Sub array extraction X from 1 , size 4 - Y from 2 , size 3 , in Z default, from 0, size 1 53 177 // we multiply this sub-array elements by 3 54 ib(Range(1,4),Range(2, 3), Range(0)) *= 3;55 cout << " -- matrix IB , Apres ib(Range(1,3),Range(2,1))*=3 : " << endl;178 ib(Range(1,4),Range(2,4), Range(0)) *= 3; 179 cout << " -- Array IB , Apres ib(Range(1,4),Range(2,4))*=3 : " << endl; 56 180 cout << ib; 181 cout << " -- Array ib(Range(1,4),Range(2,4)) = : " 182 << ib(Range(1,4),Range(2,4), Range(0)) << endl; 57 183 58 184 // Creating a double array X=5 x Y=2 … … 69 195 70 196 if (tio) tstioarr(ia, ib, ic); 71 72 }73 catch (PThrowable exc) {74 cerr << " catched Exception " << exc.Msg() << endl;75 }76 catch (...) {77 cerr << " catched unknown (...) exception " << endl;78 }79 cout << " --------------- END of Programme -------------- " << endl;80 197 } 81 198 … … 104 221 // We read the three arrays from the stream 105 222 pis >> iaa >> ibb >> icc; 106 cout << " ----- matrixIAA = \n " << iaa << endl;107 cout << " ----- matrixIBB = \n " << ibb << endl;108 cout << " ----- matrixICC = \n " << icc << endl;223 cout << " ----- Array IAA = \n " << iaa << endl; 224 cout << " ----- Array IBB = \n " << ibb << endl; 225 cout << " ----- Array ICC = \n " << icc << endl; 109 226 icc = 12; 110 cout << " ----- matrixICC (=12) = \n " << icc << endl;111 cout << " ----- matrixIAA (ICC=12) = \n " << iaa << endl;227 cout << " ----- Array ICC (=12) = \n " << icc << endl; 228 cout << " ----- Array IAA (ICC=12) = \n " << iaa << endl; 112 229 } 113 230 … … 124 241 pis.GetObject(iaa, tag); 125 242 126 cout << " ----- matrixIAAA = \n " << iaa << endl;127 cout << " ----- matrixIBBB = \n " << ibb << endl;128 cout << " ----- matrixICCC = \n " << icc << endl;243 cout << " ----- Array IAAA = \n " << iaa << endl; 244 cout << " ----- Array IBBB = \n " << ibb << endl; 245 cout << " ----- Array ICCC = \n " << icc << endl; 129 246 icc = 68; 130 cout << " ----- matrixICCC (=12) = \n " << icc << endl;131 cout << " ----- matrixIAAA (ICC=12) = \n " << iaa << endl;132 } 133 134 135 } 247 cout << " ----- Array ICCC (=12) = \n " << icc << endl; 248 cout << " ----- Array IAAA (ICC=12) = \n " << iaa << endl; 249 } 250 251 252 } -
trunk/SophyaProg/Tests/lpk.cc
r807 r812 12 12 13 13 14 void lpk_tarr(int n); 15 void lpk_tmtx(int n); 16 14 17 int main(int narg, char* arg[]) 15 18 { … … 19 22 20 23 24 25 if (narg < 2) { 26 cout << " lpk - LinAlg/LapackServer test - Usage lpk t/s [size=5] [prtlev=0] [nprtmax=100]\n" 27 << " t: lpk_tarr() rztest_lapack with TArray<r_4> \n" 28 << " s: lpk_tmtx() LapackServer with TMatrix<r_8> \n" << endl; 29 exit(0); 30 } 21 31 int n = 5; 32 int opt = 's'; 33 opt = *(arg[1]); 34 if (narg > 2) n = atoi(arg[2]); 35 int nprt = 100; 36 int prtlev = 1; 37 if (narg > 3) prtlev = atoi(arg[3]); 38 if (narg > 4) nprt = atoi(arg[4]); 39 40 BaseArray::SetMaxPrint(nprt, prtlev); 41 try { 42 if (opt == 's') lpk_tmtx(n); 43 else lpk_tarr(n); 44 } 45 catch (PThrowable exc) { 46 cerr << " catched Exception (lpk.cc) " << exc.Msg() << endl; 47 } 48 catch (...) { 49 cerr << " catched unknown (...) exception (lpk.cc) " << endl; 50 } 51 52 PrtTim(" End of lpk LinAlg/Lapack test "); 53 cout << " --------------- END of Programme -------------- " << endl; 54 } 55 56 57 void lpk_tmtx(int n) 58 { 22 59 int i,j,k; 60 BaseArray::SetDefaultMemoryMapping(BaseArray::FortranMemoryMapping); 61 Matrix a(n,n); 62 for(i=0; i<n; i++) 63 for(j=0; j<n; j++) a(j,i) = GauRnd(0., 1.); 64 cout << " ------------ Matrix A = \n " << a << "\n" << endl; 65 66 Vector x(n), b; 67 // Matrix x(n,1), b; 68 cout << " ------------ Vector X = \n " << x << "\n" << endl; 69 for(i=0; i<n; i++) x(i) = GauRnd(2., 1.5); 70 b = a*x; 23 71 24 if (narg > 1) n = atoi(arg[1]); 25 cout << ":::::::: rztest_lapack - Size=" << n << " ::::::::: " << endl; 26 try { 72 // cout << ":::::::: rztest_lapack - Size=" << n << " ::::::::: " << endl; 73 cout << " ------- lpk_tmtx() LapackServerTest Using TMatrix<r_8> -------- " << endl; 74 cout << " ------------ Matrix A = \n " << a << "\n" << endl; 75 cout << " ------------ Matrix X = \n " << x << "\n" << endl; 76 cout << " ------------ Matrix B = \n " << b << "\n" << endl; 77 78 cout << "\n Calling LapackLinSolve(a,b) .... " << endl; 79 LapackLinSolve(a,b); 80 81 cout << " ------------ Result B(=X ?) = \n " << b << "\n" << endl; 82 Vector diff = b-x; 83 cout << " ------------ Vector diff B-X = \n " << diff << "\n" << endl; 84 85 } 86 87 void lpk_tarr(int n) 88 { 89 int i,j,k; 27 90 TArray<r_4> a(n,n); 28 91 for(i=0; i<n; i++) … … 38 101 } 39 102 103 // cout << ":::::::: rztest_lapack - Size=" << n << " ::::::::: " << endl; 104 cout << " ------- lpk_tarr() LapaackTest Using TArray<r_4> -------- " << endl; 40 105 cout << " ------------ Array A = \n " << a << "\n" << endl; 41 106 cout << " ------------ Array X = \n " << x << "\n" << endl; … … 47 112 48 113 cout << " ------------ Result B(=X ?) = \n " << b << "\n" << endl; 49 50 PrtTim(" End of lpk (rztest_lapack) ");51 }52 catch (PThrowable exc) {53 cerr << " catched Exception (rztest_lapack) " << exc.Msg() << endl;54 }55 catch (...) {56 cerr << " catched unknown (...) exception (rztest_lapack) " << endl;57 }58 59 cout << " --------------- END of Programme -------------- " << endl;60 114 }
Note:
See TracChangeset
for help on using the changeset viewer.