コード例 #1
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;
}
コード例 #2
0
ファイル: sadd.c プロジェクト: josephdougherty/vsipl_dda
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;
}
コード例 #3
0
void VU_opu_d(
    vsip_mview_d *A,
    vsip_vview_d *x,
    vsip_vview_d *y)
{
     vsip_length m = vsip_mgetcollength_d(A);
     vsip_length n = vsip_mgetrowlength_d(A);
     vsip_length i,j;
     for(i=0; i<m; i++)
         for(j=0; j<n; j++)
             vsip_mput_d(A,i,j,vsip_mget_d(A,i,j) + vsip_vget_d(x,i) * vsip_vget_d(y,j));
     return;
}
コード例 #4
0
ファイル: scatter.c プロジェクト: josephdougherty/vsipl_dda
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;
}
コード例 #5
0
ファイル: euler.c プロジェクト: josephdougherty/vsipl_dda
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;
}
コード例 #6
0
void VU_vprint_d(vsip_vview_d *x)
{
   vsip_length i,L = vsip_vgetlength_d(x);
   printf("[\n");
   for(i=0; i<L; i++)
      printf("%6.4f%s\n",vsip_vget_d(x,i),((i == (L-1)) ? ";" : "]"));
   return;
}
コード例 #7
0
ファイル: div.c プロジェクト: josephdougherty/vsipl_dda
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;
}
コード例 #8
0
void VU_vfprintyg_d(char* format, vsip_vview_d* a,char* fname)
{   vsip_length N = vsip_vgetlength_d(a);
    vsip_length i;
    FILE *of = fopen(fname,"w");
    for(i=0; i<N; i++)
           fprintf(of,format, vsip_vget_d(a,i));
    fclose(of);
    return;
}
コード例 #9
0
ファイル: copyToList.c プロジェクト: rrjudd/jvsip
PyObject *vcopyToList_d(vsip_vview_d *v){
    vsip_length N = vsip_vgetlength_d(v);
    PyObject *retval = PyList_New(N);
    vsip_index i;
    for(i=0; i<N; i++){
       double x = (double)vsip_vget_d(v,i);
       PyList_SetItem(retval,i,PyFloat_FromDouble(x));
    }
    return retval;
}
コード例 #10
0
ファイル: clip.c プロジェクト: josephdougherty/vsipl_dda
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;
}
コード例 #11
0
ファイル: maxmg.c プロジェクト: josephdougherty/vsipl_dda
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;
}
コード例 #12
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;
}
コード例 #13
0
ファイル: rcfftop.c プロジェクト: josephdougherty/vsipl_dda
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);
}
コード例 #14
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;
}
コード例 #15
0
ファイル: correlation.c プロジェクト: fsheikh/openvsip
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);
  }
}