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;
}
Example #2
0
int main(int argc, char *argv[]) {
    vsip_init((void*)0);
{   if(argc < 4) {
            printf("usage\nfirEx length decimation filterFile <indataFile >outputFile\n");
            exit(0);
        }
        {
            vsip_length N = (vsip_length)atoi(argv[1]);
            int D = atoi(argv[2]);
            vsip_scalar_vi n = 0,k = 0;
            vsip_scalar_d hv;
            FILE *fh;
            vsip_fir_d *fir;
            vsip_vview_d *x = vsip_vcreate_d(N,0),
                          *h,*y;
            fh = fopen(argv[3],"r");
            while(fscanf(fh,"%lf",&hv) == 1) n++;
            rewind(fh);
            y = vsip_vcreate_d(N/D + 1,0);
            h = vsip_vcreate_d(n,0);
            n=0;
            while(fscanf(fh,"%lf",&hv) == 1) {
                vsip_vput_d(h,n,hv);
                n++;
            }
            fclose(fh);
            fir = vsip_fir_create_d(h,VSIP_NONSYM,N,D,STATE,0,0);
            n = VU_scanstdin_d(x);
            while(n == N) {
                k = vsip_firflt_d(fir,x,y);
                VU_printstdout_d(y,0,k);
                n = VU_scanstdin_d(x);
            }
            if(n != 0) {
                k = vsip_firflt_d(fir,x,y);
                VU_printstdout_d(y,0,k);
            }
            {   /* test getattr */
                vsip_fir_attr attr;
                vsip_fir_getattr_d(fir,&attr);
                printf("kernel %lu\n input %lu\n output %lu\ndecimation %d\n",
                       attr.kernel_len,attr.in_len,attr.out_len, attr.decimation);
            }
            vsip_valldestroy_d(y);
            vsip_valldestroy_d(x);
            vsip_valldestroy_d(h);
            vsip_fir_destroy_d(fir);
        }
        vsip_finalize((void*)0);
        return 1;
    }
}
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;
}
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;
}
Example #5
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);
}
Example #6
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;
}
Example #7
0
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;
}
Example #8
0
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;
}
Example #9
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;
}