void VU_cmprintm_f(char s[],
    vsip_cmview_f *X)
{
    char format[50];
    vsip_length RL = vsip_cmgetrowlength_f(X);
    vsip_length CL = vsip_cmgetcollength_f(X);
    vsip_length row,col;
    vsip_cscalar_f x;
    strcpy(format,"(%");
    strcat(format,s);
    strcat(format,"f %+");
    strcat(format,s);
    strcat(format,"fi) %s");
    printf("[\n");	
    for(row=0; row<CL; row++){
      for(col=0; col<RL; col++){
        x=vsip_cmget_f(X,row,col);
        printf(format,vsip_real_f(x),
                      vsip_imag_f(x),
               ((col==(RL-1)) ? ";" : " "));
      }  
      printf("\n");
    }
    printf("];\n");
    return;
}
Exemplo n.º 2
0
int main(){vsip_init((void*)0);
{
   vsip_cmview_f *A = vsip_cmcreate_f(M,P,VSIP_ROW,0),
                 *B = vsip_cmcreate_f(N,P,VSIP_ROW,0),
                 *R = vsip_cmcreate_f(M,N,VSIP_ROW,0);
   int i, j;
   for(i=0;i<M;i++) for(j=0;j<P;j++)
        vsip_cmput_f(A,i,j,vsip_cmplx_f(i,1 + sqrt(i*j)));
   
   for(i=0;i<N;i++) for(j=0;j<P;j++)
        vsip_cmput_f(B,i,j,vsip_cmplx_f(1 , i * j));
   
   printf("\n A input \n");
   vsip_cmprodh_f(A,B,R);
   {for(i=0;i<M;i++) {for(j=0;j<P;j++){
           printf(": (%5.2f, %5.2f) ",
             vsip_real_f(vsip_cmget_f(A,i,j)),
             vsip_imag_f(vsip_cmget_f(A,i,j)));
           }
       printf(":\n");
       }
   }
   printf("\n B input \n");
   {for(i=0;i<N;i++) {for(j=0;j<P;j++){
           printf(": (%5.2f, %5.2f) ",
             vsip_real_f(vsip_cmget_f(B,i,j)),
             vsip_imag_f(vsip_cmget_f(B,i,j)));
           }
       printf(":\n");
       }
   }
   printf("\n R output \n");
   {for(i=0;i<M;i++) {for(j=0;j<N;j++){
           printf(": (%5.2f, %5.2f) ",
             vsip_real_f(vsip_cmget_f(R,i,j)),
             vsip_imag_f(vsip_cmget_f(R,i,j)));
           }
       printf(":\n");
       }
   }
   vsip_cmalldestroy_f(A);
   vsip_cmalldestroy_f(B);
   vsip_cmalldestroy_f(R);
   } vsip_finalize((void*)0); return 0;
}
Exemplo n.º 3
0
int main(){vsip_init((void*)0);
{
   vsip_cscalar_f alpha = vsip_cmplx_f(alpha_r,alpha_i),
                  beta  = vsip_cmplx_f(beta_r,beta_i);
   void VU_cmprint_f(vsip_cmview_f*);
   void VU_cmfill_f(vsip_cmview_f*, vsip_cscalar_f);
   vsip_cmview_f *A = vsip_cmcreate_f(N,M,VSIP_ROW,0),
                 *B = vsip_cmcreate_f(P,M,VSIP_ROW,0),
                 *C = vsip_cmcreate_f(N,P,VSIP_ROW,0);
   int row, col,i;
   for(row=0;row<N;row++) for(col=0;col<M;col++)
        vsip_cmput_f(A,row,col,vsip_cmplx_f(row,col));
   
   for(row=0;row<P;row++) for(col=0;col<M;col++)
        vsip_cmput_f(B,row,col,vsip_cmplx_f(col, -2*row));
   
   printf("\n A input \n");
   VU_cmprint_f(A);
   printf("\n B input \n");
   VU_cmprint_f(B);
   VU_cmfill_f(C,vsip_cmplx_f(0,0));
   printf("alpha= (%f  %+fi), beta= (%f %+fi),\n",
                    vsip_real_f(alpha),vsip_imag_f(alpha),
                    vsip_real_f(beta),vsip_imag_f(beta));
   {
      vsip_mat_op OpA = VSIP_MAT_NTRANS;
      vsip_mat_op OpB = VSIP_MAT_HERM;
      printf("OpA %i OpB %i\n",OpA,OpB);
      for(i=0; i<L; i++){
         vsip_cgemp_f(alpha,A,OpA,B,OpB,beta,C);
         printf("C number %i\n",i); VU_cmprint_f(C); 
      }
   }
   vsip_cmalldestroy_f(A);
   vsip_cmalldestroy_f(B);
   vsip_cmalldestroy_f(C);
   } vsip_finalize((void*)0); return 0;
}
Exemplo n.º 4
0
void VU_cmprint_f(vsip_cmview_f *X)
{
    vsip_length RL = vsip_cmgetrowlength_f(X);
    vsip_length CL = vsip_cmgetcollength_f(X);
    vsip_length row,col;
    vsip_cscalar_f x;
    printf("[\n");
    for(row=0; row<CL; row++){
      for(col=0; col<RL; col++){
        x=vsip_cmget_f(X,row,col);
        printf("(%6.4f %+6.4fi%s ",vsip_real_f(x),vsip_imag_f(x),((col==(RL-1)) ? ");" : ")"));
      }  
      printf("\n");
    }
    printf("];\n");
    return;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
int main () {
  vsip_init((void*)0);{
     double time0, time_rc=0, time_cr=0;
     int i;
     /*int k; for(k=0; k<4; k++)*/{
     vsip_cvview_f* vectorOut = vsip_cvcreate_f(L/2 + 1,VSIP_MEM_NONE);
     vsip_vview_f* vectorIn = vsip_vcreate_f(L,VSIP_MEM_NONE);
     vsip_vview_f* ivectorOut = vsip_vcreate_f(L,VSIP_MEM_NONE);
     vsip_fft_f* fftplan  = vsip_rcfftop_create_f(L,1.0/L,0,VSIP_ALG_SPACE);
     vsip_fft_f* ifftplan = vsip_crfftop_create_f(L,(double)(1.0),0,VSIP_ALG_TIME);
     char printbuffer[10][40];
/*     char printbuffer[L/2][40]; */
   
     vsip_vramp_f(0, 2 * M_PI * F, vectorIn);
     vsip_vcos_f(vectorIn,vectorIn);
   
     /* print vectorIn */
     /* for(i=0; i<L/2; i++) */
     for(i=0; i<10; i++)
        sprintf(printbuffer[i],"%2d, %2d input-> %7.3f, %7.3f",
                 i, i+L/2, vsip_vget_f(vectorIn,i), vsip_vget_f(vectorIn,i+L/2));

     /*find the fft*/
     for(i=0; i<N; i++){
        /* printf("%d\n",i);fflush(stdout); */
        time0=VU_ansi_c_clock();
        vsip_rcfftop_f(fftplan,vectorIn,vectorOut);
        time_rc += (VU_ansi_c_clock() - time0);
        /*find the inverse fft*/
        time0=VU_ansi_c_clock();
        vsip_crfftop_f(ifftplan,vectorOut,ivectorOut);  
        time_cr += (VU_ansi_c_clock() - time0);
     }
     /*print it */
     /* for(i=0; i<L/2; i++) */
     for(i=0; i<10; i++)
        printf("%s   fft -> (%9.4f, %9.4f) ifft-> %7.3f, %7.3f\n" ,
              printbuffer[i],
              vsip_real_f(vsip_cvget_f(vectorOut,i)),
              vsip_imag_f(vsip_cvget_f(vectorOut,i)),
              vsip_vget_f(ivectorOut,i), 
              vsip_vget_f(ivectorOut,i+L/2));
     printf("                                  fft -> (%9.4f, %9.4f)\n",
              vsip_real_f(vsip_cvget_f(vectorOut,i)),
              vsip_imag_f(vsip_cvget_f(vectorOut,i)));
    {/* test vsip_fft_getattr_f */
         vsip_fft_attr_f attr;
         vsip_fft_getattr_f(fftplan, &attr);
         printf("%lu %lu %d %f %d\n",attr.input,attr.output,attr.place,attr.scale,attr.dir);
         vsip_fft_getattr_f(ifftplan, &attr);
         printf("%lu %lu %d %f %d\n",attr.input,attr.output,attr.place,attr.scale,attr.dir);
     }
     vsip_cvalldestroy_f(vectorOut);
     vsip_valldestroy_f(vectorIn);
     vsip_fft_destroy_f(fftplan);
     printf("time_rc %f; time_cr %f\n",time_rc/(double)N, time_cr/(double)N);
   } 
   }
   vsip_finalize((void*)0); 
   return 0;
}
Exemplo n.º 7
0
vsip_cscalar_f (vsip_cadd_f)(
  vsip_cscalar_f x, vsip_cscalar_f y) {/* x + y*/
  return vsip_cmplx_f(
    (vsip_real_f(x) + vsip_real_f(y)),
    (vsip_imag_f(x) + vsip_imag_f(y))); }
Exemplo n.º 8
0
vsip_cscalar_f (vsip_conj_f)(vsip_cscalar_f x) {	/* conj(x)	*/
  return vsip_cmplx_f(vsip_real_f(x),
	   -(vsip_imag_f(x))); }