Changeset eccae7 in git for factory


Ignore:
Timestamp:
Nov 29, 2021, 3:12:38 PM (2 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
Children:
1c90ae397653250439ad7f58016a650d1f64d3af
Parents:
8e89a3717be03ec921eaaddd599f3dba8a2774be
Message:
fix: memeory leak with leadDeg in tryBrownGCD
Location:
factory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/cfGcdAlgExt.cc

    r8e89a3 reccae7  
    370370}
    371371
     372static void leadDeg(const CanonicalForm & f, int degs[])
     373{ // leading degree vector w.r.t. lex. monomial order x(i+1) > x(i)
     374  // 'a' should point to an array of sufficient size level(f)+1
     375  if(f.inCoeffDomain())
     376    return;
     377  CanonicalForm tmp = f;
     378  do
     379  {
     380    degs[tmp.level()] = tmp.degree();
     381    tmp = LC(tmp);
     382  }
     383  while(!tmp.inCoeffDomain());
     384}
     385
    372386void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail, bool topLevel )
    373387{ // assume F,G are multivariate polys over Z/p(a) for big prime p, M "univariate" polynomial in an algebraic variable
     
    530544    return;
    531545  }
    532   int *L = new int[mv+1]; // L is addressed by i from 2 to mv
    533   int *N = new int[mv+1];
     546  int L[mv+1];
     547  int N[mv+1];
    534548  for(int i=2; i<=mv; i++)
    535549    L[i] = N[i] = 0;
    536   L = leadDeg(f, L);
    537   N = leadDeg(g, N);
     550  leadDeg(f, L);
     551  leadDeg(g, N);
    538552  CanonicalForm gamma;
    539553  TIMING_START (alg_euclid_p)
     
    587601    for(int i=2; i<=mv; i++)
    588602      dg_im[i] = 0; // reset (this is necessary, because some entries may not be updated by call to leadDeg)
    589     dg_im = leadDeg(g_image, dg_im); // dg_im cannot be NIL-pointer
     603    leadDeg(g_image, dg_im);
    590604    if(isEqual(dg_im, L, 2, mv))
    591605    {
     
    786800  for(int i=1; i<=mv; i++) // initialize 'bound', 'other' with zeros
    787801    bound[i] = other[i] = 0;
    788   bound = leadDeg(f,bound); // 'bound' is set the leading degree vector of f
    789   other = leadDeg(g,other);
     802  leadDeg(f,bound); // 'bound' is set the leading degree vector of f
     803  leadDeg(g,other);
    790804  for(int i=1; i<=mv; i++) // entry at i=0 not visited
    791805    if(other[i] < bound[i])
     
    831845    for(int i=1; i<=mv; i++)
    832846      other[i] = 0; // reset (this is necessary, because some entries may not be updated by call to leadDeg)
    833     other = leadDeg(Dp,other);
     847    leadDeg(Dp,other);
    834848
    835849    if(isEqual(bound, other, 1, mv)) // equal
     
    918932
    919933
    920 int * leadDeg(const CanonicalForm & f, int *degs)
    921 { // leading degree vector w.r.t. lex. monomial order x(i+1) > x(i)
    922   // if f is in a coeff domain, the zero pointer is returned
    923   // 'a' should point to an array of sufficient size level(f)+1
    924   if(f.inCoeffDomain())
    925     return 0;
    926   CanonicalForm tmp = f;
    927   do
    928   {
    929     degs[tmp.level()] = tmp.degree();
    930     tmp = LC(tmp);
    931   }
    932   while(!tmp.inCoeffDomain());
    933   return degs;
    934 }
    935 
    936934
    937935bool isLess(int *a, int *b, int lower, int upper)
  • factory/cfGcdAlgExt.h

    r8e89a3 reccae7  
    3535void tryBrownGCD( const CanonicalForm & F, const CanonicalForm & G, const CanonicalForm & M, CanonicalForm & result, bool & fail, bool topLevel= true );
    3636
    37 int * leadDeg(const CanonicalForm & f, int *degs);
    3837bool isLess(int *a, int *b, int lower, int upper);
    3938bool isEqual(int *a, int *b, int lower, int upper);
Note: See TracChangeset for help on using the changeset viewer.