Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #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;
}
void VU_vfreqswapIP_d(vsip_vview_d* b)
{   vsip_length N = vsip_vgetlength_d(b);
    if(N%2){/* odd */
       vsip_vview_d *a1 = vsip_vsubview_d(b,
                 (vsip_index)(N/2)+1,
                 (vsip_length)(N/2));
       vsip_vview_d *a2 = vsip_vsubview_d(b,
                 (vsip_index)0,
                 (vsip_length)(N/2)+1);
       vsip_vview_d *a3 = vsip_vcreate_d((vsip_length)(N/2)+1,
                          VSIP_MEM_NONE);
       vsip_vcopy_d_d(a2,a3);
       vsip_vputlength_d(a2,(vsip_length)(N/2));
       vsip_vcopy_d_d(a1,a2);
       vsip_vputlength_d(a2,(vsip_length)(N/2) + 1);
       vsip_vputoffset_d(a2,(vsip_offset)(N/2));
       vsip_vcopy_d_d(a3,a2);
       vsip_vdestroy_d(a1); vsip_vdestroy_d(a2);
       vsip_valldestroy_d(a3);
    }else{ /* even */
       vsip_vview_d *a1 = vsip_vsubview_d(b,
                 (vsip_index)(N/2),
                 (vsip_length)(N/2));
       vsip_vputlength_d(b,(vsip_length)(N/2));
       vsip_vswap_d(b,a1);
       vsip_vdestroy_d(a1);
       vsip_vputlength_d(b,N);
    }
    return;
}
Beispiel #5
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;
}
Beispiel #7
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;
}
int main(){vsip_init((void*)0);
{
     void VU_vfprintyg_d(char*,vsip_vview_d*,char*);
     void VU_vfreqswapIP_d(vsip_vview_d*);
     vsip_vview_d* Cw = vsip_vcreate_cheby_d(Nlength,ripple,0);
     vsip_fft_d *fft  = vsip_ccfftip_create_d(Nlength,1.0,VSIP_FFT_FWD,0,0);
     vsip_cvview_d* FCW = vsip_cvcreate_d(Nlength,0);
     /*printf("CW = "); VU_vprintm_d("%6.8f ;\n",Cw); */
     VU_vfprintyg_d("%6.8f\n",Cw,"Cheby_Window");
     vsip_cvfill_d(vsip_cmplx_d(0,0),FCW);
     { vsip_vview_d *rv = vsip_vrealview_d(FCW);
       vsip_vcopy_d_d(Cw,rv);
       vsip_ccfftip_d(fft,FCW);
       vsip_vcmagsq_d(FCW,rv);
       { vsip_index ind;
         vsip_scalar_d max = vsip_vmaxval_d(rv,&ind);
         vsip_scalar_d min = max/(10e12);
         vsip_vclip_d(rv,min,max,min,max,rv);
       } 
       vsip_vlog10_d(rv,rv);
       vsip_svmul_d(10,rv,rv);
       VU_vfreqswapIP_d(rv);
         VU_vfprintyg_d("%6.8f\n",rv,"Cheby_Window_Frequency_Response");
       vsip_vdestroy_d(rv);
     }
     vsip_fft_destroy_d(fft);
     vsip_valldestroy_d(Cw);
     vsip_cvalldestroy_d(FCW);
     } vsip_finalize((void*)0); return 0;
}
Beispiel #9
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;
}
Beispiel #11
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 */
Beispiel #12
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;
}
Beispiel #13
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;
}
int main(){vsip_init((void*)0);
{
   void VU_mprint_d(vsip_mview_d*);
   void VU_mfill_d(vsip_mview_d*, vsip_scalar_d);
   void VU_vprint_d(vsip_vview_d*);
   vsip_mview_d *A   = vsip_mcreate_d(M,N,VSIP_ROW,0);
   vsip_mview_d *ATA = vsip_mcreate_d(N,N,VSIP_ROW,0);
   vsip_vview_d *b   = vsip_vcreate_d(M,0);
   vsip_mview_d *ATB = vsip_mcreate_d(N,1,VSIP_COL,0);
   vsip_vview_d *ATb = vsip_mcolview_d(ATB,0);
   { /* store data */
     vsip_mput_d(A,0,0,1); vsip_mput_d(A,0,1,2); vsip_mput_d(A,0,2,1);
     vsip_mput_d(A,1,0,3); vsip_mput_d(A,1,1,-1); vsip_mput_d(A,1,2,0);
     vsip_mput_d(A,2,0,2); vsip_mput_d(A,2,1,1); vsip_mput_d(A,2,2,-1);
     vsip_mput_d(A,3,0,1); vsip_mput_d(A,3,1,2); vsip_mput_d(A,3,2,2);
     vsip_vput_d(b,0,1);
     vsip_vput_d(b,1,2);
     vsip_vput_d(b,2,2);
     vsip_vput_d(b,3,1);
   }
   printf("b = \n");VU_vprint_d(b);
   printf("A = \n");VU_mprint_d(A);
   VU_mfill_d(ATA,0);
   vsip_gemp_d(1,A,VSIP_MAT_TRANS,A,VSIP_MAT_NTRANS,1,ATA);
   printf("ATA = \n");VU_mprint_d(ATA);
   vsip_vmprod_d(b,A,ATb);
   printf("ATb = \n"); VU_vprint_d(ATb);
   {
      vsip_lu_d* luAop = vsip_lud_create_d(N);
      vsip_lud_d(luAop,ATA);
      vsip_lusol_d(luAop,VSIP_MAT_NTRANS,ATB);
      printf("solve ATA x = ATb\n");
      printf("x = \n"); VU_mprint_d(ATB);
      vsip_lud_destroy_d(luAop);
   }
   vsip_valldestroy_d(b);
   vsip_vdestroy_d(ATb);
   vsip_mdestroy_d(A);
   vsip_mdestroy_d(ATA);
   vsip_mdestroy_d(ATB);
   }vsip_finalize((void*)0);return 0;
}
vsip_mview_d* VU_I_d(vsip_length M)
{
  vsip_mview_d *I = vsip_mcreate_d(M,M,VSIP_ROW,VSIP_MEM_NONE);
  if(I != NULL){
      vsip_vview_d *row = vsip_mrowview_d(I,0);
      if(row != NULL){
          vsip_vputlength_d(row,(vsip_length)(M * M));
          vsip_vfill_d((vsip_scalar_d)0.0,row);
          vsip_vputlength_d(row,M);
          vsip_vputstride_d(row,(vsip_stride) (M + 1));
          vsip_vfill_d((vsip_scalar_d)1.0,row);
          vsip_vdestroy_d(row);
      } else {
          vsip_mdestroy_d(I);
          return (vsip_mview_d*) NULL;
      }
   } else {
      return (vsip_mview_d*) NULL;
   }
   return I;
}
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;
}
Beispiel #17
0
void
ref_corr_d(vsip_bias bias, vsip_support_region sup,
           vsip_vview_d const *ref,
           vsip_vview_d const *in,
           vsip_vview_d const *out)
{
  vsip_length M = vsip_vgetlength_d(ref);
  vsip_length N = vsip_vgetlength_d(in);
  vsip_length P = vsip_vgetlength_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_vview_d *sub = vsip_vcreate_d(M, VSIP_MEM_NONE);

  // compute correlation
  vsip_index i;
  for (i=0; i<P; ++i)
  {
    vsip_vfill_d(0, sub);
    vsip_stride pos = (vsip_stride)i + shift;
    double scale;
    if (pos < 0)
    {
      vsip_vview_d *subsub = vsip_vsubview_d(sub, -pos, M + pos);
      vsip_vview_d *insub = vsip_vsubview_d(in, 0, M + pos);
      vsip_vcopy_d_d(insub, subsub);
      vsip_vdestroy_d(subsub);
      vsip_vdestroy_d(insub);
      scale = M + pos;
    }
    else if (pos + M > N)
    {
      vsip_vview_d *subsub = vsip_vsubview_d(sub, 0, N - pos);
      vsip_vview_d *insub = vsip_vsubview_d(in, pos, N - pos);
      vsip_vcopy_d_d(insub, subsub);
      vsip_vdestroy_d(subsub);
      vsip_vdestroy_d(insub);
      scale = N - pos;
    }
    else
    {
      vsip_vview_d *insub = vsip_vsubview_d(in, pos, M);
      vsip_vcopy_d_d(insub, sub);
      vsip_vdestroy_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
      
    double val = vsip_vdot_d(ref, sub);
    if (bias == VSIP_UNBIASED) val /= scale;
    vsip_vput_d(out, i, val);
  }
}
int main(){vsip_init((void*)0);
{
    void VU_cmprint_d(vsip_cmview_d*);
 /*   int i;*/
    vsip_cmview_d *w = vsip_cmcreate_d(5,L+1,VSIP_ROW,0);
    vsip_cmview_d *W = vsip_cmcreate_d(5,L+1,VSIP_ROW,0);
    vsip_cmview_d *IW = vsip_cmcreate_d(5,L+1,VSIP_ROW,0);
    vsip_vview_d *blackman = vsip_vcreate_blackman_d(L,0),
                 *hanning  = vsip_vcreate_hanning_d(L,0),
                 *kaiser   = vsip_vcreate_kaiser_d(L,beta,0),
                 *cheby    = vsip_vcreate_cheby_d(L,ripple,0);
    vsip_fftm_d *fft = vsip_ccfftmop_create_d(4,L,1,VSIP_FFT_FWD,VSIP_ROW,0,0);
    vsip_fftm_d *ifft = vsip_ccfftmop_create_d(4, L, 1.0/L, VSIP_FFT_INV, VSIP_ROW,0,0);
    /*printf("  blackman ");
    printf("     hanning      kaiser       chebyshev\n");
    for(i=0; i < L; i++)
       printf("%11.8f; %11.8f; %11.8f; %11.8f\n", 
              vsip_vget_d(blackman,i),
              vsip_vget_d(hanning,i),
              vsip_vget_d(kaiser,i),
              vsip_vget_d(cheby,i)); */
    vsip_cmputcollength_d(w,4);
    vsip_cmputcollength_d(W,4);
    vsip_cmputcollength_d(IW,4);
    vsip_cmputrowlength_d(w,L);
    vsip_cmputrowlength_d(W,L);
    vsip_cmputrowlength_d(IW,L);
    {
       vsip_mview_d *wR = vsip_mrealview_d(w);
       vsip_mview_d *wI = vsip_mimagview_d(w);
       vsip_vview_d *v  = vsip_mrowview_d(wR,0);
       vsip_vview_d *vi  = vsip_mrowview_d(wI,0);
       vsip_offset o = (vsip_offset)vsip_mgetcolstride_d(wR);
       vsip_offset oi = (vsip_offset)vsip_mgetcolstride_d(wI);
       vsip_vcopy_d_d(blackman,v);
       vsip_vfill_d(0,vi);
       vsip_vputoffset_d(v,vsip_vgetoffset_d(v) + o);
       vsip_vputoffset_d(vi,vsip_vgetoffset_d(vi) + oi);
       vsip_vcopy_d_d(hanning,v);
       vsip_vfill_d(0,vi);
       vsip_vputoffset_d(v,vsip_vgetoffset_d(v) + o);
       vsip_vputoffset_d(vi,vsip_vgetoffset_d(vi) + oi);
       vsip_vcopy_d_d(kaiser,v);
       vsip_vfill_d(0,vi);
       vsip_vputoffset_d(v,vsip_vgetoffset_d(v) + o);
       vsip_vputoffset_d(vi,vsip_vgetoffset_d(vi) + oi);
       vsip_vcopy_d_d(cheby,v);
       vsip_vfill_d(0,vi);
       vsip_mdestroy_d(wR);
       vsip_vdestroy_d(v);
       vsip_mdestroy_d(wI);
       vsip_vdestroy_d(vi);
    }
    vsip_ccfftmop_d(fft,w,W);
    vsip_ccfftmop_d(ifft,W,IW);
    printf(" w = ");VU_cmprint_d(w);
    printf(" W = ");VU_cmprint_d(W);
    printf("IW = ");VU_cmprint_d(IW);
    {/* test vsip_fftm_getattr_d */
        vsip_fftm_attr_d attr;
        vsip_fftm_getattr_d(fft, &attr);
        printf("%lu %lu %lu %lu %d %f %d %d\n",
        vsip_rowindex(attr.input),
        vsip_colindex(attr.input),
        vsip_rowindex(attr.output),
        vsip_colindex(attr.output),
        attr.place,attr.scale,attr.dir,attr.major);
        vsip_fftm_getattr_d(ifft, &attr);
        printf("%lu %lu %lu %lu %d %f %d %d\n",
        vsip_rowindex(attr.input),
        vsip_colindex(attr.input),
        vsip_rowindex(attr.output),
        vsip_colindex(attr.output),
        attr.place,attr.scale,attr.dir,attr.major);
    }
    vsip_fftm_destroy_d(fft); 
    vsip_fftm_destroy_d(ifft); 
    vsip_valldestroy_d(blackman);
    vsip_valldestroy_d(hanning); 
    vsip_valldestroy_d(kaiser); 
    vsip_valldestroy_d(cheby);  
    vsip_cmalldestroy_d(w); 
    vsip_cmalldestroy_d(W); 
    vsip_cmalldestroy_d(IW); 
    }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;
}
Beispiel #20
0
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;
}