[BACK]Return to nd.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Diff for /OpenXM_contrib2/asir2000/engine/nd.c between version 1.108 and 1.109

version 1.108, 2004/09/21 02:43:11 version 1.109, 2004/09/21 04:50:15
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.107 2004/09/21 02:34:12 noro Exp $ */  /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.108 2004/09/21 02:43:11 noro Exp $ */
   
 #include "nd.h"  #include "nd.h"
   
Line 3785  int nd_to_vect_q(UINT *s0,int n,ND d,Q *r)
Line 3785  int nd_to_vect_q(UINT *s0,int n,ND d,Q *r)
         return i;          return i;
 }  }
   
 int nm_ind_pair_to_vect(int mod,UINT *s0,int n,NM_ind_pair pair,UINT *r)  
 {  
         NM m;  
         NMV mr;  
         UINT *d,*t,*s;  
         NDV p;  
         int i,j,len;  
   
         m = pair->mul;  
         d = DL(m);  
         p = nd_ps[pair->index];  
         t = (UINT *)ALLOCA(nd_wpd*sizeof(UINT));  
         for ( i = 0; i < n; i++ ) r[i] = 0;  
         len = LEN(p);  
         for ( i = j = 0, s = s0, mr = BDY(p); j < len; j++, NMV_ADV(mr) ) {  
                 ndl_add(d,DL(mr),t);  
                 for ( ; !ndl_equal(t,s); s += nd_wpd, i++ );  
                 r[i] = CM(mr);  
         }  
         for ( i = 0; !r[i]; i++ );  
         return i;  
 }  
   
 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0,int n,NM_ind_pair pair)  IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0,int n,NM_ind_pair pair)
 {  {
         NM m;          NM m;
Line 3860  IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0
Line 3837  IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0
 int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred)  int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred)
 {  {
         int i,j,k,len,pos,prev;          int i,j,k,len,pos,prev;
         Q cs,mcs,c1,c2,cr,gcd;          Q cs,mcs,c1,c2,cr,gcd,t;
         IndArray ivect;          IndArray ivect;
         unsigned char *ivc;          unsigned char *ivc;
         unsigned short *ivs;          unsigned short *ivs;
Line 3880  int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat,
Line 3857  int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat,
                         len = LEN(redv); mr = BDY(redv);                          len = LEN(redv); mr = BDY(redv);
                         igcd_cofactor(svect[k],CQ(mr),&gcd,&cs,&cr);                          igcd_cofactor(svect[k],CQ(mr),&gcd,&cs,&cr);
                         chsgnq(cs,&mcs);                          chsgnq(cs,&mcs);
                           for ( j = 0; j < col; j++ ) {
                                   mulq(svect[j],cr,&c1); svect[j] = c1;
                           }
                         svect[k] = 0; prev = k;                          svect[k] = 0; prev = k;
                         switch ( ivect->width ) {                          switch ( ivect->width ) {
                                 case 1:                                  case 1:
                                         ivc = ivect->index.c;                                          ivc = ivect->index.c;
                                         for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) {                                          for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) {
                                                 pos = prev+ivc[j]; prev = pos;                                                  pos = prev+ivc[j]; prev = pos;
                                                 mulq(svect[pos],cr,&c1); mulq(CQ(mr),mcs,&c2); addq(c1,c2,&svect[pos]);                                                  mulq(CQ(mr),mcs,&c2); addq(svect[pos],c2,&t); svect[pos] = t;
                                         }                                          }
                                         break;                                          break;
                                 case 2:                                  case 2:
                                         ivs = ivect->index.s;                                          ivs = ivect->index.s;
                                         for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) {                                          for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) {
                                                 pos = prev+ivs[j]; prev = pos;                                                  pos = prev+ivs[j]; prev = pos;
                                                 mulq(svect[pos],cr,&c1); mulq(CQ(mr),mcs,&c2); addq(c1,c2,&svect[pos]);                                                  mulq(CQ(mr),mcs,&c2); addq(svect[pos],c2,&t); svect[pos] = t;
                                         }                                          }
                                         break;                                          break;
                                 case 4:                                  case 4:
                                         ivi = ivect->index.i;                                          ivi = ivect->index.i;
                                         for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) {                                          for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) {
                                                 pos = prev+ivi[j]; prev = pos;                                                  pos = prev+ivi[j]; prev = pos;
                                                 mulq(svect[pos],cr,&c1); mulq(CQ(mr),mcs,&c2); addq(c1,c2,&svect[pos]);                                                  mulq(CQ(mr),mcs,&c2); addq(svect[pos],c2,&t); svect[pos] = t;
                                         }                                          }
                                         break;                                          break;
                         }                          }
