Exemple #1
0
int eigs_sym_part (int ni, const float * a, int nev, float * sout, float * vout) {
  FINTEGER n=ni;
  arpack_eigs_t *ae=arpack_eigs_begin(n,nev);
  int ret=0;
  

  for(;;) {
    float *x,*y;
    ret=arpack_eigs_step(ae,&x,&y); 

    if(ret<0) break; /* error */

    if(ret==0) break; /* stop iteration */

    /* ret==1 */

    float zero=0,one=1;
    FINTEGER ione=1;
    
    sgemv_("Trans",&n,&n,&one,a,&n,x,&ione,&zero,y,&ione);    
  } 
  ret=arpack_eigs_end(ae,sout,vout);
 
  return ret;
}
Exemple #2
0
int fmat_svd_partial_full(int n,int m,int nev,const float *a,int a_transposed,
                          float *s,float *vout,float *uout,int nt) {
  
  arpack_eigs_t *ae=arpack_eigs_begin(n,nev);
  if(!ae) return -100;
  int ret=0;
  
  int j,i;
  float *ax=NEWA(float,m);
  
  int it;

  for(it=0;;it++) {
    float *x,*y;
    ret=arpack_eigs_step(ae,&x,&y); 

    printf("arpack iteration %d ret=%d\r",it,ret);

    if(ret<0) break; /* error */

    if(ret==0) break; /* stop iteration */

    /* ret==1 */

    if(!a_transposed) {
      fmat_mul_v(m,n,a,n,x,ax,nt);
      fmat_mul_tv(n,m,a,n,ax,y,nt);
    } else {
      fmat_mul_tv(m,n,a,m,x,ax,nt);
      fmat_mul_v(n,m,a,m,ax,y,nt);
    }

    fflush(stdout);
  } 
  printf("\n");

  free(ax);

  float *v=vout ? vout : fmat_new(nev,n);

  ret=arpack_eigs_end(ae,s,v);

  if(ret>0) {
    int nconv=ret;
        
    if(s)
      for(j=0;j<nconv;j++) 
        s[j]=sqrt(s[j]);    

    if(uout) 
      for(i=0;i<nconv;i++) {
        float *u=uout+m*(long)i;
        if(!a_transposed)
          fmat_mul_v(m,n,a,n,v+n*(long)i,u,nt);
        else
          fmat_mul_tv(m,n,a,m,v+n*(long)i,u,nt);
        fvec_normalize(u,m,2);
      }               
    
  }

  if(!vout) free(v);
  
  return ret;
}