Changeset 3db016 in git for kernel


Ignore:
Timestamp:
Oct 4, 2018, 2:21:59 PM (6 years ago)
Author:
Karim Abou Zeid <karim23697@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
Children:
ebecd1b8b9d5d33b4cf7ba45c6db2ba7a6c31384f5d9018e6b9faaaf85ea0bc0a9a604290c0fa495
Parents:
032719177d9c8df44dff0988eee8f371af017fb4
Message:
Remove kernel dependency from libpolys and improve perfomance
Location:
kernel/GBEngine
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/GBEngine/kspoly.cc

    r032719 r3db016  
    2121#endif
    2222#include "kernel/GBEngine/shiftgb.h"
     23#include "polys/shiftop.h"
    2324
    2425#ifdef KDEBUG
  • kernel/GBEngine/shiftgb.cc

    r032719 r3db016  
    3131#include "kernel/GBEngine/shiftgb.h"
    3232#include "polys/nc/sca.h"
    33 
    34 
    35 #define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int))
    36 
    37 poly p_LPshift(poly p, int sh, const ring r)
    38 {
    39   if (sh == 0 || p == NULL) return(p);
    40 
    41   poly q  = NULL;
    42   poly pp = p;
    43   while (pp!=NULL)
    44   {
    45     poly h=pp;
    46     pIter(pp);
    47     pNext(h)=NULL;
    48     h=p_mLPshift(h,sh,r);
    49     q = p_Add_q(q, h,r);
    50   }
    51   return(q);
    52 }
    53 
    54 poly p_mLPshift(poly p, int sh, const ring r)
    55 {
    56   if (sh == 0 || p == NULL || p_LmIsConstantComp(p,r)) return(p);
    57 
    58   int lV = r->isLPring;
    59 
    60   int L = p_mLastVblock(p,r);
    61   assume(L+sh>=1);
    62   assume(L+sh<=r->N/lV);
    63 
    64   int *e=(int *)omAlloc0((r->N+1)*sizeof(int));
    65   int *s=(int *)omAlloc0((r->N+1)*sizeof(int));
    66   p_GetExpV(p,e,r);
    67 
    68   int j;
    69   //  for (j=1; j<=r->N; j++)
    70   // L*lV gives the last position of the last block
    71   for (j=1; j<= L*lV ; j++)
    72   {
    73     assume(e[j]<=1);
    74     if (e[j]==1)
    75     {
    76       assume(j + (sh*lV)<=r->N);
    77       assume(j + (sh*lV)>=1);
    78       s[j + (sh*lV)] = e[j]; /* actually 1 */
    79     }
    80   }
    81   p_SetExpV(p,s,r);
    82   freeT(e, r->N);
    83   freeT(s, r->N);
    84   /*  pSetm(m); */ /* done in the pSetExpV */
    85   /* think on the component and coefficient */
    86   //  number c = pGetCoeff(p);
    87   //  p_SetCoeff0(m,p_GetCoeff(p,r),r);
    88   return(p);
    89 }
     33#include "polys/shiftop.h"
    9034
    9135poly p_LPCopyAndShiftLM(poly p, int sh, const ring r)
    9236{
    9337  if (sh == 0 || p == NULL) return p;
    94   poly q = p_mLPshift(p_Head(p, r), sh, r);
     38
     39  poly q = p_Head(p, r);
     40  p_mLPshift(q, sh, r);
    9541  pNext(q) = pNext(p);
    9642  return q;
    97 }
    98 
    99 /* returns the number of maximal block */
    100 /* appearing among the monomials of p */
    101 /* the 0th block is the 1st one */
    102 int p_LastVblock(poly p, const ring r)
    103 {
    104   poly q = p;
    105   int ans = 0;
    106   while (q!=NULL)
    107   {
    108     int ansnew = p_mLastVblock(q, r);
    109     ans    = si_max(ans,ansnew);
    110     pIter(q);
    111   }
    112   return(ans);
    113 }
    114 
    115 /* for a monomial p, returns the number of the last block */
    116 /* where a nonzero exponent is sitting */
    117 int p_mLastVblock(poly p, const ring r)
    118 {
    119   if (p == NULL || p_LmIsConstantComp(p,r))
    120   {
    121     return(0);
    122   }
    123 
    124   int lV = r->isLPring;
    125   int *e=(int *)omAlloc0((r->N+1)*sizeof(int));
    126   p_GetExpV(p,e,r);
    127   int j,b;
    128   j = r->N;
    129   while ( (!e[j]) && (j>=1) ) j--;
    130   freeT(e, r->N);
    131   assume(j>0);
    132   b = (int)((j+lV-1)/lV); /* the number of the block, >=1 */
    133   return (b);
    134 }
    135 
    136 /* returns the number of maximal block */
    137 /* appearing among the monomials of p */
    138 /* the 0th block is the 1st one */
    139 int p_FirstVblock(poly p, const ring r)
    140 {
    141   if (p == NULL) {
    142     return 0;
    143   }
    144 
    145   poly q = p;
    146   int ans = p_mFirstVblock(q, r);
    147   while (q!=NULL)
    148   {
    149     int ansnew = p_mFirstVblock(q, r);
    150     if (ansnew > 0) { // don't count constants
    151       ans = si_min(ans,ansnew);
    152     }
    153     pIter(q);
    154   }
    155   /* do not need to delete q */
    156   return(ans);
    157 }
    158 
    159 /* for a monomial p, returns the number of the first block */
    160 /* where a nonzero exponent is sitting */
    161 int p_mFirstVblock(poly p, const ring r)
    162 {
    163   if (p == NULL || p_LmIsConstantComp(p,r))
    164   {
    165     return(0);
    166   }
    167 
    168   int lV = r->isLPring;
    169   int *e=(int *)omAlloc0((r->N+1)*sizeof(int));
    170   p_GetExpV(p,e,r);
    171   int j,b;
    172   j = 1;
    173   while ( (!e[j]) && (j<=r->N-1) ) j++;
    174   freeT(e, r->N);
    175   assume(j <= r->N);
    176   b = (int)(j+lV-1)/lV; /* the number of the block, 1<= b <= r->N  */
    177   return (b);
    17843}
    17944
     
    21277  }
    21378  /* do not need e anymore */
    214   freeT(e, currRing->N);
     79  omFreeSize((ADDRESS) e, (currRing->N+1)*sizeof(int));
    21580
    21681  if (j==0) goto ret_true;
     
    22590    if (B[j]!=1)
    22691    {
    227       freeT(B, b);
     92      omFreeSize((ADDRESS) B, (b+1)*sizeof(int));
    22893      return(0);
    22994    }
    23095  }
    23196 ret_true:
    232   freeT(B, b);
     97  omFreeSize((ADDRESS) B, (b+1)*sizeof(int));
    23398  return(1);
    23499}
     
    297162  m1 = p_GetExp_k_n(m1, hole, r->N, r);
    298163
    299   p_mLPshift(m2, 1 - p_mFirstVblock(m2, r), r);
     164  p_mLPunshift(m2, r);
    300165  p_SetCoeff(m1, m1Coeff, r);
     166
     167  assume(pFirstVblock(m1,r) <= 1);
     168  assume(pFirstVblock(m2,r) <= 1);
    301169}
    302170
  • kernel/GBEngine/shiftgb.h

    r032719 r3db016  
    1212#include "polys/nc/nc.h"
    1313
    14 poly p_LPshift(poly p, int sh, const ring r);
    15 poly p_mLPshift(poly p, int sh, const ring r);
    1614poly p_LPCopyAndShiftLM(poly p, int sh, const ring r);
    17 
    18 #define pLPshift(p, sh) p_LPshift(p, sh, currRing)
    19 #define pmLPshift(p, sh) p_mLPshift(p, sh, currRing)
    2015#define pLPCopyAndShiftLM(p, sh) p_LPCopyAndShiftLM(p, sh, currRing)
    21 
    22 int p_LastVblock(poly p, const ring r);
    23 int p_mLastVblock(poly p, const ring r);
    24 
    25 #define pLastVblock(p) p_LastVblock(p,currRing)
    26 #define pmLastVblock(p) p_mLastVblock(p,currRing)
    27 
    28 int p_FirstVblock(poly p, const ring r);
    29 int p_mFirstVblock(poly p, const ring r);
    30 
    31 #define pFirstVblock(p) p_FirstVblock(p,currRing)
    32 #define pmFirstVblock(p) p_mFirstVblock(p,currRing)
    3316
    3417int isInV(poly p, const ring r);
Note: See TracChangeset for help on using the changeset viewer.