Line 4059  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead
Line 4039  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead
         for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++;          for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++;
         if ( !len ) return 0;          if ( !len ) return 0;
         else {          else {
                 mr0 = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len);                  mr0 = (NMV)GC_malloc(nmv_adv*len);
 #if 0  #if 0
                 ndv_alloc += nmv_adv*len;                  ndv_alloc += nmv_adv*len;
 #endif  #endif
Line 4068  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead
Line 4048  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead
                 for ( j = k = 0; j < col; j++, p += nd_wpd )                  for ( j = k = 0; j < col; j++, p += nd_wpd )
                         if ( !rhead[j] ) {                          if ( !rhead[j] ) {
                                 if ( c = vect[k++] ) {                                  if ( c = vect[k++] ) {
                                           if ( DN(c) )
                                                   error("afo");
                                         ndl_copy(p,DL(mr)); CQ(mr) = c; NMV_ADV(mr);                                          ndl_copy(p,DL(mr)); CQ(mr) = c; NMV_ADV(mr);
                                 }                                  }
                         }                          }
Line 4155  NODE nd_f4(int m)
Line 4137  NODE nd_f4(int m)
         PGeoBucket bucket;          PGeoBucket bucket;
         struct oEGT eg0,eg1,eg_f4;          struct oEGT eg0,eg1,eg_f4;
   
         if ( !m )  
                 error("nd_f4 : not implemented");  
 #if 0  #if 0
         ndv_alloc = 0;          ndv_alloc = 0;
 #endif  #endif
Line 4298  NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s
Line 4278  NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s
                 SG((NDV)BDY(r)) = spsugar[i];                  SG((NDV)BDY(r)) = spsugar[i];
                 GC_free(spmat[i]);                  GC_free(spmat[i]);
         }          }
           if ( r0 ) NEXT(r) = 0;
         for ( ; i < sprow; i++ ) GC_free(spmat[i]);          for ( ; i < sprow; i++ ) GC_free(spmat[i]);
         get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2);          get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2);
         init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2);          init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2);
Line 4328  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
Line 4309  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
         spcol = col-nred;          spcol = col-nred;
         get_eg(&eg0);          get_eg(&eg0);
         /* elimination (1st step) */          /* elimination (1st step) */
         spmat = (Q **)ALLOCA(nsp*sizeof(UINT *));          spmat = (Q **)ALLOCA(nsp*sizeof(Q *));
         svect = (Q *)ALLOCA(col*sizeof(UINT));          svect = (Q *)ALLOCA(col*sizeof(Q));
         spsugar = (int *)ALLOCA(nsp*sizeof(UINT));          spsugar = (int *)ALLOCA(nsp*sizeof(Q));
         for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) {          for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) {
                 nd_sp(0,0,sp,&spol);                  nd_sp(0,0,sp,&spol);
                 if ( !spol ) continue;                  if ( !spol ) continue;
Line 4338  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
Line 4319  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
                 maxrs = ndv_reduce_vect_q(svect,col,imat,rvect,nred);                  maxrs = ndv_reduce_vect_q(svect,col,imat,rvect,nred);
                 for ( i = 0; i < col; i++ ) if ( svect[i] ) break;                  for ( i = 0; i < col; i++ ) if ( svect[i] ) break;
                 if ( i < col ) {                  if ( i < col ) {
                         spmat[sprow] = v = (Q *)MALLOC_ATOMIC(spcol*sizeof(Q));                          spmat[sprow] = v = (Q *)MALLOC(spcol*sizeof(Q));
                         for ( j = k = 0; j < col; j++ )                          for ( j = k = 0; j < col; j++ )
                                 if ( !rhead[j] ) v[k++] = svect[j];                                  if ( !rhead[j] ) v[k++] = svect[j];
                         spsugar[sprow] = MAX(maxrs,SG(spol));                          spsugar[sprow] = MAX(maxrs,SG(spol));
                         sprow++;                          sprow++;
                 }                  }
                 nd_free(spol);  /*              nd_free(spol); */
         }          }
         get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1);          get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1);
         if ( DP_Print ) {          if ( DP_Print ) {
Line 4352  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
Line 4333  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
                 fflush(asir_out);                  fflush(asir_out);
         }          }
         /* free index arrays */          /* free index arrays */
         for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c);  /*      for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); */
   
         /* elimination (2nd step) */          /* elimination (2nd step) */
         colstat = (int *)ALLOCA(spcol*sizeof(int));          colstat = (int *)ALLOCA(spcol*sizeof(int));
