Exemplo n.º 1
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.º 2
0
 static int qr_solve(qr_type *qr, vsip_qrd_prob p, matrix_type *m)
 { return vsip_cqrsol_f(qr, p, m);}