bridge/class-master/depend/pari/src/basemath/alglin1.c
/* M is a RgMs with nbrow rows, A a list of row indices.
   Eliminate rows of M with a single entry that do not belong to A,
   and the corresponding columns. Also eliminate columns until #colums=#rows.
   Return pcol and prow:
   pcol is a map from the new columns indices to the old one.
   prow is a map from the old rows indices to the new one (0 if removed).
*/
M is a RgMs with nbrow rows, A a list of row indices.
Eliminate rows of M with a single entry that do not belong to A,
and the corresponding columns. Also eliminate columns until #colums=#rows.
Return pcol and prow:
pcol is a map from the new columns indices to the old one.
prow is a map from the old rows indices to the new one (0 if removed).
M is a RgMs with nbrow rows A a list of row indices . Eliminate rows of M with a single entry that do not belong to A and the corresponding columns . Also eliminate columns until #colums = #rows . Return pcol and prow : pcol is a map from the new columns indices to the old one . prow is a map from the old rows indices to the new one ( 0 if removed ) .
void
RgMs_structelim_col(GEN M, long nbcol, long nbrow, GEN A, GEN *p_col, GEN *p_row)
{
  long i,j,k;
  long lA = lg(A);
  GEN prow = cgetg(nbrow+1, t_VECSMALL);
  GEN pcol = zero_zv(nbcol);
  pari_sp av = avma;
  long rcol = nbcol, rrow = 0, imin = nbcol - usqrt(nbcol);
  GEN iscol = const_vecsmall(nbcol, 1);
  GEN Wrow  = zero_zv(nbrow);
  GEN wcol = cgetg(nbcol+1, t_VECSMALL);
  pari_sp av2=avma;
  for (i = 1; i <= nbcol; ++i)
  {
    GEN F = gmael(M, i, 1);
    long l = lg(F)-1;
    for (j = 1; j <= l; ++j)
      Wrow[F[j]]++;
  }
  for (j = 1; j < lA; ++j)
  {
    if (Wrow[A[j]] == 0) { *p_col=NULL; return; }
    Wrow[A[j]] = -1;
  }
  for (i = 1; i <= nbrow; ++i)
    if (Wrow[i])
      rrow++;
  rem_singleton(M, iscol, Wrow, &rcol, &rrow);
  if (rcol<rrow) pari_err_BUG("RgMs_structelim, rcol<rrow");
  for (; rcol>rrow;)
  {
    long w;
    GEN per = fill_wcol(M, iscol, Wrow, &w, wcol);
    for (i = nbcol; i>=imin && wcol[per[i]]>=w && rcol>rrow; i--)
      rem_col(gmael(M, per[i], 1), per[i], iscol, Wrow, &rcol, &rrow);
    rem_singleton(M, iscol, Wrow, &rcol, &rrow);
    avma = av2;
  }
  for (j = 1, i = 1; i <= nbcol; ++i)
    if (iscol[i])
      pcol[j++] = i;
  setlg(pcol,j);
  for (k = 1, i = 1; i <= nbrow; ++i)
    prow[i] = Wrow[i] ? k++: 0;
  avma = av;
  *p_col = pcol; *p_row = prow;
}
void RgMs_structelim_col ( GEN M , long nbcol , long nbrow , GEN A , GEN * p_col , GEN * p_row ) { long i , j , k ; long lA = lg ( A ) ; GEN prow = cgetg ( nbrow + 1 , t_VECSMALL ) ; GEN pcol = zero_zv ( nbcol ) ; pari_sp av = avma ; long rcol = nbcol , rrow = 0 , imin = nbcol - usqrt ( nbcol ) ; GEN iscol = const_vecsmall ( nbcol , 1 ) ; GEN Wrow = zero_zv ( nbrow ) ; GEN wcol = cgetg ( nbcol + 1 , t_VECSMALL ) ; pari_sp av2 = avma ; for ( i = 1 ; i <= nbcol ; ++ i ) { GEN F = gmael ( M , i , 1 ) ; long l = lg ( F ) - 1 ; for ( j = 1 ; j <= l ; ++ j ) Wrow [ F [ j ] ] ++ ; } for ( j = 1 ; j < lA ; ++ j ) { if ( Wrow [ A [ j ] ] == 0 ) { * p_col = NULL ; return ; } Wrow [ A [ j ] ] = -1 ; } for ( i = 1 ; i <= nbrow ; ++ i ) if ( Wrow [ i ] ) rrow ++ ; rem_singleton ( M , iscol , Wrow , & rcol , & rrow ) ; if ( rcol < rrow ) pari_err_BUG ( " " ) ; for ( ; rcol > rrow ; ) { long w ; GEN per = fill_wcol ( M , iscol , Wrow , & w , wcol ) ; for ( i = nbcol ; i >= imin && wcol [ per [ i ] ] >= w && rcol > rrow ; i -- ) rem_col ( gmael ( M , per [ i ] , 1 ) , per [ i ] , iscol , Wrow , & rcol , & rrow ) ; rem_singleton ( M , iscol , Wrow , & rcol , & rrow ) ; avma = av2 ; } for ( j = 1 , i = 1 ; i <= nbcol ; ++ i ) if ( iscol [ i ] ) pcol [ j ++ ] = i ; setlg ( pcol , j ) ; for ( k = 1 , i = 1 ; i <= nbrow ; ++ i ) prow [ i ] = Wrow [ i ] ? k ++ : 0 ; avma = av ; * p_col = pcol ; * p_row = prow ; }
M is a RgMs with nbrow rows, A a list of row indices.
M is a RgMs with nbrow rows A a list of row indices .