Line 4362  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
Line 4343  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
                 NEXTNODE(r0,r); BDY(r) =                  NEXTNODE(r0,r); BDY(r) =
                         (pointer)vect_to_ndv_q(spmat[i],spcol,col,rhead,s0vect);                          (pointer)vect_to_ndv_q(spmat[i],spcol,col,rhead,s0vect);
                 SG((NDV)BDY(r)) = spsugar[i];                  SG((NDV)BDY(r)) = spsugar[i];
                 GC_free(spmat[i]);  /*              GC_free(spmat[i]); */
         }          }
         for ( ; i < sprow; i++ ) GC_free(spmat[i]);          if ( r0 ) NEXT(r) = 0;
   
   /*      for ( ; i < sprow; i++ ) GC_free(spmat[i]); */
         get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2);          get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2);
         init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2);          init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2);
         if ( DP_Print ) {          if ( DP_Print ) {
Line 4634  void nd_exec_f4_red_dist()
Line 4617  void nd_exec_f4_red_dist()
   
 int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int col,int *colstat)  int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int col,int *colstat)
 {  {
         int mod,i,j,t;          int mod,i,j,t,c,rank,rank0,inv;
           int *ci,*ri;
           Q dn;
           MAT m,nm;
         int **wmat;          int **wmat;
   
         /* XXX */          /* XXX */
Line 4651  int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int co
Line 4637  int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int co
                                 wmat[i][j] = 0;                                  wmat[i][j] = 0;
                 }                  }
         }          }
         nd_gauss_elim_mod(wmat,sugar,row,col,mod,colstat);          rank0 = nd_gauss_elim_mod(wmat,sugar,row,col,mod,colstat);
           NEWMAT(m); m->row = row; m->col = col; m->body = (pointer **)mat0;
           rank = generic_gauss_elim(m,&nm,&dn,&ri,&ci);
           if ( rank != rank0 )
                   error("afo");
           for ( i = 0; i < row; i++ )
                   for ( j = 0; j < col; j++ )
                           mat0[i][j] = 0;
           c = col-rank;
           for ( i = 0; i < rank; i++ ) {
                   mat0[i][ri[i]] = dn;
                   for ( j = 0; j < c; j++ )
                           mat0[i][ci[j]] = (Q)BDY(nm)[i][j];
           }
           inv = invm(rem(NM(dn),mod),mod);
           if ( SGN(dn) < 0 ) inv = mod-inv;
           for ( i = 0; i < row; i++ )
                   for ( j = 0; j < col; j++ ) {
                           if ( mat0[i][j] ) {
                                   t = rem(NM(mat0[i][j]),mod);
                                   if ( SGN(mat0[i][j]) < 0 ) t = mod-t;
                           } else
                                   t = 0;
                           c = dmar(t,inv,0,mod);
                           if ( wmat[i][j] != c )
                                   error("afo");
                   }
           return rank;
 }  }
   
 int nd_gauss_elim_mod(int **mat0,int *sugar,int row,int col,int md,int *colstat)  int nd_gauss_elim_mod(int **mat0,int *sugar,int row,int col,int md,int *colstat)

Legend:
Removed from v.1.108  
changed lines
  Added in v.1.109

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>