Exemple #1
0
int main()
{
  int i;
  vsip_cvview_d* dataEuler;
  vsip_vview_d* data;

  vsip_init((void *)0);
  dataEuler = vsip_cvcreate_d(L, VSIP_MEM_NONE);
  data = vsip_vcreate_d(L, VSIP_MEM_NONE);
  /* Make up some data */
  /* Compute a ramp from zero to 2pi */
  vsip_vramp_d(0.0, (2.0 * PI / (double) (L - 1)), data);
  /* Compute Euler */
  vsip_veuler_d(data,dataEuler);
  /* Now print out data and dataEuler */
  for(i=0; i < L; i++)
  {
    printf(" %7.4f => (%7.4f, %7.4f)\n",vsip_vget_d(data,i),
    vsip_real_d(vsip_cvget_d(dataEuler,i)),
    vsip_imag_d(vsip_cvget_d(dataEuler,i)));
  }
  /* Destroy the vector views and any associated blocks */
  vsip_blockdestroy_d(vsip_vdestroy_d(data));
  vsip_cblockdestroy_d(vsip_cvdestroy_d(dataEuler));
  vsip_finalize((void *)0);
  return 0;
}
Exemple #2
0
#include <stdio.h>
#include "vsip.h"
#define L 7                  /* length */
int main()
{
  double data[L];    /*a user-created data space */
  int i;
  vsip_vview_d* ramp;
  vsip_vview_d* output;

  vsip_init((void *)0);
  ramp = vsip_vcreate_d(L, VSIP_MEM_NONE);
  output = vsip_vbind_d(vsip_blockbind_d(data,L, VSIP_MEM_NONE),0,1,L);
  /*compute a ramp from zero to L-1*/
  vsip_vramp_d(0.0, 1.0, ramp);
  /* admit the user block with no update */
  vsip_blockadmit_d(vsip_vgetblock_d(output),VSIP_FALSE);
  /*compute the hyperbolic cosine value */
  vsip_vcosh_d(ramp, output);
  /* release the user block with update */
  vsip_blockrelease_d(vsip_vgetblock_d(output),VSIP_TRUE);
  /*print it */
  for(i=0; i<L; i++)
    printf("%f ",data[i]);
  printf("\n");
  /*destroy the vector views and any associated blocks */
  vsip_blockdestroy_d(vsip_vdestroy_d(ramp));
  vsip_blockdestroy_d(vsip_vdestroy_d(output));
  vsip_finalize((void *)0);
  return 0;
}
Exemple #3
0
int main()
{
  int i;
  vsip_scalar_d dataLeft;
  vsip_vview_d* dataRight;
  vsip_vview_d* dataSum;
  vsip_init((void *)0);
  dataRight = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataSum = vsip_vcreate_d(L, VSIP_MEM_NONE);
  /* Make up some data to find the magnitude of */
  /* First set the scalar equal to 1*/
  dataLeft = 1.0;
  /* Then compute a ramp from one to minus one */
  vsip_vramp_d(1.0, -2.0/(double)(L-1), dataRight);
  /* Add the scalar and the vector */
  vsip_svadd_d(dataLeft, dataRight, dataSum);
  /* now print out the data and its sum */
  for(i=0; i < L; i++)
    printf("%7.4f = (%7.4f) + (%7.4f) \n", vsip_vget_d(dataSum,i),
           dataLeft, vsip_vget_d(dataRight,i));
  /* destroy the vector views and any associated blocks */
  vsip_blockdestroy_d(vsip_vdestroy_d(dataRight));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataSum));
  vsip_finalize((void *)0);
  return 0;
}
int main(){vsip_init((void*)0);
{
   vsip_vview_d *a = vsip_vcreate_d(N,0),
                *r = vsip_vcreate_d(P,0);
   vsip_mview_d *B = vsip_mcreate_d(P,N,VSIP_ROW,0);
   int i, j;
   vsip_vramp_d(1.0,1.0,a);
   for(i=0;i<P;i++) for(j=0;j<N;j++)
        vsip_mput_d(B,i,j,1 + i * j);
   
   printf("\n  vector input \n");
   vsip_mvprod_d(B,a,r);
   for(j=0;j<N;j++){
        printf(" %6.2f  ",vsip_vget_d(a,j));
   }
   printf("\n");
   printf("\n matrix input \n");
   {for(i=0; i<P; i++) {for(j=0;j<N;j++){
           printf(" %6.2f  ",vsip_mget_d(B,i,j));
           }
       printf(";\n");
       }
   }
   printf("\n vector output \n");
   for(j=0;j<P;j++){
           printf("%6.2f ",vsip_vget_d(r,j));
   }
   printf("\n");
   vsip_valldestroy_d(a);
   vsip_valldestroy_d(r);
   vsip_malldestroy_d(B);
   }vsip_finalize((void*)0);return 0;
}
Exemple #5
0
int main()
{
  double data[N]; /* a user-created data space */
  int i;
  vsip_vview_d* a;
  vsip_vview_d* x;

  vsip_init((void *)0);
  a = vsip_vbind_d(vsip_blockbind_d(data,N, VSIP_MEM_NONE),0,1,N);
  x = vsip_vcreate_d(N, VSIP_MEM_NONE);
  vsip_vramp_d(0.0, 1.0, x);
  /* admit the user block with no update */
  vsip_blockadmit_d(vsip_vgetblock_d(a),VSIP_FALSE);
  /*compute the 10^x value */
  vsip_vexp10_d(x, a);
  /* release the user block with update */
  vsip_blockrelease_d(vsip_vgetblock_d(a),VSIP_TRUE);
  /*print it */
  for(i=0; i<N; i++)
    printf("%f ",data[i]);
  printf("\n");
  /*destroy the vector views and any associated blocks */
  vsip_blockdestroy_d(vsip_vdestroy_d(x));
  vsip_blockdestroy_d(vsip_vdestroy_d(a));
  vsip_finalize((void *)0);
  return 0;
}
Exemple #6
0
int main()
{
  vsip_vview_d* data;
  vsip_init((void *)0);
  data = vsip_vcreate_d(L, VSIP_MEM_NONE);
  /* Make up some data to find the sum of squares of */
  vsip_vramp_d(0.0, 1.0, data);
  printf("%f \n", vsip_vsumsqval_d(data));
  vsip_blockdestroy_d(vsip_vdestroy_d(data));
  vsip_finalize((void *)0);
  return 0;
} /* output */
Exemple #7
0
int main()
{
  vsip_vview_d *dataA;
  vsip_vview_d *dataB;
  vsip_vview_vi *Index;
  vsip_vview_bl *dataBl;
  int i;
  vsip_length N;

  vsip_init((void *)0);
  dataA = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataB = vsip_vcreate_d(L, VSIP_MEM_NONE);
  Index = vsip_vcreate_vi(L, VSIP_MEM_NONE);
  dataBl= vsip_vcreate_bl(L, VSIP_MEM_NONE);
  /* make up some data */
  vsip_vramp_d(0,2 * PI/(L-1),dataA);
  vsip_vcos_d(dataA,dataB);
  /* find out where dataB is greater than zero */
  vsip_vfill_d(0,dataA);
  vsip_vlgt_d(dataB,dataA,dataBl);
  /* find the index where dataB is greater than zero */
  if((N = vsip_vindexbool(dataBl,Index)))
  {
    /* make a vector of those points where dataB is greater than zero*/
    vsip_vgather_d(dataB,Index,vsip_vputlength_d(dataA,N));
    /*print out the results */
    printf("Index Value\n");
    for(i=0; i<N; i++)
      printf("%li %6.3f\n",
	     vsip_vget_vi(Index,i),
	     vsip_vget_d(dataA,i));
  }
  else
  {
    printf("Zero Length Index");
    exit(0);
  }
  vsip_vfill_d(0,dataB);
  vsip_vscatter_d(dataA,dataB,Index);
  for(i=0; i<L; i++)
    printf("%6.3f\n",vsip_vget_d(dataB,i));
  /*recover the data space*/
  vsip_blockdestroy_d(vsip_vdestroy_d(dataA));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataB));
  vsip_blockdestroy_vi(vsip_vdestroy_vi(Index));
  vsip_blockdestroy_bl(vsip_vdestroy_bl(dataBl));
  vsip_finalize((void *)0);
  return 0;
}
int main (){vsip_init((void*)0);
{
  int i;
  vsip_cvview_d* vector = vsip_cvcreate_d(L,0);
  vsip_vview_d* realIn = vsip_vrealview_d(vector);
  vsip_vview_d* imagIn = vsip_vimagview_d(vector);
  vsip_fft_d* fftplan = vsip_ccfftip_create_d(L,1,-1,0,0);
  vsip_fft_d* fftplanI = vsip_ccfftip_create_d(L,(double)1/L,1,0,0);
  char printDataOne[L][20],
       printDataTwo[L][30];

  /* put some data in realIn*/
  vsip_vramp_d(0, 2 * VU_PI * F, realIn);
  vsip_vcos_d(realIn,realIn);
  /* print realIn */
  for(i=0; i<L; i++){ 
       sprintf(printDataOne[i],"%2d input -> %7.4f",i, vsip_vget_d(realIn,i));
  }
  /*make sure imagIn is full of zeros*/
  vsip_vfill_d(0,imagIn);

  /*find the fft*/
  vsip_ccfftip_d(fftplan,vector);
  for(i=0; i<L; i++){
     sprintf(printDataTwo[i]," fft -> (%7.3f, %7.3f)",
           vsip_real_d(vsip_cvget_d(vector,i)),
           vsip_imag_d(vsip_cvget_d(vector,i)));
  }
  /*invert the fft*/
  vsip_ccfftip_d(fftplanI,vector);
  /*print it */
  for(i=0; i<L; i++){
     printf("%s %s  ifft -> (%7.3f, %7.3f)\n",
           printDataOne[i],
           printDataTwo[i],
           vsip_real_d(vsip_cvget_d(vector,i)),
           vsip_imag_d(vsip_cvget_d(vector,i)));
  }
 
  {
     vsip_vdestroy_d((void*)imagIn);
     vsip_vdestroy_d((void*)realIn);
     vsip_cblockdestroy_d(vsip_cvdestroy_d((void*)vector));
     vsip_fft_destroy_d((void*)fftplan);
     vsip_fft_destroy_d((void*)fftplanI);
  }
  } vsip_finalize((void*)0);return 0;
}
int main()
{
  vsip_vview_d* data;

  vsip_init((void *)0);
  data = vsip_vcreate_d(L, VSIP_MEM_NONE);
  /* Make up some data to find the mean square value of */
  /* Compute a ramp from zero to L-1 */
  vsip_vramp_d(0.0, 1.0, data);
  /* And find and print its mean square value */
  printf("%f \n",vsip_vmeansqval_d(data));
  /*destroy the vector views and any associated blocks */
  vsip_blockdestroy_d(vsip_vdestroy_d(data));
  vsip_finalize((void *)0);
  return 0;
}
Exemple #10
0
int main()
{
  int i;
  /* define some vectors */
  vsip_vview_d* dataReOne;
  vsip_vview_d* dataReTwo;
  vsip_vview_d* dataReQuotient;
  vsip_cvview_d* dataComplex;
  vsip_cvview_d* dataComplexQuotient;

  vsip_init((void *)0);
  dataReOne = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataReTwo = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataReQuotient = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataComplex = vsip_cvcreate_d(L, VSIP_MEM_NONE);
  dataComplexQuotient = vsip_cvcreate_d(L, VSIP_MEM_NONE);
  /* make up some data */
  vsip_vramp_d(1,1,dataReOne);
  vsip_vfill_d(2,dataReTwo);
  vsip_vcmplx_d(dataReTwo,dataReOne,dataComplex);

  /*divide one by two and print the input and output */
  vsip_vdiv_d(dataReOne,dataReTwo,dataReQuotient);
  for(i=0; i<L; i++)
    printf("%7.4f / %7.4f = %7.4f\n",
           vsip_vget_d(dataReOne,i), vsip_vget_d(dataReTwo,i),
           vsip_vget_d(dataReQuotient,i)); printf("\n");
  /*divide one by complex and print the input and output */
  vsip_rcvdiv_d(dataReOne,dataComplex,dataComplexQuotient);
  for(i=0; i<L; i++)
    printf("%7.4f / (%7.4f + %7.4fi) = (%7.4f + %7.4fi)\n",
           vsip_vget_d(dataReOne,i),
           vsip_real_d(vsip_cvget_d(dataComplex,i)),
           vsip_imag_d(vsip_cvget_d(dataComplex,i)),
           vsip_real_d(vsip_cvget_d(dataComplexQuotient,i)),
           vsip_imag_d(vsip_cvget_d(dataComplexQuotient,i)));
  /* destroy created objects */
  vsip_blockdestroy_d(vsip_vdestroy_d(dataReOne));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataReTwo));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataReQuotient));
  vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplex));
  vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplexQuotient));
  vsip_finalize((void *)0);
  return 0;
}
Exemple #11
0
int main()
{
  int i;
  vsip_cscalar_d z;
  vsip_scalar_d data[N]; /* a public data space for I/O */
  vsip_fft_d *rcfftNop;
  vsip_block_d *block;
  vsip_vview_d *xin;
  vsip_cvview_d *yout;

  vsip_init((void *)0);
  rcfftNop = /* Create an out-of-place Real->Cmplx N-pt FFT */
    vsip_rcfftop_create_d(N, 1.0, 1, VSIP_ALG_TIME);
  /* Create a block object and bind it to the array data */
  block = vsip_blockbind_d(data, N, VSIP_MEM_NONE);
  xin = vsip_vbind_d(block, 0, 1, N);
  /* Create another block and complex vector view for the
     symmetric output */
  yout = vsip_cvcreate_d((N/2)+1, VSIP_MEM_NONE);
  /* Admit block to VSIPL for processing and initialize with a
     linear ramp */
  vsip_blockadmit_d(block, VSIP_FALSE);
  vsip_vramp_d(0.0, 1.0, xin);
  /* Compute an out-of-place Real->Cmplx N-pt FFT using the
     rcfftNop object */
  vsip_rcfftop_d(rcfftNop, xin, yout);
  /* print it */
  printf("Real Input Vector\n");
  for(i=0; i<N; i++) 
  {
    printf("%g\n", vsip_vget_d(xin,i));
  }
  printf("\nComplex Output Vector\n");
  for(i=0; i<(N/2)+1; i++) 
  {
    z = vsip_cvget_d(yout,i);
    printf(SCMPLX "\n", ACMPLX(z));
  }
  /* Destroy the rcfftNop, blocks, and view objects */
  vsip_fft_destroy_d(rcfftNop);
  vsip_valldestroy_d(xin);
  vsip_cvalldestroy_d(yout);
  vsip_finalize((void *)0);
  return(0);
}
int main (){ vsip_init((void*)0); 
{
  int i;
  vsip_cblock_d* blockOut = vsip_cblockcreate_d(2 * L, 0);
  vsip_cvview_d* vectorOut = vsip_cvbind_d(blockOut,0,2,L);
  vsip_cvview_d* vectorIn = vsip_cvcreate_d(L,0);
  vsip_vview_d* realIn = vsip_vrealview_d(vectorIn);
  vsip_vview_d* imagIn = vsip_vimagview_d(vectorIn);
  vsip_fft_d* fftplan = vsip_ccfftop_create_d(L,1,-1,0,0);
  vsip_fft_d* fftplanI = vsip_ccfftop_create_d(L,(double)1/L,1,0,0);
  char inputdata[L][20];

  /* put some data in realIn*/
  vsip_vramp_d(0, 2 * PI * F, realIn);
  vsip_vcos_d(realIn,realIn);
  /* print realIn */
  for(i=0; i<L; i++)
       sprintf(inputdata[i],"%2d input-> %7.3f",i, vsip_vget_d(realIn,i));
  /*make sure imagIn is full of zeros*/
  vsip_vfill_d(0,imagIn);

  /*find the fft*/
  vsip_ccfftop_d(fftplan,vectorIn,vectorOut);
  /*invert the fft*/
  vsip_ccfftop_d(fftplanI,vectorOut,vectorIn);
  /*print it */
  for(i=0; i<L; i++)
     printf("%s   fft -> (%7.3f, %7.3f)   ifft -> (%7.3f, %7.3f)\n",
           inputdata[i],
           vsip_real_d(vsip_cvget_d(vectorOut,i)),
           vsip_imag_d(vsip_cvget_d(vectorOut,i)),
           vsip_real_d(vsip_cvget_d(vectorIn,i)),
           vsip_imag_d(vsip_cvget_d(vectorIn,i)));
  {
     vsip_vdestroy_d(imagIn);
     vsip_vdestroy_d(realIn);
     vsip_cblockdestroy_d(vsip_cvdestroy_d(vectorIn));
     vsip_cblockdestroy_d(vsip_cvdestroy_d(vectorOut));
     vsip_fft_destroy_d(fftplan);
     vsip_fft_destroy_d(fftplanI);
  }
  } vsip_finalize((void*)0);return 0;
}
Exemple #13
0
int main()
{
  vsip_vview_d *dataIn, *dataClip;
  vsip_init((void *)0);
  dataIn = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataClip = vsip_vcreate_d(L, VSIP_MEM_NONE);
  /* make some data */
  vsip_vramp_d(0.0, (2 * PI)/(L - 1.0), dataIn);
  vsip_vcos_d(dataIn,dataIn);
  vsip_vclip_d(dataIn,-.8,.8,-.8,.8,dataClip);
  printf("clip Cosine between -.8 and .8\n in => out\n ");
  {
    int i;
    for(i=0; i<L; i++)
      printf("%7.4f => %7.4f\n",
             vsip_vget_d(dataIn,i),vsip_vget_d(dataClip,i));
  }
  vsip_finalize((void *)0);
  return 0;
}
Exemple #14
0
int main()
{
  int i = 0;
  vsip_vview_d *dataA;
  vsip_vview_d *dataB;
  vsip_vview_d *dataMax;
  vsip_vview_d *dataMin;
  vsip_vview_d *dataRamp;

  vsip_init((void *)0);
  dataA = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataB = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataMax = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataMin = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataRamp = vsip_vcreate_d(L, VSIP_MEM_NONE);
  /* Make up some data */
  vsip_vramp_d(0.0, (2 * PI)/((double)(L-1)), dataRamp);
  vsip_vsin_d(dataRamp, dataA);
  vsip_vcos_d(dataRamp, dataB);
  /* find the Maximum Magnitde dataA or dataB*/
  vsip_vmaxmg_d(dataA,dataB,dataMax);
  vsip_vminmg_d(dataA,dataB,dataMin);
  /* print out the results */
  printf("A B Max Mag Min Mag\n");
  for(i = 0; i < L; i++)
    printf("%7.4f %7.4f %7.4f %7.4f\n",
           vsip_vget_d(dataA,i), vsip_vget_d(dataB,i),
           vsip_vget_d(dataMax,i), vsip_vget_d(dataMin,i));
  /* recover allocated memory */
  vsip_blockdestroy_d(vsip_vdestroy_d(dataA));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataB));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataMax));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataMin));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataRamp));
  vsip_finalize((void *)0);
  return 0;
}
int main(){vsip_init((void*)0);
{
    vsip_cmview_d *Adummy  = vsip_cmcreate_d(5*NN,5*NN,VSIP_COL,0);
    vsip_cmview_d *A = vsip_cmsubview_d(Adummy,3,2,NN,NN);
/*    vsip_cmview_d *A= vsip_cmcreate_d(NN,NN,VSIP_COL,0); */
    vsip_cvview_d *x0 = vsip_cvcreate_d(NN,0);
    vsip_vview_d *x0_r = vsip_vrealview_d(x0);
    vsip_vview_d *x0_i = vsip_vimagview_d(x0);
    vsip_cmview_d *X  = vsip_cmcreate_d(NN,3,VSIP_ROW,0);
    vsip_cmview_d *XT  = vsip_cmcreate_d(NN,3,VSIP_COL,0);
    vsip_cmputrowstride_d(A,2*vsip_cmgetrowstride_d(A));
    vsip_cmputcolstride_d(A,3*vsip_cmgetcolstride_d(A)); 

    /* matrix data */
    vsip_cmput_d(A,0,0,vsip_cmplx_d(0.5,0.1)); vsip_cmput_d(A,0,1,vsip_cmplx_d(7,0.1)); 
    vsip_cmput_d(A,0,2,vsip_cmplx_d(10,0.1)); vsip_cmput_d(A,0,3,vsip_cmplx_d(12,0.1));
    vsip_cmput_d(A,0,4,vsip_cmplx_d(-3,0.1)); vsip_cmput_d(A,0,5,vsip_cmplx_d(0,0.1)); vsip_cmput_d(A,0,6,vsip_cmplx_d(.05,0.1));

    vsip_cmput_d(A,1,0,vsip_cmplx_d(2,0.1)); vsip_cmput_d(A,1,1,vsip_cmplx_d(13,0.1)); 
    vsip_cmput_d(A,1,2,vsip_cmplx_d(18,0.1)); vsip_cmput_d(A,1,3,vsip_cmplx_d(6,0.1));
    vsip_cmput_d(A,1,4,vsip_cmplx_d(0,0.1)); vsip_cmput_d(A,1,5,vsip_cmplx_d(130,0.1)); vsip_cmput_d(A,1,6,vsip_cmplx_d(8,0.1));

    vsip_cmput_d(A,2,0,vsip_cmplx_d(3,0.1)); vsip_cmput_d(A,2,1,vsip_cmplx_d(-9,0.1)); 
    vsip_cmput_d(A,2,2,vsip_cmplx_d(2,0.1)); vsip_cmput_d(A,2,3,vsip_cmplx_d(3,0.2));
    vsip_cmput_d(A,2,4,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,2,5,vsip_cmplx_d(-9,0.2)); vsip_cmput_d(A,2,6,vsip_cmplx_d(6,0.2));

    vsip_cmput_d(A,3,0,vsip_cmplx_d(4,0.2)); vsip_cmput_d(A,3,1,vsip_cmplx_d(2,0.2)); 
    vsip_cmput_d(A,3,2,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,3,3,vsip_cmplx_d(4,0.2));
    vsip_cmput_d(A,3,4,vsip_cmplx_d(1,0.2)); vsip_cmput_d(A,3,5,vsip_cmplx_d(2,0.2)); vsip_cmput_d(A,3,6,vsip_cmplx_d(3,0.2));

    vsip_cmput_d(A,4,0,vsip_cmplx_d(.2,0.3)); vsip_cmput_d(A,4,1,vsip_cmplx_d(2,0.3)); 
    vsip_cmput_d(A,4,2,vsip_cmplx_d(9,0.3)); vsip_cmput_d(A,4,3,vsip_cmplx_d(4,0.3));
    vsip_cmput_d(A,4,4,vsip_cmplx_d(1,0.3)); vsip_cmput_d(A,4,5,vsip_cmplx_d(2,0.3)); 
    vsip_cmput_d(A,4,6,vsip_cmplx_d(3,0.3));

    vsip_cmput_d(A,5,0,vsip_cmplx_d(.1,0.4)); vsip_cmput_d(A,5,1,vsip_cmplx_d(2,0.4)); 
    vsip_cmput_d(A,5,2,vsip_cmplx_d(.3,0.4)); vsip_cmput_d(A,5,3,vsip_cmplx_d(4,0.4));
    vsip_cmput_d(A,5,4,vsip_cmplx_d(1,0.4)); vsip_cmput_d(A,5,5,vsip_cmplx_d(2,0.4)); vsip_cmput_d(A,5,6,vsip_cmplx_d(3,0.4));

    vsip_cmput_d(A,6,0,vsip_cmplx_d(.01,0.4)); vsip_cmput_d(A,6,1,vsip_cmplx_d(.2,0.4)); 
    vsip_cmput_d(A,6,2,vsip_cmplx_d(3,0.4)); vsip_cmput_d(A,6,3,vsip_cmplx_d(4,0.4));
    vsip_cmput_d(A,6,4,vsip_cmplx_d(1,0.4)); vsip_cmput_d(A,6,5,vsip_cmplx_d(2,0.4)); vsip_cmput_d(A,6,6,vsip_cmplx_d(3,0.4));

    { /* were solving for NTRANS Ax = B */
      /* use a known X, calculate B using Ax */
      int k; 
      vsip_cvview_d *x;
      vsip_cmview_d *AT = vsip_cmcreate_d(NN,NN,VSIP_ROW,VSIP_MEM_NONE);
      vsip_length L     = vsip_cmgetrowlength_d(X);
      vsip_cmherm_d(A,AT);
      printf("A = "); VU_cmprintm_d("7.4",A);
      printf("AT = "); VU_cmprintm_d("7.4",AT);
      vsip_vramp_d(1,1,x0_r);
      vsip_vramp_d(1,-1,x0_i);
      for(k=0; k<L; k++){
        x  = vsip_cmcolview_d(X,k);
        vsip_cmvprod_d(A,x0,x);
        vsip_rscvmul_d(2.0,x0,x0);
        vsip_cvdestroy_d(x);
      }
      vsip_vramp_d(1,1,x0_r);
      vsip_vramp_d(1,-1,x0_i);
      for(k=0; k<L; k++){
        x  = vsip_cmcolview_d(XT,k);
        vsip_cmvprod_d(AT,x0,x);
        VU_cvprintm_d("7.4",x0);
        vsip_rscvmul_d(2.0,x0,x0);
        vsip_cvdestroy_d(x);
      }
      vsip_cmalldestroy_d(AT);
      printf("B = "); VU_cmprintm_d("7.4",X);
      printf("BT = "); VU_cmprintm_d("7.4",XT);
      {
        /* then solve to see if we get X back */
        vsip_clu_d* luAop = vsip_clud_create_d(NN);
        if(luAop == NULL) exit(1);
        vsip_clud_d(luAop,A);
        {  vsip_clu_attr_d attr;
           vsip_clud_getattr_d(luAop,&attr);
           printf("lud size %lu\n",attr.n);
        }  
        vsip_clusol_d(luAop,VSIP_MAT_NTRANS,X);
        vsip_clusol_d(luAop,VSIP_MAT_HERM,XT);
        vsip_clud_destroy_d(luAop);
      }
    }
    printf("A\\X = "); VU_cmprintm_d("9.6",X);
    printf("A'\\X = "); VU_cmprintm_d("9.6",XT);
    {
       vsip_vdestroy_d(x0_r);vsip_vdestroy_d(x0_i);
       vsip_cvalldestroy_d(x0);
       vsip_cmalldestroy_d(X);
       vsip_cmalldestroy_d(A);
    }
    }vsip_finalize((void*)0);return 1;
}
int main(){vsip_init((void*)0);
{
    vsip_mview_d *A  = vsip_mcreate_d(N,N,VSIP_COL,0);
    vsip_vview_d *x0 = vsip_vcreate_d(N,0);
    vsip_vview_d *b  = vsip_vcreate_d(N,0);
    vsip_mview_d *X  = vsip_mcreate_d(N,3,VSIP_ROW,0);
    vsip_mview_d *XT  = vsip_mcreate_d(N,3,VSIP_COL,0);
    vsip_vramp_d(1,1,x0); vsip_vmul_d(x0,x0,x0);
    vsip_mput_d(A,0,0,-3); vsip_mput_d(A,0,1,7); vsip_mput_d(A,0,2,10); vsip_mput_d(A,0,3,12);
    vsip_mput_d(A,1,0,0); vsip_mput_d(A,1,1,13); vsip_mput_d(A,1,2,18); vsip_mput_d(A,1,3,6);
    vsip_mput_d(A,2,0,2); vsip_mput_d(A,2,1,-9); vsip_mput_d(A,2,2,6); vsip_mput_d(A,2,3,3);
    vsip_mput_d(A,3,0,1); vsip_mput_d(A,3,1,2); vsip_mput_d(A,3,2,3); vsip_mput_d(A,3,3,4);
    {int i,j; printf("A = [\n"); for(i=0; i<N; i++){
                  for(j=0; j<N; j++) printf("%9.2f%s",vsip_mget_d(A,i,j),(j == N-1) ? "":",");
                  printf(";\n");
              }
              printf("]\n");
    }
    { int k; 
      vsip_vview_d *x;
      vsip_length L    = vsip_mgetrowlength_d(X);
      for(k=0; k<L; k++){
        x  = vsip_mcolview_d(X,k);
        vsip_mvprod_d(A,x0,b);
        vsip_vcopy_d_d(b,x);
        vsip_svmul_d(2.0,x0,x0);
        vsip_vdestroy_d(x);
      }
    {int i,j; printf("X = [\n");for(i=0; i<N; i++){
                  for(j=0; j<3; j++) printf("%9.2f%s",vsip_mget_d(X,i,j),(j == 2) ? "":",");
                  printf(";\n");
              }
              printf("]\n");
    }
    {
      vsip_lu_d* luAop = vsip_lud_create_d(N);
      vsip_mcopy_d_d(X,XT);
      if(luAop == NULL) exit(1);
      vsip_lud_d(luAop,A);
      vsip_lusol_d(luAop,0,X);
      vsip_lusol_d(luAop,1,XT);
      vsip_lud_destroy_d(luAop);
    }
    }
    {int i,j; printf("A\\X\n"); for(i=0; i<N; i++){
                  for(j=0; j<3; j++) printf("%9.2f%s",vsip_mget_d(X,i,j),(j == 2) ? "":",");
                  printf(";\n");
              }
    }
    {int i,j; printf("A'\\X\n"); for(i=0; i<N; i++){
                  for(j=0; j<3; j++) printf("%9.2f%s",vsip_mget_d(XT,i,j),(j == 2) ? "":",");
                  printf(";\n");
              }
    }
    {
       vsip_valldestroy_d(b);
       vsip_valldestroy_d(x0);
       vsip_malldestroy_d(X);
       vsip_malldestroy_d(A);
    }
    }vsip_finalize((void*)0);return 1;
}
Exemple #17
0
void
test_corr_d(vsip_support_region support, vsip_bias bias,
            vsip_length ref_size, vsip_length input_size)
{
  vsip_length const n_loop = 3;
  vsip_length const output_size = ref_corr_output_size(support, ref_size, input_size);

  vsip_corr1d_d *corr = vsip_corr1d_create_d(ref_size, input_size, support, 0, VSIP_ALG_SPACE);
  vsip_corr1d_attr attr;
  vsip_corr1d_getattr_d(corr, &attr);

  test_assert(attr.support  == support);
  test_assert(attr.ref_len == ref_size);
  test_assert(attr.data_len == input_size);
  test_assert(attr.lag_len == output_size);

  vsip_randstate *rand = vsip_randcreate(0, 1, 1, VSIP_PRNG);

  vsip_vview_d *ref = vsip_vcreate_d(ref_size, VSIP_MEM_NONE);
  vsip_vview_d *in = vsip_vcreate_d(input_size, VSIP_MEM_NONE);
  vsip_vview_d *out = vsip_vcreate_d(output_size, VSIP_MEM_NONE);
  vsip_vfill_d(100, out);
  vsip_vview_d *chk = vsip_vcreate_d(output_size, VSIP_MEM_NONE);
  vsip_vfill_d(101, chk);

  vsip_index loop;
  for (loop=0; loop<n_loop; ++loop)
  {
    if (loop == 0)
    {
      vsip_vfill_d(1, ref);
      vsip_vramp_d(0, 1, in);
    }
    else if (loop == 1)
    {
      vsip_vrandu_d(rand, ref);
      vsip_vramp_d(0, 1, in);
    }
    else
    {
      vsip_vrandu_d(rand, ref);
      vsip_vrandu_d(rand, in);
    }

    vsip_correlate1d_d(corr, bias, ref, in, out);

    ref_corr_d(bias, support, ref, in, chk);

    double error = verror_db_d(out, chk);

#if VERBOSE
    if (error > -100)
    {
      vsip_index i;
      for (i=0; i<output_size; ++i)
      {
        printf("%d : out = %f, chk = %f\n", i, vsip_vget_d(out, i), vsip_vget_d(chk, i));
      }
      printf("error = %f\n", error);
    }
#endif

    test_assert(error < -100);
  }
}
int main(){vsip_init((void*)0);
{
    vsip_mview_d *A  = vsip_mcreate_d(N,N,VSIP_ROW,0);
    vsip_vview_d *x0 = vsip_vcreate_d(N,0);
    vsip_vview_d *b  = vsip_vcreate_d(N,0);
    vsip_mview_d *X  = vsip_mcreate_d(N,3,VSIP_ROW,0);
    vsip_mview_d *XT  = vsip_mcreate_d(N,3,VSIP_ROW,0);
    vsip_vramp_d(1,1,x0); vsip_vmul_d(x0,x0,x0);
    { int i;
      vsip_vview_d *r = vsip_mrowview_d(A,0);
      vsip_offset o = vsip_vgetoffset_d(r);
      for(i=0; i<N; i++){
          vsip_vputoffset_d(r,o);
          vsip_vramp_d(i,1,r);
          o +=N;
      }
      vsip_vdestroy_d(r);
    }
    { vsip_vview_d *r = vsip_mdiagview_d(A,0);
      vsip_vfill_d(0,r);
      vsip_vdestroy_d(r);
    }
    {int i,j; printf("A = [\n"); for(i=0; i<N; i++){
                  for(j=0; j<N; j++) printf("%9.2f%s",vsip_mget_d(A,i,j),(j == N-1) ? "":",");
                  printf(";\n");
              }
              printf("]\n");
    }
    { int k; 
      vsip_vview_d *x;
      vsip_length L    = vsip_mgetrowlength_d(X);
      for(k=0; k<L; k++){
        x  = vsip_mcolview_d(X,k);
        vsip_mvprod_d(A,x0,b);
        vsip_vcopy_d_d(b,x);
        vsip_svmul_d(2.0,x0,x0);
        vsip_vdestroy_d(x);
      }
    {int i,j; printf("X = [\n"); for(i=0; i<N; i++){
                  for(j=0; j<3; j++) printf("%9.2f%s",vsip_mget_d(X,i,j),(j == 2) ? "":",");
                  printf(";\n");
              }
              printf("]\n");
    }
      {vsip_lu_d* luAop = vsip_lud_create_d(N);
      vsip_mcopy_d_d(X,XT);
      if(luAop == NULL) exit(1);
      vsip_lud_d(luAop,A);
      vsip_lusol_d(luAop,0,X);
      vsip_lusol_d(luAop,1,XT);
      vsip_lud_destroy_d(luAop);
      }
    }
    {int i,j; printf("A\\X\n"); for(i=0; i<N; i++){
                  for(j=0; j<3; j++) printf("%9.2f%s",vsip_mget_d(X,i,j),(j == 2) ? "":",");
                  printf(";\n");
              }
    }
    {int i,j; printf("A'\\X\n"); for(i=0; i<N; i++){
                  for(j=0; j<3; j++) printf("%9.2f%s",vsip_mget_d(XT,i,j),(j == 2) ? "":",");
                  printf(";\n");
              }
    }
    {
       vsip_valldestroy_d(b);
       vsip_valldestroy_d(x0);
       vsip_malldestroy_d(X);
       vsip_malldestroy_d(A);
    }
    }vsip_finalize((void*)0);return 1;
}