| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <stdio.h> | 
|---|
| 3 |  | 
|---|
| 4 | #include <exception> | 
|---|
| 5 | #include <string> | 
|---|
| 6 |  | 
|---|
| 7 | #ifdef USEVECSTL | 
|---|
| 8 | #include <vector> | 
|---|
| 9 | #endif | 
|---|
| 10 |  | 
|---|
| 11 | class MyException : public exception | 
|---|
| 12 | { | 
|---|
| 13 | public: | 
|---|
| 14 | MyException(const char * msg) { _msg = msg; } | 
|---|
| 15 | //  ~MyException() { } | 
|---|
| 16 | string Msg() { return(_msg); } | 
|---|
| 17 | private: | 
|---|
| 18 | string _msg; | 
|---|
| 19 | }; | 
|---|
| 20 |  | 
|---|
| 21 | template<class T> class Matrix | 
|---|
| 22 | { | 
|---|
| 23 | T* data; | 
|---|
| 24 | int siz_x, siz_y, offset, step_x, step_y; | 
|---|
| 25 | int size; | 
|---|
| 26 |  | 
|---|
| 27 | public: | 
|---|
| 28 | Matrix (int sx, int sy, int step=0, int offset=0, bool fg=false); | 
|---|
| 29 | ~Matrix (); | 
|---|
| 30 |  | 
|---|
| 31 | inline T operator [] (int k) const { return data[k]; } | 
|---|
| 32 | inline T& operator [] (int k) { return data[k]; } | 
|---|
| 33 |  | 
|---|
| 34 | inline T operator () (int ix, int iy) const { return data[ix+iy*siz_x]; } | 
|---|
| 35 | inline T& operator () (int ix, int iy) { return data[ix+iy*siz_x]; } | 
|---|
| 36 |  | 
|---|
| 37 | inline T  elem (int ix, int iy) const { return data[offset+ix*step_x+iy*step_y]; } | 
|---|
| 38 | inline T& elem (int ix, int iy) { return data[offset+ix*step_x+iy*step_y]; } | 
|---|
| 39 |  | 
|---|
| 40 | inline T  elemCk (int ix, int iy) const | 
|---|
| 41 | { if ((ix < 0) || (ix >= siz_x) || (iy < 0) || (iy >= siz_y)) | 
|---|
| 42 | throw MyException("Matrix<T> Out of bound"); | 
|---|
| 43 | return data[offset+ix*step_x+iy*step_y]; } | 
|---|
| 44 |  | 
|---|
| 45 | inline T& elemCk (int ix, int iy) | 
|---|
| 46 | { if ((ix < 0) || (ix >= siz_x) || (iy < 0) || (iy >= siz_y)) | 
|---|
| 47 | throw MyException("Matrix<T> Out of bound"); | 
|---|
| 48 | return data[offset+ix*step_x+iy*step_y]; } | 
|---|
| 49 |  | 
|---|
| 50 | inline int getSize () const { return size; } | 
|---|
| 51 | inline int getSizeX () const { return siz_x; } | 
|---|
| 52 | inline int getSizeY () const { return siz_y; } | 
|---|
| 53 |  | 
|---|
| 54 | // Addition et multiplication en utilisant elem() | 
|---|
| 55 | Matrix<T> * Add(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 56 | Matrix<T> * Mult(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 57 | // Addition et multiplication en utilisant elemCk() | 
|---|
| 58 | Matrix<T> * AddCk(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 59 | Matrix<T> * MultCk(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 60 | // Addition et multiplication en utilisant l'operateur [] | 
|---|
| 61 | Matrix<T> * AddO1(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 62 | Matrix<T> * MultO1(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 63 | // Addition et multiplication en utilisant l'operateur () | 
|---|
| 64 | Matrix<T> * AddO2(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 65 | Matrix<T> * MultO2(Matrix<T> & v1, Matrix<T> & v2); | 
|---|
| 66 | }; | 
|---|
| 67 |  | 
|---|
| 68 | template<class T> Matrix<T>::Matrix (int sx, int sy, int step, int off, bool fg) | 
|---|
| 69 | { | 
|---|
| 70 | int k; | 
|---|
| 71 | int s = offset+sx*sy*step; | 
|---|
| 72 | if (s < 1) s = 1; | 
|---|
| 73 | size = s; | 
|---|
| 74 | siz_x = sx; | 
|---|
| 75 | siz_y = sy; | 
|---|
| 76 | offset = off; | 
|---|
| 77 | step_x = step; | 
|---|
| 78 | step_y = step*siz_x; | 
|---|
| 79 | data = new T[size]; | 
|---|
| 80 | if (!fg)  return; | 
|---|
| 81 |  | 
|---|
| 82 | T * p = data; | 
|---|
| 83 | for(k=0; k<s; k++) p[k] = (T)0; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | template<class T> Matrix<T>::~Matrix() | 
|---|
| 87 | { | 
|---|
| 88 | delete[] data; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | template<class T> Matrix<T> * Matrix<T>::Add(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 94 | { | 
|---|
| 95 | int i,j; | 
|---|
| 96 |  | 
|---|
| 97 | for (i = 0; i < siz_x; i++) | 
|---|
| 98 | for (j = 0; j < siz_y; j++) | 
|---|
| 99 | elem(i,j) = v1.elem(i,j)+v2.elem(i,j); | 
|---|
| 100 | return (this); | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | template<class T> Matrix<T> * Matrix<T>::Mult(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 104 | { | 
|---|
| 105 | int i,j; | 
|---|
| 106 |  | 
|---|
| 107 | for (i = 0; i < siz_x; i++) | 
|---|
| 108 | for (j = 0; j < siz_y; j++) | 
|---|
| 109 | elem(i,j) = v1.elem(i,j)*v2.elem(i,j); | 
|---|
| 110 | return (this); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 |  | 
|---|
| 114 | template<class T> Matrix<T> * Matrix<T>::AddCk(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 115 | { | 
|---|
| 116 | int i,j; | 
|---|
| 117 |  | 
|---|
| 118 | for (i = 0; i < siz_x; i++) | 
|---|
| 119 | for (j = 0; j < siz_y; j++) | 
|---|
| 120 | elem(i,j) = v1.elemCk(i,j)+v2.elemCk(i,j); | 
|---|
| 121 | return (this); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | template<class T> Matrix<T> * Matrix<T>::MultCk(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 125 | { | 
|---|
| 126 | int i,j; | 
|---|
| 127 |  | 
|---|
| 128 | for (i = 0; i < siz_x; i++) | 
|---|
| 129 | for (j = 0; j < siz_y; j++) | 
|---|
| 130 | elem(i,j) = v1.elemCk(i,j)*v2.elemCk(i,j); | 
|---|
| 131 | return (this); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | template<class T> Matrix<T> * Matrix<T>::AddO1(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 135 | { | 
|---|
| 136 | int i; | 
|---|
| 137 | for (i = 0; i < size; i++) (*this)[i] = v1[i] + v2[i]; | 
|---|
| 138 | return (this); | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | template<class T> Matrix<T> * Matrix<T>::MultO1(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 142 | { | 
|---|
| 143 | int i; | 
|---|
| 144 | for (i = 0; i < size; i++) (*this)[i] = v1[i] * v2[i]; | 
|---|
| 145 | return (this); | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | template<class T> Matrix<T> * Matrix<T>::AddO2(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 149 | { | 
|---|
| 150 | int i,j; | 
|---|
| 151 |  | 
|---|
| 152 | for (i = 0; i < siz_x; i++) | 
|---|
| 153 | for (j = 0; j < siz_y; j++)  (*this)(i,j) = v1(i,j) + v2(i,j); | 
|---|
| 154 | return (this); | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | template<class T> Matrix<T> * Matrix<T>::MultO2(Matrix<T> &v1, Matrix<T> &v2) | 
|---|
| 158 | { | 
|---|
| 159 | int i,j; | 
|---|
| 160 |  | 
|---|
| 161 | for (i = 0; i < siz_x; i++) | 
|---|
| 162 | for (j = 0; j < siz_y; j++)  (*this)(i,j) = v1(i,j) * v2(i,j); | 
|---|
| 163 | return (this); | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 |  | 
|---|
| 167 | extern "C" void InitTim(); | 
|---|
| 168 | extern "C" void PrtTim(const char *Comm); | 
|---|
| 169 |  | 
|---|
| 170 | /* --------------------------------------------------------------------- */ | 
|---|
| 171 | /* --------------------------- Main Program ---------------------------- */ | 
|---|
| 172 | /* --------------------------------------------------------------------- */ | 
|---|
| 173 |  | 
|---|
| 174 | int main (int narg, char *arg[]) | 
|---|
| 175 | { | 
|---|
| 176 |  | 
|---|
| 177 | int pos, N, M, Mx, My, Off, Step, OPT, OPE, i; | 
|---|
| 178 |  | 
|---|
| 179 |  | 
|---|
| 180 | if (narg < 2) { | 
|---|
| 181 | printf("\n Usage: matrix Type(=1,2,3 Int,Float,Double) Ope(=1...10) [N [Mx,My,...] ] \n"); | 
|---|
| 182 | printf("Ope: 1=Create/Delete 2=1+FillVect \n"); | 
|---|
| 183 | printf("Ope: 3=AddO1  4=MultO1 (Using operator [k]) \n"); | 
|---|
| 184 | printf("Ope: 5=AddO2  6=MultO2 (Using operator (i,j)) \n"); | 
|---|
| 185 | printf("Ope: 7=Add    8=Mult   (Using elem()) \n"); | 
|---|
| 186 | printf("Ope: 9=AddCk  10=MultCk (Using elemCk() - with bound checking) \n"); | 
|---|
| 187 | printf("N: Number of operations (def= 100) \n"); | 
|---|
| 188 | printf("Mx,My,Step,Offset: Matrix size (def= 300,200,1,0) \n\n"); | 
|---|
| 189 | exit(0); | 
|---|
| 190 | } | 
|---|
| 191 |  | 
|---|
| 192 | InitTim(); | 
|---|
| 193 |  | 
|---|
| 194 | OPT = 1; OPE = 1; | 
|---|
| 195 | if (narg > 1)  OPT = atoi(arg[1]); | 
|---|
| 196 | if ( (OPT < 1) || (OPT > 3) )  OPT = 1; | 
|---|
| 197 |  | 
|---|
| 198 | if (narg > 2)  OPE = atoi(arg[2]); | 
|---|
| 199 | if ( (OPE < 1) || (OPE > 10) )  OPE = 1; | 
|---|
| 200 |  | 
|---|
| 201 | N = 100; | 
|---|
| 202 | if (narg > 3)  N = atoi(arg[3]); | 
|---|
| 203 | if (N < 1) N = 1; | 
|---|
| 204 | if (N > 100000) N = 100000; | 
|---|
| 205 | Mx = 300; | 
|---|
| 206 | My = 200; | 
|---|
| 207 | Off = 0; | 
|---|
| 208 | Step = 1; | 
|---|
| 209 | if (narg > 4)  sscanf(arg[4], "%d,%d,%d,%d", &Mx, &My, &Step, &Off); | 
|---|
| 210 | if (Mx < 100) Mx = 100; | 
|---|
| 211 | if (My < 100) My = 100; | 
|---|
| 212 | if (Mx > 10000) Mx = 10000; | 
|---|
| 213 | if (My > 10000) My = 10000; | 
|---|
| 214 | if (Step < 1) Step = 1; | 
|---|
| 215 | if (Step > 5) Step = 5; | 
|---|
| 216 | if (Off < 0) Off = 0; | 
|---|
| 217 | if (Off > 1000) Off = 1000; | 
|---|
| 218 |  | 
|---|
| 219 | M = Mx*My*Step; | 
|---|
| 220 |  | 
|---|
| 221 |  | 
|---|
| 222 | printf(" MatrixC++ TestSpeed Typ=%d Ope=%d N=%d MSz=%d\n", OPT, OPE, N,M); | 
|---|
| 223 | printf("    Matrix Size X= %d  Y = %d  Step= %d Offset= %d \n", Mx, My, Step, Off); | 
|---|
| 224 | if (OPE < 3) { /* Test creation / destruction */ | 
|---|
| 225 | int fg = OPE-1; | 
|---|
| 226 | bool fgf = (fg != 0) ? true : false; | 
|---|
| 227 | printf("\n\n Test new/delete Matrix<T> - fg= %d ( <> 0 ---> FillVec) \n", fg); | 
|---|
| 228 | switch (OPT) | 
|---|
| 229 | { | 
|---|
| 230 | case 1 : | 
|---|
| 231 | { | 
|---|
| 232 | Matrix<int> * v; | 
|---|
| 233 | printf("Test %d new/delete Matrix<int>[%d] \n",N,M); | 
|---|
| 234 | for(i=0; i<N; i++) { | 
|---|
| 235 | v = new Matrix<int>(Mx, My, Step, Off, fgf); | 
|---|
| 236 | delete v; | 
|---|
| 237 | } | 
|---|
| 238 | } | 
|---|
| 239 | break; | 
|---|
| 240 | case 2 : | 
|---|
| 241 | { | 
|---|
| 242 | Matrix<float> * v; | 
|---|
| 243 | printf("Test %d  new/delete Matrix<float>[%d] \n",N,M); | 
|---|
| 244 | for(i=0; i<N; i++) { | 
|---|
| 245 | v = new Matrix<float>(Mx, My, Step, Off, fgf); | 
|---|
| 246 | delete v; | 
|---|
| 247 | } | 
|---|
| 248 | } | 
|---|
| 249 | break; | 
|---|
| 250 | case 3 : | 
|---|
| 251 | { | 
|---|
| 252 | Matrix<double> * v; | 
|---|
| 253 | printf("Test %d  new/delete Matrix<double>[%d] \n",N,M); | 
|---|
| 254 | for(i=0; i<N; i++) { | 
|---|
| 255 | v = new Matrix<double>(Mx, My, Step, Off, fgf); | 
|---|
| 256 | delete v; | 
|---|
| 257 | } | 
|---|
| 258 | } | 
|---|
| 259 | break; | 
|---|
| 260 | } | 
|---|
| 261 | PrtTim("Fin New/Delete "); | 
|---|
| 262 | printf(" .......... Fin de MatrixC++ ........... \n"); | 
|---|
| 263 | return (0); | 
|---|
| 264 | } | 
|---|
| 265 |  | 
|---|
| 266 | // ---------- Test Addition, Multiplication ------------- | 
|---|
| 267 |  | 
|---|
| 268 | switch (OPT) | 
|---|
| 269 | { | 
|---|
| 270 | case 1 : | 
|---|
| 271 | { | 
|---|
| 272 | printf("\n\n Test %d operations Matrix<int>[%d] \n",N,M); | 
|---|
| 273 |  | 
|---|
| 274 | Matrix<int> *v1,*v2,*v3; | 
|---|
| 275 | v1 = new Matrix<int>(Mx, My, Step, Off); | 
|---|
| 276 | v2 = new Matrix<int>(Mx, My, Step, Off); | 
|---|
| 277 | v3 = new Matrix<int>(Mx, My, Step, Off); | 
|---|
| 278 | PrtTim("Fin_Creation "); | 
|---|
| 279 |  | 
|---|
| 280 | for(pos=0; pos<M; pos++) | 
|---|
| 281 | { (*v1)[pos] = random()%1000; | 
|---|
| 282 | (*v2)[pos] = random()%5000; } | 
|---|
| 283 |  | 
|---|
| 284 | PrtTim("Fin remplissage "); | 
|---|
| 285 |  | 
|---|
| 286 | if (OPE == 3) { | 
|---|
| 287 | for(pos=0; pos<N; pos++) | 
|---|
| 288 | v3->AddO1(*v1, *v2); | 
|---|
| 289 | PrtTim("Fin Addition AddO1 operator [k]"); | 
|---|
| 290 | } | 
|---|
| 291 | else if (OPE == 4) { | 
|---|
| 292 | for(pos=0; pos<N; pos++) | 
|---|
| 293 | v3->MultO1(*v1, *v2); | 
|---|
| 294 | PrtTim("Fin Multiplication MultO1  operator [k]"); | 
|---|
| 295 | } | 
|---|
| 296 | else if (OPE == 5) { | 
|---|
| 297 | for(pos=0; pos<N; pos++) | 
|---|
| 298 | v3->AddO2(*v1, *v2); | 
|---|
| 299 | PrtTim("Fin Addition AddO2 operator (i,j)"); | 
|---|
| 300 | } | 
|---|
| 301 | else if (OPE == 6) { | 
|---|
| 302 | for(pos=0; pos<N; pos++) | 
|---|
| 303 | v3->MultO2(*v1, *v2); | 
|---|
| 304 | PrtTim("Fin Multiplication MultO2 operator (i,j)"); | 
|---|
| 305 | } | 
|---|
| 306 | else if (OPE == 7) { | 
|---|
| 307 | for(pos=0; pos<N; pos++) | 
|---|
| 308 | v3->Add(*v1, *v2); | 
|---|
| 309 | PrtTim("Fin Addition Add"); | 
|---|
| 310 | } | 
|---|
| 311 | else if (OPE == 8) { | 
|---|
| 312 | for(pos=0; pos<N; pos++) | 
|---|
| 313 | v3->Mult(*v1, *v2); | 
|---|
| 314 | PrtTim("Fin Multiplication Mult"); | 
|---|
| 315 | } | 
|---|
| 316 | else if (OPE == 9) { | 
|---|
| 317 | for(pos=0; pos<N; pos++) | 
|---|
| 318 | v3->AddCk(*v1, *v2); | 
|---|
| 319 | PrtTim("Fin Addition AddCk"); | 
|---|
| 320 | } | 
|---|
| 321 | else if (OPE == 10) { | 
|---|
| 322 | for(pos=0; pos<N; pos++) | 
|---|
| 323 | v3->MultCk(*v1, *v2); | 
|---|
| 324 | PrtTim("Fin Multiplication MultCk"); | 
|---|
| 325 | } | 
|---|
| 326 |  | 
|---|
| 327 | printf("Result[1.2] I1= %d %d  I2= %d %d  I3= %d %d \n", | 
|---|
| 328 | v1->elem(1,0),v1->elem(2,0), v2->elem(1,0),v2->elem(2,0), | 
|---|
| 329 | v3->elem(1,0),v3->elem(2,0)); | 
|---|
| 330 | printf("ResAdd[991-2] I1= %d %d  I2= %d %d  I3= %d %d \n", | 
|---|
| 331 | v1->elem(991,0),v1->elem(992,0), v2->elem(991,0),v2->elem(992,0), | 
|---|
| 332 | v3->elem(991,0),v3->elem(992,0)); | 
|---|
| 333 | } | 
|---|
| 334 | break; | 
|---|
| 335 |  | 
|---|
| 336 | case 2 : | 
|---|
| 337 | { | 
|---|
| 338 | printf("\n\n Test %d operations Matrix<float>[%d] \n",N,M); | 
|---|
| 339 | Matrix<float> *v1,*v2,*v3; | 
|---|
| 340 | v1 = new Matrix<float>(Mx, My, Step, Off); | 
|---|
| 341 | v2 = new Matrix<float>(Mx, My, Step, Off); | 
|---|
| 342 | v3 = new Matrix<float>(Mx, My, Step, Off); | 
|---|
| 343 | PrtTim("Fin_Creation "); | 
|---|
| 344 |  | 
|---|
| 345 | for(pos=0; pos<M; pos++) | 
|---|
| 346 | { (*v1)[pos] = (float)(random()%1000)/250.; | 
|---|
| 347 | (*v2)[pos] =  (float)(random()%5000)/250.; } | 
|---|
| 348 |  | 
|---|
| 349 | PrtTim("Fin remplissage "); | 
|---|
| 350 |  | 
|---|
| 351 | if (OPE == 3) { | 
|---|
| 352 | for(pos=0; pos<N; pos++) | 
|---|
| 353 | v3->AddO1(*v1, *v2); | 
|---|
| 354 | PrtTim("Fin Addition AddO1 operator [k]"); | 
|---|
| 355 | } | 
|---|
| 356 | else if (OPE == 4) { | 
|---|
| 357 | for(pos=0; pos<N; pos++) | 
|---|
| 358 | v3->MultO1(*v1, *v2); | 
|---|
| 359 | PrtTim("Fin Multiplication MultO1  operator [k]"); | 
|---|
| 360 | } | 
|---|
| 361 | else if (OPE == 5) { | 
|---|
| 362 | for(pos=0; pos<N; pos++) | 
|---|
| 363 | v3->AddO2(*v1, *v2); | 
|---|
| 364 | PrtTim("Fin Addition AddO2 operator (i,j)"); | 
|---|
| 365 | } | 
|---|
| 366 | else if (OPE == 6) { | 
|---|
| 367 | for(pos=0; pos<N; pos++) | 
|---|
| 368 | v3->MultO2(*v1, *v2); | 
|---|
| 369 | PrtTim("Fin Multiplication MultO2 operator (i,j)"); | 
|---|
| 370 | } | 
|---|
| 371 | else if (OPE == 7) { | 
|---|
| 372 | for(pos=0; pos<N; pos++) | 
|---|
| 373 | v3->Add(*v1, *v2); | 
|---|
| 374 | PrtTim("Fin Addition Add"); | 
|---|
| 375 | } | 
|---|
| 376 | else if (OPE == 8) { | 
|---|
| 377 | for(pos=0; pos<N; pos++) | 
|---|
| 378 | v3->Mult(*v1, *v2); | 
|---|
| 379 | PrtTim("Fin Multiplication Mult"); | 
|---|
| 380 | } | 
|---|
| 381 | else if (OPE == 9) { | 
|---|
| 382 | for(pos=0; pos<N; pos++) | 
|---|
| 383 | v3->AddCk(*v1, *v2); | 
|---|
| 384 | PrtTim("Fin Addition AddCk"); | 
|---|
| 385 | } | 
|---|
| 386 | else if (OPE == 10) { | 
|---|
| 387 | for(pos=0; pos<N; pos++) | 
|---|
| 388 | v3->MultCk(*v1, *v2); | 
|---|
| 389 | PrtTim("Fin Multiplication MultCk"); | 
|---|
| 390 | } | 
|---|
| 391 |  | 
|---|
| 392 | printf("Result[1.2] F1= %g %g  F2= %g %g  F3= %g %g \n", | 
|---|
| 393 | v1->elem(1,0),v1->elem(2,0), v2->elem(1,0),v2->elem(2,0), | 
|---|
| 394 | v3->elem(1,0),v3->elem(2,0)); | 
|---|
| 395 | printf("Result[991-2] F1= %g %g  F2= %g %g  F3= %g %g \n", | 
|---|
| 396 | v1->elem(991,0),v1->elem(992,0), v2->elem(991,0),v2->elem(992,0), | 
|---|
| 397 | v3->elem(991,0),v3->elem(992,0)); | 
|---|
| 398 | } | 
|---|
| 399 | break; | 
|---|
| 400 |  | 
|---|
| 401 | case 3 : | 
|---|
| 402 | { | 
|---|
| 403 | printf("\n\n Test %d operations Matrix<double>[%d] \n",N,M); | 
|---|
| 404 | Matrix<double> *v1,*v2,*v3; | 
|---|
| 405 | v1 = new Matrix<double>(Mx, My, Step, Off); | 
|---|
| 406 | v2 = new Matrix<double>(Mx, My, Step, Off); | 
|---|
| 407 | v3 = new Matrix<double>(Mx, My, Step, Off); | 
|---|
| 408 | PrtTim("Fin_Creation "); | 
|---|
| 409 |  | 
|---|
| 410 |  | 
|---|
| 411 | if (OPE == 3) { | 
|---|
| 412 | for(pos=0; pos<N; pos++) | 
|---|
| 413 | v3->AddO1(*v1, *v2); | 
|---|
| 414 | PrtTim("Fin Addition AddO1 operator [k]"); | 
|---|
| 415 | } | 
|---|
| 416 | else if (OPE == 4) { | 
|---|
| 417 | for(pos=0; pos<N; pos++) | 
|---|
| 418 | v3->MultO1(*v1, *v2); | 
|---|
| 419 | PrtTim("Fin Multiplication MultO1  operator [k]"); | 
|---|
| 420 | } | 
|---|
| 421 | else if (OPE == 5) { | 
|---|
| 422 | for(pos=0; pos<N; pos++) | 
|---|
| 423 | v3->AddO2(*v1, *v2); | 
|---|
| 424 | PrtTim("Fin Addition AddO2 operator (i,j)"); | 
|---|
| 425 | } | 
|---|
| 426 | else if (OPE == 6) { | 
|---|
| 427 | for(pos=0; pos<N; pos++) | 
|---|
| 428 | v3->MultO2(*v1, *v2); | 
|---|
| 429 | PrtTim("Fin Multiplication MultO2 operator (i,j)"); | 
|---|
| 430 | } | 
|---|
| 431 | else if (OPE == 7) { | 
|---|
| 432 | for(pos=0; pos<N; pos++) | 
|---|
| 433 | v3->Add(*v1, *v2); | 
|---|
| 434 | PrtTim("Fin Addition Add"); | 
|---|
| 435 | } | 
|---|
| 436 | else if (OPE == 8) { | 
|---|
| 437 | for(pos=0; pos<N; pos++) | 
|---|
| 438 | v3->Mult(*v1, *v2); | 
|---|
| 439 | PrtTim("Fin Multiplication Mult"); | 
|---|
| 440 | } | 
|---|
| 441 | else if (OPE == 9) { | 
|---|
| 442 | for(pos=0; pos<N; pos++) | 
|---|
| 443 | v3->AddCk(*v1, *v2); | 
|---|
| 444 | PrtTim("Fin Addition AddCk"); | 
|---|
| 445 | } | 
|---|
| 446 | else if (OPE == 10) { | 
|---|
| 447 | for(pos=0; pos<N; pos++) | 
|---|
| 448 | v3->MultCk(*v1, *v2); | 
|---|
| 449 | PrtTim("Fin Multiplication MultCk"); | 
|---|
| 450 | } | 
|---|
| 451 |  | 
|---|
| 452 |  | 
|---|
| 453 | printf("Result[1.2] D1= %g %g  D2= %g %g  D3= %g %g \n", | 
|---|
| 454 | v1->elem(1,0),v1->elem(2,0), v2->elem(1,0),v2->elem(2,0), | 
|---|
| 455 | v3->elem(1,0),v3->elem(2,0)); | 
|---|
| 456 | printf("Result[991-2] D1= %g %g  D2= %g %g  D3= %g %g \n", | 
|---|
| 457 | v1->elem(991,0),v1->elem(992,0), v2->elem(991,0),v2->elem(992,0), | 
|---|
| 458 | v3->elem(991,0),v3->elem(992,0)); | 
|---|
| 459 | } | 
|---|
| 460 | break; | 
|---|
| 461 |  | 
|---|
| 462 | default: | 
|---|
| 463 | puts("Erreur d'option !"); | 
|---|
| 464 | break; | 
|---|
| 465 | } | 
|---|
| 466 |  | 
|---|
| 467 |  | 
|---|
| 468 |  | 
|---|
| 469 | PrtTim("Fin de Matrix/C++ "); | 
|---|
| 470 | printf(" .......... Fin de MatrixC++ ........... \n"); | 
|---|
| 471 | return (0); | 
|---|
| 472 | } | 
|---|
| 473 |  | 
|---|
| 474 | /* | 
|---|
| 475 | #ifdef DECCXX | 
|---|
| 476 | #pragma define_template Matrix<int> | 
|---|
| 477 | #pragma define_template Matrix<float> | 
|---|
| 478 | #pragma define_template Matrix<double> | 
|---|
| 479 | #endif | 
|---|
| 480 |  | 
|---|
| 481 | #if defined(GNUGCC) || defined (HPaCC) | 
|---|
| 482 | template class Matrix<int>; | 
|---|
| 483 | template class Matrix<float>; | 
|---|
| 484 | template class Matrix<double>; | 
|---|
| 485 | #endif | 
|---|
| 486 |  | 
|---|
| 487 | */ | 
|---|