Changeset 462f5d in git


Ignore:
Timestamp:
Aug 2, 2016, 2:20:33 PM (8 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
39b90e9373410f209be536692f8ad127c852cc0e
Parents:
2ca98b322f5cd4132f63aa412234febf9a402043
Message:
cleanup shiftgb.cc

removed duplicate code (pLPshift,pLastVblock)
copied fix for tr.#767 to p_LPshift, p_LastVblock
memory handling in p_LPshiftT
checking user input in extra.cc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Singular/extra.cc

    r2ca98b3 r462f5d  
    310310        char tbuf[MAXPATHLEN];
    311311        char *s=omFindExec((char*)h->Data(),tbuf);
    312         if(s==NULL) s=(char*)"";
     312        if(s==NULL) s=(char*)"";
    313313        res->data=(void *)omStrDup(s);
    314314        res->rtyp=STRING_CMD;
     
    10981098        h=h->next;
    10991099        int lVblock=(int)((long)(h->Data()));
     1100        if (sh<0)
     1101        {
     1102          WerrorS("negative shift for pLPshift");
     1103          return TRUE;
     1104        }
     1105        int L = pmLastVblock(p,lVblock);
     1106        if (L+sh-1 > uptodeg)
     1107        {
     1108          WerrorS("pLPshift: too big shift requested\n");
     1109          return TRUE;
     1110        }
    11001111        res->data = pLPshift(p,sh,uptodeg,lVblock);
    11011112        res->rtyp = POLY_CMD;
     
    33763387          }
    33773388          else
    3378           {
    3379             WerrorS("expected `system(\"HNF\",<matrix|intmat|bigintmat>)`");
    3380             return TRUE;
    3381           }
     3389          {
     3390            WerrorS("expected `system(\"HNF\",<matrix|intmat|bigintmat>)`");
     3391            return TRUE;
     3392          }
    33823393        }
    33833394        else return TRUE;
  • kernel/GBEngine/shiftgb.cc

    r2ca98b3 r462f5d  
    4747  /* assume shift takes place, shifts the poly p by sh */
    4848  /* p is like TObject: lm in currRing = r, tail in tailRing  */
     49  /* copies p */
    4950
    5051  if (p==NULL) return(p);
     
    5859
    5960  poly q   = NULL;
    60   poly s   = p_mLPshift(p, sh, uptodeg, lV, r); // lm in currRing
     61  poly s   = p_mLPshift(p_Head(p,r), sh, uptodeg, lV, r); // lm in currRing
     62  /* pNext(s) will be fixed below */
    6163  poly pp = pNext(p);
    6264
    6365  while (pp != NULL)
    6466  {
    65     q = p_Add_q(q, p_mLPshift(pp,sh,uptodeg,lV,strat->tailRing),strat->tailRing);
     67    poly h=p_mLPshift(p_Head(pp,strat->tailRing),sh,uptodeg,lV,strat->tailRing);
    6668    pIter(pp);
     69
     70    q = p_Add_q(q, h,strat->tailRing);
    6771  }
    6872  pNext(s) = q;
     
    7175}
    7276
    73 
    7477poly p_LPshift(poly p, int sh, int uptodeg, int lV, const ring r)
    7578{
     
    7881
    7982  /* assume sh and uptodeg agree TODO check */
    80 
    81   if (p==NULL) return(p);
     83  assume(sh>=0);
     84
    8285  if (sh == 0) return(p); /* the zero shift */
    8386
    8487  poly q  = NULL;
    85   poly pp = p; // do not take copies
     88  poly pp = p;
    8689  while (pp!=NULL)
    8790  {
    88     q = p_Add_q(q, p_mLPshift(pp,sh,uptodeg,lV,r),r);
     91    poly h=pp;
    8992    pIter(pp);
     93    pNext(h)=NULL;
     94    h=p_mLPshift(h,sh,uptodeg,lV,r);
     95    q = p_Add_q(q, h,r);
    9096  }
    9197  return(q);
     
    98104  if (sh == 0) return(p); /* the zero shift */
    99105
    100   if (sh < 0 )
    101   {
    102 #ifdef PDEBUG
    103     PrintS("pmLPshift: negative shift requested\n");
    104 #endif
    105     return(NULL); /* violation, 2check */
    106   }
    107 
     106  assume(sh>=0);
    108107  int L = p_mLastVblock(p,lV,r);
    109   if (L+sh-1 > uptodeg)
    110   {
    111 #ifdef PDEBUG
    112     PrintS("p_mLPshift: too big shift requested\n");
    113 #endif
    114     return(NULL); /* violation, 2check */
    115   }
     108  assume(L+sh-1<=uptodeg);
     109
    116110  int *e=(int *)omAlloc0((r->N+1)*sizeof(int));
    117111  int *s=(int *)omAlloc0((r->N+1)*sizeof(int));
     
    123117  for (j=1; j<= L*lV ; j++)
    124118  {
     119    assume(e[j]<=1);
    125120    if (e[j]==1)
    126121    {
     122      assume(j + (sh*lV)<=r->N);
    127123      s[j + (sh*lV)] = e[j]; /* actually 1 */
    128 #ifdef PDEBUG
    129       omCheckAddr(s);
    130 #endif
    131     }
    132 #ifdef PDEBUG
    133     else
    134     {
    135       if (e[j]!=0)
    136       {
    137          //         Print("p_mLPshift: ex[%d]=%d\n",j,e[j]);
    138       }
    139     }
    140 #endif
    141   }
    142   poly m = p_One(r);
    143   p_SetExpV(m,s,r);
     124    }
     125  }
     126  p_SetExpV(p,s,r);
    144127  freeT(e, r->N);
    145128  freeT(s, r->N);
     
    148131  //  number c = pGetCoeff(p);
    149132  //  p_SetCoeff0(m,p_GetCoeff(p,r),r);
    150   p_SetComp(m,p_GetComp(p,r),r); // component is preserved
    151   p_SetCoeff0(m,n_Copy(p_GetCoeff(p,r),r->cf),r);  // coeff is preserved
    152   return(m);
    153 }
    154 
    155 poly pLPshift(poly p, int sh, int uptodeg, int lV)
    156 {
    157   /* assume shift takes place */
    158   /* shifts the poly p by sh */
    159   /* deletes p */
    160 
    161   /* assume sh and uptodeg agree */
    162 
    163   if (sh == 0) return(p); /* the zero shift */
    164 
    165   poly q  = NULL;
    166   poly pp = p;
    167   while (pp!=NULL)
    168   {
    169     poly h=pp;
    170     pIter(pp);
    171     pNext(h)=NULL;
    172     h=pmLPshift(h,sh,uptodeg,lV);
    173     q = p_Add_q(q, h,currRing);
    174   }
    175   return(q);
    176 }
    177 
    178 poly pmLPshift(poly p, int sh, int uptodeg, int lV)
    179 {
    180   /* TODO: use a shortcut with p_ version */
    181   /* pm is a monomial */
    182 
    183   if (sh == 0) return(p); /* the zero shift */
    184 
    185   if (sh < 0 )
    186   {
    187 #ifdef PDEBUG
    188     PrintS("pmLPshift: negative shift requested\n");
    189 #endif
    190     return(NULL); /* violation, 2check */
    191   }
    192 
    193   int L = pmLastVblock(p,lV);
    194   if (L+sh-1 > uptodeg)
    195   {
    196 #ifdef PDEBUG
    197     PrintS("pmLPshift: too big shift requested\n");
    198 #endif
    199     return(NULL); /* violation, 2check */
    200   }
    201   int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int));
    202   int *s=(int *)omAlloc0((currRing->N+1)*sizeof(int));
    203   pGetExpV(p,e);
    204   int j;
    205   for (j=1; j<=currRing->N; j++)
    206   {
    207     if (e[j]==1)
    208     {
    209       s[j + (sh*lV)] = e[j]; /* actually 1 */
    210     }
    211   }
    212   pSetExpV(p,s);
    213   /*  pSetm(m); */ /* done in the pSetExpV */
    214   freeT(e, currRing->N);
    215   freeT(s, currRing->N);
    216133  return(p);
    217 }
    218 
    219 int pLastVblock(poly p, int lV)
    220 {
    221   /* returns the number of maximal block */
    222   /* appearing among the monomials of p */
    223   /* the 0th block is the 1st one */
    224   poly q = p; //p_Copy(p,currRing); /* need it ? */
    225   int ans = 0;
    226   int ansnew = 0;
    227   while (q!=NULL)
    228   {
    229     ansnew = pmLastVblock(q,lV);
    230     ans    = si_max(ans,ansnew);
    231     pIter(q);
    232   }
    233   /* do not need to delete q */
    234   return(ans);
    235 }
    236 
    237 int pmLastVblock(poly p, int lV)
    238 {
    239   /* for a monomial p, returns the number of the last block */
    240   /* where a nonzero exponent is sitting */
    241   if (pIsConstantPoly(p))
    242   {
    243     return(int(0));
    244   }
    245   int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int));
    246   pGetExpV(p,e);
    247   int j,b;
    248   j = currRing->N;
    249   while ( (!e[j]) && (j>=1) ) j--;
    250   freeT(e, currRing->N);
    251   if (j==0)
    252   {
    253 #ifdef PDEBUG
    254     PrintS("pmLastVblock: unexpected zero exponent vector\n");
    255 #endif
    256     return(j);
    257   }
    258   b = (int)(j/lV) + 1; /* the number of the block, >=1 */
    259   return (b);
    260134}
    261135
     
    288162  /* appearing among the monomials of p */
    289163  /* the 0th block is the 1st one */
    290   poly q = p; //p_Copy(p,currRing); /* need it ? */
     164  poly q = p;
    291165  int ans = 0;
    292166  int ansnew = 0;
     
    297171    pIter(q);
    298172  }
    299   /* do not need to delete q */
    300173  return(ans);
    301174}
     
    314187  j = r->N;
    315188  while ( (!e[j]) && (j>=1) ) j--;
    316   if (j==0)
    317   {
    318 #ifdef PDEBUG
    319     PrintS("pmLastVblock: unexpected zero exponent vector\n");
    320 #endif
    321     return(j);
    322   }
     189  freeT(e, r->N);
     190  assume(j>0);
    323191  b = (int)((j+lV-1)/lV); /* the number of the block, >=1 */
    324   freeT(e,r->N);
    325192  return (b);
    326193}
  • kernel/GBEngine/shiftgb.h

    r2ca98b3 r462f5d  
    2727int p_LastVblock(poly p, int lV, const ring r);
    2828
    29 poly pLPshift(poly p, int sh, int uptodeg, int lV);
    30 poly pmLPshift(poly p, int sh, int uptodeg, int lV);
     29//poly pLPshift(poly p, int sh, int uptodeg, int lV);
     30#define pLPshift(p,sh,uptodeg,lV) p_LPshift(p,sh,uptodeg,lV,currRing)
    3131
    32 int pLastVblock(poly p, int lV);
    33 int pmLastVblock(poly p, int lV);
     32//int pLastVblock(poly p, int lV);
     33#define pLastVblock(p,lV) p_LastVblock(p,lV,currRing)
     34//int pmLastVblock(poly p, int lV);
     35#define pmLastVblock(p,lV) p_mLastVblock(p,lV,currRing)
    3436
    3537int pFirstVblock(poly p, int lV);
Note: See TracChangeset for help on using the changeset viewer.