[2647] | 1 | #include "sopnamsp.h"
|
---|
| 2 | #include "machdefs.h"
|
---|
| 3 |
|
---|
| 4 | #include <math.h>
|
---|
| 5 | #include <iostream>
|
---|
| 6 |
|
---|
| 7 | #include "srandgen.h"
|
---|
| 8 | #include "tarrinit.h"
|
---|
| 9 | #include "tvector.h"
|
---|
| 10 | #include "sopemtx.h"
|
---|
| 11 | #include "timing.h"
|
---|
| 12 |
|
---|
| 13 | /********************************************************
|
---|
| 14 | Programme test pour les fonctionalites de calcul
|
---|
| 15 | sur matrices et vecteurs dans SOPHYA/TArray
|
---|
| 16 | Reza - fev 2005
|
---|
| 17 | *********************************************************/
|
---|
| 18 |
|
---|
| 19 | int mxv_inverse(int l); // ErrorCode = 64
|
---|
| 20 |
|
---|
| 21 | static double TOLERANCE = 1.e-6;
|
---|
| 22 | static int nprt = 100;
|
---|
| 23 | static int prtlev = 1;
|
---|
| 24 |
|
---|
| 25 | int main(int narg, char* arg[])
|
---|
| 26 | {
|
---|
| 27 |
|
---|
| 28 | SophyaInit();
|
---|
| 29 | InitTim(); // Initializing the CPU timer
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | if (narg < 2) {
|
---|
| 34 | cout << " tmxv : Test SOPHYA Matrix/Vector operations\n"
|
---|
| 35 | << " Usage: tmxv select [sizeL,C=5,5] [prtlev=1] [nprtmax=100]\n"
|
---|
| 36 | << " select= inverse / all= \n"
|
---|
| 37 | << " inverse: ComputeInverse() r_8 \n" << endl;
|
---|
| 38 | exit(0);
|
---|
| 39 | }
|
---|
| 40 | int l,c;
|
---|
| 41 | l = c = 5;
|
---|
| 42 | int wsf = 2;
|
---|
| 43 | string opt = arg[1];
|
---|
| 44 | if (narg > 2) sscanf(arg[2], "%d,%d", &l, &c);
|
---|
| 45 | if (narg > 3) prtlev = atoi(arg[3]);
|
---|
| 46 | if (narg > 4) nprt = atoi(arg[4]);
|
---|
| 47 |
|
---|
| 48 | cout << " tmxv - TMatrix/TVector operations tests sizeL,C=" << l << "," << c
|
---|
| 49 | << " opt= " << opt << endl;
|
---|
| 50 | int rc = 0;
|
---|
| 51 | BaseArray::SetMaxPrint(nprt, prtlev);
|
---|
| 52 | try {
|
---|
| 53 | if (opt == "inverse") rc = mxv_inverse(l);
|
---|
| 54 | else { cout << "tmxv/ Unknown option " << opt << " ! " << endl; rc = 66; }
|
---|
| 55 | }
|
---|
| 56 | catch (PThrowable exc) {
|
---|
[3334] | 57 | cerr << " tmxv catched Exception (tmxv.cc) " << exc.Msg() << endl;
|
---|
[2647] | 58 | rc = 77;
|
---|
| 59 | }
|
---|
| 60 | catch (...) {
|
---|
[3334] | 61 | cerr << " tmxv catched unknown (...) exception (tmxv.cc) " << endl;
|
---|
[2647] | 62 | rc = 78;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[3334] | 65 | PrtTim(" End of tmxv matrix inversion test ");
|
---|
[2647] | 66 | cout << " --------------- END of Programme -------- (Rc= "
|
---|
| 67 | << rc << ") --- " << endl;
|
---|
| 68 | return(rc);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | // -----------------------------------------------------------------------
|
---|
| 72 | /* Nouvelle-Fonction */
|
---|
| 73 | int mxv_inverse(int m)
|
---|
| 74 | {
|
---|
| 75 | cout << " mxv_inverse() - Test SimpleMatrixOperation<r_8> " << endl;
|
---|
| 76 |
|
---|
| 77 | Matrix a(m , m), ainv, idmx(m,m), mxprod, diff;
|
---|
| 78 | a = RandomSequence(RandomSequence::Gaussian, 0., 4.);
|
---|
| 79 | PrtTim(" End of a_inint");
|
---|
| 80 |
|
---|
| 81 | cout << "\n Calling SimpleMatrixOperation::Inverse .... " << endl;
|
---|
| 82 | SimpleMatrixOperation<r_8> smo;
|
---|
| 83 | ainv = smo.Inverse(a);
|
---|
| 84 | PrtTim(" End of smo.Inverse()");
|
---|
| 85 | mxprod = a*ainv;
|
---|
| 86 | PrtTim(" End of mxprod = a*ainv");
|
---|
| 87 | idmx = IdentityMatrix();
|
---|
| 88 | PrtTim(" End of idmx = IdentityMatrix()");
|
---|
| 89 | diff = mxprod-idmx;
|
---|
| 90 | PrtTim(" End of Compute(diff)");
|
---|
| 91 |
|
---|
| 92 | if (prtlev > 0) {
|
---|
| 93 | cout << " ------------ Matrix A = \n " << a << "\n" << endl;
|
---|
| 94 | cout << " ------------ Matrix Inverse(A) = \n " << ainv << "\n" << endl;
|
---|
| 95 | cout << " ------------ Matrix mxprod = A*Inverse(A) = \n " << mxprod << "\n" << endl;
|
---|
| 96 | }
|
---|
| 97 | double min,max;
|
---|
| 98 | diff.MinMax(min, max);
|
---|
| 99 | PrtTim(" End of diffCheck");
|
---|
| 100 | cout << " Min/Max difference Matrix (?=0) , Min= " << min
|
---|
| 101 | << " Max= " << max << endl;
|
---|
| 102 | if ((fabs(min) > TOLERANCE) || (fabs(max) > TOLERANCE)) {
|
---|
| 103 | cout << " !!! Difference exceeding tolerance (=" << TOLERANCE << ") !!!"
|
---|
| 104 | << endl;
|
---|
| 105 | return 64;
|
---|
| 106 | }
|
---|
| 107 | return 0;
|
---|
| 108 |
|
---|
| 109 | }
|
---|
| 110 |
|
---|