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