示例#1
0
文件: ssdiv.c 项目: ssacco/specs
int main()
{
    int i;
    /* define some data space */
    vsip_cvview_d* dataComplex;
    vsip_cvview_d* dataComplexQuotient;

    vsip_init((void *)0);
    dataComplex = vsip_cvcreate_d(L, VSIP_MEM_NONE);
    dataComplexQuotient = vsip_cvcreate_d(L, VSIP_MEM_NONE);
    /* put some complex data in dataComplex */
    for(i = 0; i < L; i++)
        vsip_cvput_d(dataComplex,i,
                     vsip_cmplx_d((double)(i * i),(double)(i+1)));
    /*divide dataComplex by some denom and print the input and output */
    vsip_cvrsdiv_d(dataComplex,denom,dataComplexQuotient);
    for(i=0; i<L; i++)
        printf("(%7.4f + %7.4fi) / %7.4f) = (%7.4f + %7.4fi)\n",
               vsip_real_d(vsip_cvget_d(dataComplex,i)),
               vsip_imag_d(vsip_cvget_d(dataComplex,i)),
               denom,
               vsip_real_d(vsip_cvget_d(dataComplexQuotient,i)),
               vsip_imag_d(vsip_cvget_d(dataComplexQuotient,i)));
    vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplex));
    vsip_cblockdestroy_d(vsip_cvdestroy_d(dataComplexQuotient));
    vsip_finalize((void *)0);
    return 0;
}
示例#2
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;
}
示例#3
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;
}
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;
}
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;
}
static vsip_cmview_d* VU_cI_d(vsip_length M)
{
  vsip_cmview_d *I = vsip_cmcreate_d(M,M,VSIP_ROW,VSIP_MEM_NONE);
  if(I != NULL){
      vsip_cvview_d *row = vsip_cmrowview_d(I,0);
      if(row != NULL){
          vsip_cvputlength_d(row,(vsip_length)(M * M));
          vsip_cvfill_d(vsip_cmplx_d(0.0,0.0),row);
          vsip_cvputlength_d(row,M);
          vsip_cvputstride_d(row,(vsip_stride) (M + 1));
          vsip_cvfill_d(vsip_cmplx_d(1.0,0.0),row);
          vsip_cvdestroy_d(row);
      } else {
          vsip_cmdestroy_d(I);
          return (vsip_cmview_d*) NULL;
      }
   } else {
      return (vsip_cmview_d*) NULL;
   }
   return I;
}
示例#7
0
void
ref_ccorr_d(vsip_bias bias, vsip_support_region sup,
            vsip_cvview_d const *ref,
            vsip_cvview_d const *in,
            vsip_cvview_d const *out)
{
  vsip_length M = vsip_cvgetlength_d(ref);
  vsip_length N = vsip_cvgetlength_d(in);
  vsip_length P = vsip_cvgetlength_d(out);
  vsip_length expected_P = ref_corr_output_size(sup, M, N);
  vsip_stride shift      = ref_expected_shift(sup, M);

  assert(expected_P == P);

  vsip_cvview_d *sub = vsip_cvcreate_d(M, VSIP_MEM_NONE);

  // compute correlation
  vsip_index i;
  for (i=0; i<P; ++i)
  {
    vsip_cvfill_d(vsip_cmplx_d(0,0), sub);
    vsip_stride pos = (vsip_stride)i + shift;
    double scale;
    if (pos < 0)
    {
      vsip_cvview_d *subsub = vsip_cvsubview_d(sub, -pos, M + pos);
      vsip_cvview_d *insub = vsip_cvsubview_d(in, 0, M + pos);
      vsip_cvcopy_d_d(insub, subsub);
      vsip_cvdestroy_d(subsub);
      vsip_cvdestroy_d(insub);
      scale = M + pos;
    }
    else if (pos + M > N)
    {
      vsip_cvview_d *subsub = vsip_cvsubview_d(sub, 0, N - pos);
      vsip_cvview_d *insub = vsip_cvsubview_d(in, pos, N - pos);
      vsip_cvcopy_d_d(insub, subsub);
      vsip_cvdestroy_d(subsub);
      vsip_cvdestroy_d(insub);
      scale = N - pos;
    }
    else
    {
      vsip_cvview_d *insub = vsip_cvsubview_d(in, pos, M);
      vsip_cvcopy_d_d(insub, sub);
      vsip_cvdestroy_d(insub);
      scale = M;
    }

#if VSIP_IMPL_CORR_CORRECT_SAME_SUPPORT_SCALING
#else
    if (sup == VSIP_SUPPORT_SAME)
    {
      if      (i < (M/2))     scale = i + (M+1)/2;         // i + ceil(M/2)
      else if (i < N - (M/2)) scale = M;                   // M
      else                    scale = N - 1 + (M+1)/2 - i; // N-1+ceil(M/2)-i
    }
#endif
      
    vsip_cscalar_d val = vsip_cvjdot_d(ref, sub);
    if (bias == VSIP_UNBIASED)
    {
      val.r /= scale;
      val.i /= scale;
    }
    vsip_cvput_d(out, i, val);
  }
}
示例#8
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;
}
示例#9
0
void (vsip_cvalldestroy_d)(
  vsip_cvview_d* v) {	/* vector view  destructor*/
  vsip_cblockdestroy_d(vsip_cvdestroy_d(v));
  }