Пример #1
0
void VU_cmconjIP_f(vsip_cmview_f *R)
{
    vsip_cvview_f *R_row = vsip_cmrowview_f(R,0);
    vsip_length MR       = vsip_cmgetcollength_f(R);
    vsip_stride Rcs      = vsip_cmgetcolstride_f(R);
    vsip_offset offset   = vsip_cmgetoffset_f(R);
    while(MR-- > 1){
         vsip_cvconj_f(R_row,R_row);
         offset += Rcs;
         vsip_cvputoffset_f(R_row,offset);
   }vsip_cvconj_f(R_row,R_row);
   vsip_cvdestroy_f(R_row);
}         
void VU_cmprodqh_f(
     vsip_cmview_f *C,
     vsip_cmview_f *H,
     vsip_scalar_f *beta)
{
     vsip_cmattr_f attr_C,attr_C0;
     vsip_cmattr_f attr_H0;
     vsip_cvattr_f attr_h,attr_v0;
     vsip_cvview_f *h = vsip_cmcolview_f(H,0);
     vsip_length m,n;
     vsip_length j;
     vsip_stride k;
     vsip_cvview_f *v, *w;
     vsip_cmgetattrib_f(C,&attr_C);
     vsip_cvgetattrib_f(h,&attr_h);
     vsip_cmgetattrib_f(H,&attr_H0);
     attr_C0 = attr_C;
     m = attr_C.col_length;
     n = attr_C.row_length;
     v = vsip_cvcreate_f(n,0);
     vsip_cvgetattrib_f(v,&attr_v0);
     w = vsip_cvcreate_f(m,0);
     vsip_cvfill_f(vsip_cmplx_f(0,0),v);
     for(k= attr_H0.row_length - 1; k >= 0; k--){
         j = (vsip_length)k;
         attr_h.offset = j * attr_H0.row_stride +
                         j * attr_H0.col_stride + attr_H0.offset;
         attr_h.length = attr_H0.col_length - j;
         vsip_cvputlength_f(v,attr_h.length);
         vsip_cvputoffset_f(v,n - attr_h.length);
         vsip_cvputattrib_f(h,&attr_h);
         vsip_cvcopy_f_f(h,v);
         vsip_cvput_f(v,0,vsip_cmplx_f(1,0));
         vsip_cvputattrib_f(v,&attr_v0);
         VU_rscmvprod_f(-beta[j],C,v,w);
         VU_copuh_f(C,w,v);              
     }
     vsip_cmputattrib_f(C,&attr_C0);
     vsip_cvdestroy_f(h);
     vsip_cvalldestroy_f(v);
     vsip_cvalldestroy_f(w);
     return;
}
Пример #3
0
int main(int argc, char **argv)
{
    vsip_scalar_f userArray[2*N];
    vsip_cblock_f *blk;
    vsip_cvview_f *vw;
    vsip_dda_cvdata_f *data;
    vsip_dda_cvdataattr_f attrib;
    vsip_cscalar_f *arrayPtr;
    vsip_scalar_f *interPtr;
    vsip_scalar_f *splitRealPtr, *splitImagPtr;
    vsip_scalar_f *data1ptr, *data2ptr;    
    vsip_init((void *)0);   
    blk = vsip_cblockbind_f(&userArray[0], 0, N, VSIP_MEM_NONE);
        /* TODO: Handle error */
    /* NOTE
     * The block bind call above implies an INTERLEAVED storage format in the
     * user array, but once admitted, the implementation may use a different
     * storage format.
     */
    vsip_cblockadmit_f(blk, 0); /* TODO: Handle error */
    vw = vsip_cvbind_f(blk, 0, 1, N); /* TODO: Handle error */
    /* NOTE
     * No layout is provided when the data object is created, so the view's own
     * layout is used.
     */             
    data = vsip_dda_cvdatacreate_f(vw, 0, VSIP_DDA_SYNC_POLICY_OUT, 0);
    /* TODO: Handle error */
    vsip_dda_cvdatagetattrib_f(data, &attrib); /* TODO: Handle error */   
    /* NOTE
     * Since the layout of the data object is not specified, the data object
     * attributes must retrieved, and the storage format checked, to determine
     * which complex pointer accessor to use.
     */    
    if(VSIP_STORAGE_FORMAT_ARRAY == attrib.layout->storage_format)
    {        
        arrayPtr = vsip_dda_cvptr_as_array_f(data); /* TODO: Handle error */
        arrayPtr[0].r = 1.0F; arrayPtr[0].i = -1.0F;
    }
    else if(VSIP_STORAGE_FORMAT_INTERLEAVED_COMPLEX
        == attrib.layout->storage_format)
    {
        interPtr = vsip_dda_cvptr_as_inter_f(data); /* TODO: Handle error */
        interPtr[0] = 1.0F; interPtr[1] = -1.0F;       
    }
    else if(VSIP_STORAGE_FORMAT_SPLIT_COMPLEX == attrib.layout->storage_format)
    {
        vsip_dda_cvptr_as_split_f(data, &splitRealPtr, &splitImagPtr);
            /* TODO: Handle error */
        splitRealPtr[0] = 1.0F; splitImagPtr[0] = -1.0F;
    }
    vsip_dda_cvdatadestroy_f(data); /* TODO: Handle error */
    /* NOTE
     * Because of the OUT synchronization policy, the proxied view will have
     * been updated with the contents of any DDA buffers.
     */
    vsip_cvdestroy_f(vw); /* TODO: Handle error */
    vsip_cblockrelease_f(blk, 1, &data1ptr, &data2ptr); /* TODO: Handle error */
    vsip_cblockdestroy_f(blk);
    vsip_finalize((void *)0);
    return 0;
}
Пример #4
0
int main(){vsip_init((void*)0);
{
    int i,j, solretval=0;
    vsip_cmview_f *A  = vsip_cmcreate_f(M,N,VSIP_COL,0);
    vsip_cmview_f *X  = vsip_cmcreate_f(M,NB,VSIP_ROW,0);

    /* Nullify the data-space */
    for (i=0; i <  vsip_cmgetcollength_f(A); i++)
      for(j=0; j < vsip_cmgetrowlength_f(A); j++)
        vsip_cmput_f(A,i,j,vsip_cmplx_f(0,0));

    for (i=0; i <  vsip_cmgetcollength_f(X); i++)
      for(j=0; j <  vsip_cmgetrowlength_f(X); j++)
        vsip_cmput_f(X,i,j,vsip_cmplx_f(0,0));

    /* Initialise matrix A */
    for (i=0; i<M; i++)
      for (j = 0; j < N; j++)
	if(i == j) 
          vsip_cmput_f(A,i,j,vsip_cmplx_f(M+1, 0));
        else if(i > j)
          vsip_cmput_f(A,i,j, vsip_cmplx_f(1,1));
        else if(i < j)
          vsip_cmput_f(A,i,j,vsip_cmplx_f(1,-1));


    {int i,j; 
    printf("A matrix\nA = [\n");
    for(i=0; i<M; i++)
      {
	for(j=0; j< N; j++) 
	  printf("%6.2f+%6.2fi%s",
                     vsip_real_f(vsip_cmget_f(A,i,j)),
                     vsip_imag_f(vsip_cmget_f(A,i,j)),(j == N-1) ? "":",");
                   (i == M - 1) ? printf("]\n") : printf(";\n");
      }
    }
    { int j, k; 
    vsip_cvview_f *y = NULL;
    vsip_cvview_f *x;
    vsip_vview_f *yr = NULL, *yi = NULL;

    vsip_length L    = NB;
    vsip_length p    = M;
    for(k=0; k<L; k++)
      {
        x  = vsip_cmcolview_f(X,k);
	for (j=0; j<p; j++)
	  {
	    y  = vsip_cmrowview_f(A,j);
            yr = vsip_vrealview_f(y);
            yi = vsip_vimagview_f(y);
	    vsip_cvput_f(x,j, vsip_cmplx_f((double)(k+1)*(vsip_vsumval_f(yr)),
                             (double) (k+1)*(vsip_vsumval_f(yi))));
	    /* vsip_vput_f(x,j,(vsip_vsumval_f(y)));*/
	   vsip_cvdestroy_f(y);
           vsip_vdestroy_f(yr);
           vsip_vdestroy_f(yi);
	  }
        vsip_cvdestroy_f(x);
      }
    }
    {int i,j; 
    printf("rhs matrix\nB = [\n");
    for(i=0; i<NN; i++)
      {
	for(j=0; j<NB; j++) 
	  printf("%7.2f+%7.2fi%s",
                     vsip_real_f(vsip_cmget_f(X,i,j)),
                     vsip_imag_f(vsip_cmget_f(X,i,j)),(j == NB-1) ? "":",");
                   (i == NN - 1) ? printf("]\n") : printf(";\n");
      }
    }
    {vsip_cqr_f* qrAop = vsip_cqrd_create_f(M,N, QOPT);
    if(qrAop == NULL) exit(1);

    {int i,j;
    printf("matrix A after factorisation\n R/Q -- \n");
    if(QOPT == VSIP_QRD_SAVEQ1)
    {
      printf("qrd } returns %i\n",vsip_cqrd_f(qrAop,A));      
      printf("matrix A after factorisation: skinny Q explicitly\n Q1 = [\n");
      for(i= 0; i< M ; i++)
        {
          for(j=0; j< N; j++)
            printf("%8.4f+%8.4fi%s",
                     vsip_real_f(vsip_cmget_f(A,i,j)),
                     vsip_imag_f(vsip_cmget_f(A,i,j)),(j == N-1) ? "":",");
                   (i == M - 1) ? printf("]\n") : printf(";\n");
        }

    } else if(QOPT == VSIP_QRD_SAVEQ || QOPT == VSIP_QRD_NOSAVEQ)
    {
      printf("qrd returns %i\n",vsip_cqrd_f(qrAop,A));
      printf("matrix A after fact.: R and ");
	(QOPT == VSIP_QRD_SAVEQ) ?  printf("full Q implicitly\n Q/R = [\n") :
			printf("Q not saved -- ignore LT portion. \n R = [\n");
      for(i= 0; i<M ; i++)
	{
	  for(j=0; j< N; j++)
	    printf("%9.5f+%9.5fi%s",
                     vsip_real_f(vsip_cmget_f(A,i,j)),
                     vsip_imag_f(vsip_cmget_f(A,i,j)),(j == N-1) ? "":",");
                   (i == M - 1) ? printf("]\n") : printf(";\n"); 
	}
    }
    }
    if( QPROB == VSIP_LLS)
    {
       if (QOPT == VSIP_QRD_SAVEQ1 || QOPT == VSIP_QRD_SAVEQ)
       {
	  if((solretval=vsip_cqrsol_f(qrAop, QPROB, X)))
	  {
	    printf("WARNING -- Least Squares soln returns %i-- CHECK\n", 
		   solretval);	    
	    printf("Upper triang. mat. R, possibly singular\n");
	  }
	  else
	    printf("Least Squares soln returns %i\n", solretval);
       }
       else
	 {
	 printf("Least Squares systems cannot be solved by the NOSAVEQ option -- exiting\n");
	 exit(1);
	 }
       }
    else
      {
      if((solretval=vsip_cqrsol_f(qrAop,QPROB, X)))
      {
	printf("Covariance soln returns %i\n",solretval);
	printf("Upper triang. mat. R, possibly singular\n");
      }
      else
      printf("Covariance soln returns %i\n",solretval);
    }
    vsip_cqrd_destroy_f(qrAop);
    }

    {int i,j;
    printf("Soln Matrix\nX = [\n");
      for(i=0; i<N; i++)
	{
	  for(j=0; j<NB; j++) 
	    printf("%9.5f+%9.5fi%s",
                     vsip_real_f(vsip_cmget_f(X,i,j)),
                     vsip_imag_f(vsip_cmget_f(X,i,j)),(j == NB-1) ? "":",");
                   (i == N - 1) ? printf("]\n") : printf(";\n");
	}
    }

    vsip_cmalldestroy_f(X);
    vsip_cmalldestroy_f(A);
    } vsip_finalize((void*)0); return 1;
}
Пример #5
0
int main(int argc, char *argv[]){vsip_init((void*)0);
{  if(argc < 3){
      printf("usage\nqrdex M N FileName\n");
      exit(1);
   }
   { /* get some data */
     vsip_length M = (vsip_length)atoi(argv[1]),
                 N = (vsip_length)atoi(argv[2]);
     vsip_cmview_f *A = vsip_cmcreate_f(M,N,VSIP_COL,0),
                  *Q = vsip_cmcreate_f(M,N,VSIP_ROW,0);
     vsip_scalar_f *beta = (vsip_scalar_f*)malloc(N * sizeof(vsip_scalar_f));
     
     FILE *fptr = fopen(argv[3],"r");
     VU_cmreadf_f(fptr,A);
     fclose(fptr);
     vsip_cmcopy_f_f(A,Q);
     printf("input matrix A \n");
     printf("A =");VU_cmprintm_f("6.4",A);
     VU_chouseqr_f(Q,beta); /* make a QR matrix, keep the betas */
     printf("Decomposed A with R in upper, \n");
     printf("and householder vector in lower \n");
     printf("householder value on diagonal is 1\n");
     printf("v(2:m)\\R =");VU_cmprintm_f("6.4",Q); 
     { /* Multiply Q times R to see if we get A */
       vsip_length i,j;
       vsip_cmview_f *R = vsip_cmcreate_f(M,N,VSIP_ROW,0);
       vsip_cvview_f *r = vsip_cmrowview_f(R,0);
       vsip_cvputlength_f(r,N * M);
       vsip_cvfill_f(vsip_cmplx_f(0,0),r);
       for(i=0; i<N; i++) /* extract R */
          for(j = i; j<N; j++)
              vsip_cmput_f(R,i,j,vsip_cmget_f(Q,i,j));
       VU_cqprodm_f(R,Q,beta); /* Q * R */
       printf("Multiply Q times R and see if we get A\n");
       printf("QR = \n"); VU_cmprintm_f("6.4",R);
       vsip_cvdestroy_f(r);
       vsip_cmalldestroy_f(R);
     }
     { /* Multiply I * Q to get Q */
       vsip_cmview_f *I = vsip_cmcreate_f(M,M,VSIP_ROW,0);
       vsip_cvview_f *I_rv = vsip_cmrowview_f(I,0);
       vsip_cvputlength_f(I_rv,M * M);
       vsip_cvfill_f(vsip_cmplx_f(0.0,0.0),I_rv);
       vsip_cvputlength_f(I_rv,M);
       vsip_cvputstride_f(I_rv,M+1);
       vsip_cvfill_f(vsip_cmplx_f(1.0,0.0),I_rv);
       printf("Using an Identity matrix extract Q using Householdoer update\n");
       printf("I = \n"); VU_cmprintm_f("6.4",I);
       VU_cqprodm_f(I,Q,beta);
       printf("Q = \n"); VU_cmprintm_f("6.4",I);
       { /* Multiply Q hermitian * A to get R */
         vsip_cmview_f *AC = vsip_cmcreate_f(M,N,VSIP_COL,0);
         vsip_cmview_f *QT = vsip_cmtransview_f(I);
         vsip_cmview_f *R  = vsip_cmcreate_f(M,N,VSIP_ROW,0);
         vsip_cmprodj_f(QT,A,R);
         VU_cmconjIP_f(R);
         printf("Using Q from above mutiply Hermitian(Q) times A to get R\n");
         printf("QT * A = R = \n"); VU_cmprintm_f("6.4",R);
         vsip_cmcopy_f_f(A,AC);
         printf("Using Householder update multiply Transpose(Q) times A to get R\n");
         VU_cqhprodm_f(AC,Q,beta);
         printf("QT * AC = R = \n"); VU_cmprintm_f("6.4",AC);
         { vsip_cmview_f *QTQ = vsip_cmcreate_f(M,M,VSIP_ROW,0);
           vsip_cmprodj_f(QT,I,QTQ);
           printf("QT * Q = I = \n"); VU_cmprintm_f("6.4",QTQ);
           vsip_cmalldestroy_f(QTQ);
         }
         vsip_cmdestroy_f(QT);
         vsip_cmalldestroy_f(R); 
       } 
       {
          /* general Multiply  */
         vsip_cmview_f *J = vsip_cmcreate_f(M,2 * M,VSIP_ROW,0);
         vsip_cmview_f *K = vsip_cmcreate_f(M,2 * M,VSIP_ROW,0);
         vsip_cvview_f *J_rv = vsip_cmrowview_f(J,0);
         vsip_cvputlength_f(J_rv,2 * M * M);
         vsip_cvfill_f(vsip_cmplx_f(2.0,-1.0),J_rv);
         vsip_cvputlength_f(J_rv,M);
         vsip_cvputstride_f(J_rv,2 * M+1);
         vsip_cvfill_f(vsip_cmplx_f(1.0,1.0),J_rv);
         vsip_cvputoffset_f(J_rv,M);
         vsip_cvfill_f(vsip_cmplx_f(3.0,0.0),J_rv);
         printf("Make a big matrix J to test with \n");
         printf("J = \n"); VU_cmprintm_f("6.4",J);

         vsip_cmprod_f(I,J,K);
         VU_cqprodm_f(J,Q,beta);
         printf("Multiply Q * J using Householder update \n");
         printf("J = \n"); VU_cmprintm_f("6.4",J);
         printf("Multiply Q * J using Q extracted above \n");
         printf("K = \n"); VU_cmprintm_f("6.4",K);
         printf("\n");

         {  vsip_cmview_f *JT = vsip_cmtransview_f(J);
            vsip_cmview_f *KT = vsip_cmtransview_f(K);
            VU_cmconjIP_f(JT);
            printf("Conjugate Transpose the current J (overwritten by the above operation\n");
            printf("JT = \n"); VU_cmprintm_f("6.4",JT);
            vsip_cmprod_f(JT,I,KT);
            VU_cmprodq_f(JT,Q,beta);

            printf("Multiply hermitian(J) * Q using Householder update \n");
            printf("JT = \n"); VU_cmprintm_f("6.4",JT);
            printf("Multiply hermitian(J) * Q using Q extracted above \n");
            printf("KT = \n"); VU_cmprintm_f("6.4",KT);
            vsip_cmdestroy_f(JT);
            vsip_cmdestroy_f(KT);
         }
         {  vsip_cmview_f *QT = vsip_cmtransview_f(I);
            VU_cmconjIP_f(QT);
            vsip_cmprod_f(QT,J,K);
            VU_cqhprodm_f(J,Q,beta);
            printf("Transpose JT to J, multiply transpose(Q) * J using Householder\n");
            printf("J = \n"); VU_cmprintm_f("6.4",J);
            printf("Transpose JT to J, multiply transpose(Q) * J using Q extracted above\n");
            printf("K = \n"); VU_cmprintm_f("6.4",K);
            {
               vsip_cmview_f* JT = vsip_cmtransview_f(J);
               vsip_cmview_f* KT = vsip_cmtransview_f(K);
               VU_cmconjIP_f(JT);
               vsip_cmprod_f(JT,QT,KT);
               VU_cmconjIP_f(QT);
               printf("Transpose J, Multiply J * transpose(Q) using Q extracted above\n");
               printf("K = \n"); VU_cmprintm_f("6.4",KT);
               VU_cmprodqh_f(JT,Q,beta);
               VU_cmconjIP_f(JT);
               printf("Transpose J, Multiply J * transpose(Q) using Householder\n");
               printf("J = \n"); VU_cmprintm_f("6.4",JT);
               vsip_cmdestroy_f(JT);
               vsip_cmdestroy_f(KT);
            }
            vsip_cmdestroy_f(QT);
         }
         { vsip_cmview_f *I2 = vsip_cmcreate_f(M,M,VSIP_ROW,0);
           vsip_cmview_f *I2t = vsip_cmtransview_f(I2);
           vsip_cmcopy_f_f(I,I2);                  VU_cmprodqh_f(I2,Q,beta);
           printf("test mprodqh QQh =\n"); VU_cmprintm_f("6.4",I2);
           vsip_cmcopy_f_f(I,I2);VU_cmconjIP_f(I2);VU_cqprodm_f(I2t,Q,beta);
           printf("test qprodm QQh =\n"); VU_cmprintm_f("6.4",I2);
           vsip_cmcopy_f_f(I,I2);                  VU_cqhprodm_f(I2,Q,beta);
           printf("test qhprodm QhQ =\n"); VU_cmprintm_f("6.4",I2);
           vsip_cmcopy_f_f(I,I2);VU_cmconjIP_f(I2);VU_cmprodq_f(I2t,Q,beta);
           printf("test mprodq QhQ =\n"); VU_cmprintm_f("6.4",I2);
           vsip_cmdestroy_f(I2t);
           vsip_cmalldestroy_f(I2);
         }
           
       }
       vsip_cvdestroy_f(I_rv);
       vsip_cmalldestroy_f(I);
     }
     vsip_cmalldestroy_f(A);
     vsip_cmalldestroy_f(Q);
     free(beta);
     } vsip_finalize((void*)0); return 0;
   }
}
Пример #6
0
int main(){vsip_init((void*)0);
{  int i,j; /* counters */
   vsip_vview_f *windowt = vsip_vcreate_hanning_f(Ns,0);
   vsip_vview_f *windowp = vsip_vcreate_hanning_f(Mp,0);
   vsip_vview_f *kernel = 
         vsip_vcreate_kaiser_f(Nfilter,kaiser,0);
   vsip_fir_f *fir = vsip_fir_create_f(kernel,
                         VSIP_NONSYM,2 * Nn,2,VSIP_STATE_SAVE,0,0);
   vsip_vview_f *t =vsip_vcreate_f(Ns,0); /*time vector*/
   vsip_vview_f *noise[Nnoise];
   vsip_vview_f *nv = vsip_vcreate_f(2 * Nn,0);
   vsip_vview_f *tt = vsip_vcreate_f(Ns,0); 
   vsip_mview_f *data = vsip_mcreate_f(Mp,Ns,VSIP_ROW,0),
                *rmview;
   vsip_vview_f *data_v, *gram_v;
   vsip_cvview_f *gram_data_v;
   vsip_cmview_f *gram_data = 
        vsip_cmcreate_f(Mp,Ns/2 + 1,VSIP_COL,0);
   vsip_mview_f  *gram = 
         vsip_mcreate_f(Mp,Ns/2 + 1,VSIP_ROW,0);
   vsip_mview_f  *Xim = 
         vsip_mcreate_f(Mp,Mp+1,VSIP_ROW,0);
   vsip_scalar_f alpha = (D * Fs) / c;
vsip_vview_f *m = vsip_vcreate_f(Mp,0);
   vsip_vview_f *Xi = vsip_vcreate_f(Mp + 1,0);
   vsip_randstate *state =
          vsip_randcreate(15,1,1,VSIP_PRNG);
   vsip_scalar_f w0 = 2 * M_PI * F0/Fs;
   vsip_scalar_f w1 = 2 * M_PI * F1/Fs;
   vsip_scalar_f w2 = 2 * M_PI * F2/Fs;
   vsip_scalar_f w3 = 2 * M_PI * F3/Fs;
   vsip_scalar_f cnst1 = M_PI/Nnoise;  
   vsip_offset offset0 = (vsip_offset)(alpha * Mp + 1);
   vsip_fftm_f *rcfftmop_obj = /* time fft */
   vsip_rcfftmop_create_f(Mp,Ns,1,VSIP_ROW,0,0);
   vsip_fftm_f *ccfftmip_obj =
         vsip_ccfftmip_create_f(Mp,Ns/2 +
             1,VSIP_FFT_FWD,1,VSIP_COL,0,0);
   vsip_vramp_f(0,1,m);
   vsip_vramp_f(0,M_PI/Mp,Xi); 
   vsip_vcos_f(Xi,Xi);
   vsip_vouter_f(alpha,m,Xi,Xim);
   { vsip_vview_f *gram_v = vsip_mrowview_f(gram,0);
     vsip_vputlength_f(gram_v,Mp*(Ns/2 + 1));
     vsip_vfill_f(0,gram_v);
     vsip_vdestroy_f(gram_v);
   }
   for(j=0; j<Nnoise; j++){
      noise[j] = vsip_vcreate_f(Nn,0);
      vsip_vrandn_f(state,nv);
      vsip_firflt_f(fir,nv,noise[j]);
      vsip_svmul_f(12.0/(Nnoise),noise[j],noise[j]);
      vsip_vputlength_f(noise[j],Ns);
   }
   vsip_vramp_f(0,1.0,t); /* time vector */
for(i=0; i<Mp; i++){
      vsip_scalar_f Xim_val = vsip_mget_f(Xim,i,Theta_o);
      data_v = vsip_mrowview_f(data,i);
      vsip_vsmsa_f(t,w0,-w0 * Xim_val,tt);
      vsip_vcos_f(tt,data_v); /*F0 time series */
      vsip_vsmsa_f(t,w1,-w1 * Xim_val,tt);
      vsip_vcos_f(tt,tt); /*F1 time series */
      vsip_vadd_f(tt,data_v,data_v);
      vsip_vsmsa_f(t,w2,-w2 * Xim_val,tt);
      vsip_vcos_f(tt,tt); /*F2 time series */
      vsip_vadd_f(tt,data_v,data_v);
      vsip_vsmsa_f(t,w3,-w3 * Xim_val,tt);
      vsip_vcos_f(tt,tt); /*F3 time series */
      vsip_svmul_f(3.0,tt,tt); /* scale by 3.0 */
      vsip_vadd_f(tt,data_v,data_v);
      vsip_svmul_f(3,data_v,data_v);
      for(j=0; j<Nnoise; j++){ 
          /* simple time delay beam forming for noise */
         vsip_vputoffset_f(noise[j],offset0 + 
           (int)( i * alpha * cos(j * cnst1)));
         vsip_vadd_f(noise[j],data_v,data_v); 
      } 
      /* need to destroy before going on to next phone */
      vsip_vdestroy_f(data_v);
   }
   /* window the data and the array to reduce sidelobes */
   vsip_vmmul_f(windowt,data,VSIP_ROW,data);
   vsip_vmmul_f(windowp,data,VSIP_COL,data);

   /* do ffts */
   vsip_rcfftmop_f(rcfftmop_obj,data,gram_data);
   vsip_ccfftmip_f(ccfftmip_obj,gram_data);

   { /* scale gram to db, min 0 max 255 */
      vsip_index ind;
      gram_v = vsip_mrowview_f(gram,0);
      gram_data_v = vsip_cmcolview_f(gram_data,0);
      rmview = vsip_mrealview_f(gram_data);
      vsip_vputlength_f(gram_v,Mp*(Ns/2 + 1)); 
      vsip_cvputlength_f(gram_data_v,Mp*(Ns/2 + 1));
data_v = vsip_vrealview_f(gram_data_v);
      vsip_vcmagsq_f(gram_data_v,data_v);
      vsip_mcopy_f_f(rmview,gram);
      vsip_vdestroy_f(data_v);
      vsip_svadd_f(1.0 -
      vsip_vminval_f(gram_v,&ind),gram_v,gram_v);
      vsip_vlog10_f(gram_v,gram_v); 
      vsip_svmul_f(256.0 / vsip_vmaxval_f(gram_v,&ind),
                    gram_v,gram_v);/* scale */
      /* reorganize the data to place zero in the 
          center for direction space */
      data_v = vsip_vcloneview_f(gram_v);
      vsip_vputlength_f(data_v,(Mp/2) * (Ns/2 + 1));
      vsip_vputoffset_f(data_v,(Mp/2) * (Ns/2 + 1));
      vsip_vputlength_f(gram_v,(Mp/2) * (Ns/2 + 1));
      vsip_vswap_f(data_v,gram_v);
      vsip_vdestroy_f(gram_v);
      vsip_vdestroy_f(data_v);
      vsip_cvdestroy_f(gram_data_v);
      vsip_mdestroy_f(rmview);
   }
   VU_mprintgram_f(gram,"gram_output");
   } vsip_finalize((void*)0); return 0;        
}
Пример #7
0
int main(){
vsip_init((void*)0);{
    vsip_cvview_f *A = vsip_cvcreate_f(16,0);
    vsip_cvview_f *a = vsip_cvsubview_f(A,0,4);
    vsip_cvview_f *B = vsip_cvcreate_f(16,0);
    vsip_cvview_f *b = vsip_cvsubview_f(B,0,4);
    vsip_scalar_f user_data_r[16],*udr;
    vsip_scalar_f user_data_i[16],*udi;
    vsip_cblock_f *cblock = vsip_cblockbind_f(
             user_data_r,user_data_i,16,0);
    vsip_cvview_f *c = vsip_cvbind_f(cblock,1,2,4);

    /* unit stride data_even out of place */
    FILE *fptr = fopen("data_even","r");
    vsip_cblockadmit_f(cblock,VSIP_FALSE);
    printf("test cvlog\n");
    printf("unit stride data even out of place");
    VU_cvreadf_f(fptr,a);
    fclose(fptr);
    printf("input vector\n"); VU_cvprintm_f("6.4",a);
    vsip_cvlog_f(a,b);
    printf("input vector after operation\n");VU_cvprintm_f("6.4",a);
    printf("output vector\n"); VU_cvprintm_f("6.4",b);
    /* inplace */
    vsip_cvlog_f(a,a);
    printf("output of inplace\n"); VU_cvprintm_f("6.4",a);

    /* unit stride data_odd out of place */
    printf("unit stride data odd out of place\n");
    vsip_cvputlength_f(a,5);
    vsip_cvputlength_f(b,5);
    fptr = fopen("data_odd","r");
    VU_cvreadf_f(fptr,a);
    fclose(fptr);
    printf("input vector\n"); VU_cvprintm_f("6.4",a);
    vsip_cvlog_f(a,b);
    printf("input vector after operation\n");VU_cvprintm_f("6.4",a);
    printf("output vector\n"); VU_cvprintm_f("6.4",b);

    /* input stride 1 output stride 2 */
    printf("input stride 1 output stride 2\n");
    vsip_cvputstride_f(b,2);
    fptr = fopen("data_odd","r"); VU_cvreadf_f(fptr,a); fclose(fptr);
    vsip_cvlog_f(a,b);
    printf("output vector\n"); VU_cvprintm_f("6.4",b);

    /* input stride 2 output stride 3 */
    printf("input stride 2 output stride 3\n");
    vsip_cvputstride_f(a,2);
    vsip_cvputstride_f(b,3);
    fptr = fopen("data_odd","r"); VU_cvreadf_f(fptr,a); fclose(fptr);
    vsip_cvlog_f(a,b);
    printf("output vector\n"); VU_cvprintm_f("6.4",b);

    /* input stride 2 output stride 1 */
    printf("input stride 2 output stride 1\n");
    vsip_cvputstride_f(a,2);
    vsip_cvputstride_f(b,1);
    fptr = fopen("data_odd","r"); VU_cvreadf_f(fptr,a); fclose(fptr);
    vsip_cvlog_f(a,b);
    printf("output vector\n"); VU_cvprintm_f("6.4",b);

    /* in place stride 2 */
    printf("in place stride 2\n");
    fptr = fopen("data_odd","r"); VU_cvreadf_f(fptr,a); fclose(fptr);
    vsip_cvlog_f(a,a);
    printf("output vector\n"); VU_cvprintm_f("6.4",a);

    /* out of place from user block to VSIPL block */
    printf("out of place from user block to VSIPL block\n");
    printf("User block associated with split complex data array\n");
    printf("user view offset 1, stride 2\n");
    printf("vsipl view offset 0, stride 2\n");
    fptr = fopen("data_odd","r"); VU_cvreadf_f(fptr,c); fclose(fptr);
    vsip_cvlog_f(c,a);
    printf("output vector\n"); VU_cvprintm_f("6.4",a);

    /* clean up */
    vsip_cblockrelease_f(cblock,VSIP_FALSE,&udr,&udi);
    vsip_cvalldestroy_f(c);
    vsip_cvdestroy_f(a);
    vsip_cvdestroy_f(b);
    vsip_cvalldestroy_f(A);
    vsip_cvalldestroy_f(B);
    }vsip_finalize((void*)0);return 0;
}
Пример #8
0
int main(){
   int init = vsip_init((void*)0);
   int i,j, cholsol_retval,chold_retval;
   double t0 = VU_ansi_c_clock(); /* for doing some timeing */
   vsip_cscalar_f czero = vsip_cmplx_f((vsip_scalar_f)0.0,(vsip_scalar_f)0.0);
   vsip_cmview_f *A  = vsip_cmcreate_f(N,N,VSIP_COL,0);
   vsip_cmview_f *RU  = vsip_cmcreate_f(N,N,VSIP_COL,0);
   vsip_cmview_f *RL  = vsip_cmcreate_f(N,N,VSIP_COL,0);
   vsip_cmview_f *XB  = vsip_cmcreate_f(N,M,VSIP_ROW,0);
   vsip_cchol_f* chol = vsip_cchold_create_f(UPORLO,N);   /* NOTE: UPORLO macro above main() */

   /* to make sure we have a valid Positive Symetric define */
   /* an upper triangular (RU) with positive pivots and     */
   /* zero below the main diagonal.                         */
   /* Then initialize RL with hermitian of RU               */
   /* finally create A as the matrix product of RL and RU   */

   /* Initialise matrix RU  */
   /* time this             */
   t0 = VU_ansi_c_clock();
   for (i=0; i<N; i++){
      for(j = i; j < N; j++){
         #ifdef OBNOXIOUS
         /* make up some reasonably obnoxious data                */
         vsip_scalar_f a = cos(1.5/((j+1)*(i+1)))+sqrt(i*j);
         vsip_scalar_f b = (i + j + 1) * cos(M_PI * a);
         #else
         /* the above was to obnoxious for bigger than about N = 10 */
         /* the following works for N > 100 */
         vsip_scalar_f a = 1; vsip_scalar_f b = 1; 
         #endif
         if(i == j) /* fill diagonal */
             vsip_cmput_f(RU,i,j, vsip_cmplx_f(sqrt(N) + sqrt(i),0));
         else { /* fill off diagonal */
                vsip_cmput_f(RU,i,j,vsip_cmplx_f(b,a)); 
                vsip_cmput_f(RU,j,i,czero); 
         }
      }
   }
   /* initialize RL */
   vsip_cmherm_f(RU,RL);
   #ifdef PRINT
      VU_cmprintm_f("7.4",RU);
      VU_cmprintm_f("7.4",RL);
   #endif
   printf("Matrix initialize for RU and RL = %f seconds\n",VU_ansi_c_clock() - t0);

   /* initialize A */
   /* this step will take a long time so time it */
   t0 = VU_ansi_c_clock();
   vsip_cmprod_f(RL,RU,A);
   #ifdef OBNOXIOUS
      for(i=0; i<N; i++){
         vsip_cvview_f *aview = vsip_cmrowview_f(A,i);
         vsip_cvrsdiv_f(aview,vsip_cmag_f(vsip_cvmeanval_f(aview)),aview);
         vsip_cvdestroy_f(aview);
      }
   #endif
   printf("Matrix multiply for initialization of A = %f seconds\n",VU_ansi_c_clock() - t0);

   /* print  A                                                      */
   /* we only want to do this if A is something reasonable to print */
   /* selected as an option in the make file                        */
   #ifdef PRINT
      printf("Matrix A =\n");
      VU_cmprintm_f("4.2",A);
      fflush(stdout);
   #endif

   /* initialise rhs                      */
   /* start out with XB = {1,2,3,...,M}   */
   /* calculate what B must be using A    */
   /* then solve to see if we get XB back */
   {  vsip_index i;
      vsip_vview_f *y = vsip_vcreate_f(vsip_cmgetcollength_f(A),VSIP_MEM_NONE);
      vsip_vview_f *x_r,*x_i;
      vsip_cvview_f *x;
      vsip_mview_f *A_r = vsip_mrealview_f(A),
                   *A_i = vsip_mimagview_f(A);
      /* time this */
      t0 = VU_ansi_c_clock();
      for(i=0; i<M; i++){
         vsip_vfill_f((vsip_scalar_f)i+1.0,y);
         x = vsip_cmcolview_f(XB,i);
         x_r = vsip_vrealview_f(x);
         x_i = vsip_vimagview_f(x);
         vsip_mvprod_f(A_r,y,x_r);
         vsip_mvprod_f(A_i,y,x_i);
         vsip_cvdestroy_f(x);
         vsip_vdestroy_f(x_r);
         vsip_vdestroy_f(x_i);
      }
      vsip_mdestroy_f(A_r);
      vsip_mdestroy_f(A_i);
      printf("Matrix init for B = %f seconds\n",VU_ansi_c_clock() - t0);
   }

   /* print  XB                                                      */
   /* we only want to do this if XB is something reasonable to print */
   /* selected as an option in the make file                         */
   #ifdef PRINT
      printf("Matrix B = \n");
      VU_cmprintm_f("7.4",XB);
      fflush(stdout);
   #endif

   if(chol != NULL){
      t0 = VU_ansi_c_clock(); /* we want to time the decomposition */
      chold_retval = vsip_cchold_f(chol,A);
      printf("time decomp %f\n",VU_ansi_c_clock() - t0);
      printf("decompostion returns %d\n",chold_retval);
   
      /* now do the solution */
      t0 = VU_ansi_c_clock(); /* we want to time the solution */
      cholsol_retval=vsip_ccholsol_f(chol,XB);
      printf("time solution %f\n",VU_ansi_c_clock() - t0);
      printf("cholsol returns %d\n",cholsol_retval);

      /* print  XB                                                      */
      /* we only want to do this if XB is something reasonable to print */
      /* selected as an option in the make file; otherwise              */
      /* we print a single row of XB if the matrix is to large since    */
      /* M is usally reasonable. Printed as a column vector             */
      #ifdef PRINT
         printf("Matrix X = \n");
         VU_cmprintm_f("7.4",XB);
         fflush(stdout);
      #else
         {  /* pick a row in the middle */
            vsip_cvview_f *x = vsip_cmrowview_f(XB,N/2);
            printf("This output sould be 1,2,...,M\n");
            VU_cvprintm_f("7.4",x);
            fflush(stdout);
            vsip_cvdestroy_f(x);
         }
      #endif
   } else {
         printf("failed to create cholesky object \n");
   }
   vsip_cmalldestroy_f(XB);
   vsip_cmalldestroy_f(A);
   vsip_cmalldestroy_f(RL);
   vsip_cmalldestroy_f(RU);
   vsip_cchold_destroy_f(chol);
   vsip_finalize((void*)0);
   return 1;
}
Пример #9
0
void (vsip_cvalldestroy_f)(
  vsip_cvview_f* v) {	/* vector view  destructor*/
  vsip_cblockdestroy_f(vsip_cvdestroy_f(v));
  }