#include <stdio.h>
#include <iostream>
#include "sopnamsp.h"
#include "srandgen.h"
#include "timing.h"
#include "cimage.h"
#include "ntoolsinit.h"
// Test des NDataBlock
#include "ndatablock.h"

#include "blitz/array.h"
using namespace blitz ;

main(int narg, char *arg[])
{
SophyaInit();
InitTim();

char strg[128];
int N1,N2, k, kk, i, j;
N1 = 1;
N2 = 10;
if (narg > 1)  N1 = atoi(arg[1]);
if (narg > 2)  N2 = atoi(arg[2]);

cout << N1 << " Tests avec " << N2 << " multiplications" << endl; 

int sx = 300;
int sy = 200;

ImageR4  img(sx, sy), i2(sx, sy), ir(sx, sy);
for(kk=0; kk<N1; kk++) {
  cout << kk << " - Remplissage image (" << sx << "x" << sy << ") , " << N2 << " mult. " << endl;
  for(i=0; i<sx; i++)
    for(j=0; j<sy; j++) img(i,j) = frand01()*10.*j+20.*i;
  for(i=0; i<sx; i++)
    for(j=0; j<sy; j++) i2(i,j) =  frand01()*10.*j+20.*i;

  for(k=0; k<N2; k++) ir = img * i2;
  sprintf(strg, "Img T[%d] ", kk);
  PrtTim(strg);
}


 cout << "\n ====  Test avec Blitz++ " << endl;

Array<float,2> a1(sy, sx), a2(sy, sx), a3(sy, sx);
firstIndex ii;
secondIndex jj;

for(kk=0; kk<N1; kk++) {
  cout << kk << " BlitzArray (" << sx << "x" << sy << ") , " << N2 << " mult. " << endl;
  a1 = frand01()*10.*jj+20.*ii;
  a2 = frand01()*10.*jj+20.*ii;
  for(k=0; k<N2; k++) a3 = a1*a2;
  sprintf(strg, "Blitz-Array T[%d] ", kk);
  PrtTim(strg);
}

 cout << "\n ====  Test avec NDataBlock<float> " << endl;
NDataBlock<r_4> b1(sx*sy), b2(sx*sy), b3(sx*sy);
for(kk=0; kk<N1; kk++) {
  cout << kk << " NDataBlock<float> (" << sx*sy <<  ") , " << N2 << " mult. " << endl;
  for(k=0; k<sx*sy; k++) {
    b1(k) = frand01()*10.*k;
    b2(k) = frand01()*10.*k;
    }
  for(k=0; k<N2; k++) b3 = b1*b2;
  sprintf(strg, "NDataBlock<float> T[%d] ", kk);
  PrtTim(strg);
}

exit(0);
}
