Ignore:
Timestamp:
Mar 16, 2017, 4:29:28 PM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
f1cee38cd6cac02cfd2e0311e88e6d0feaf11505
Parents:
4fbbedd2f732aad850d2db9352ecc293ba229165
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2017-03-16 16:29:28+01:00
git-committer:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2017-03-16 16:48:34+01:00
Message:
Minor*: allocation -> omalloc, removed unueed routines, code cleanup

also fixes memory leak for minor(poly-matrix,int,SB)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/linear_algebra/MinorInterface.cc

    r4fbbed r733b51  
    1919
    2020using namespace std;
    21 
    22 static inline bool currRingIsOverIntegralDomain ()
    23 {
    24   return rField_is_Domain(currRing);
    25 }
    26 
    27 bool currRingIsOverField ()
    28 {
    29   if (rField_is_Ring_PtoM(currRing)) return false;
    30   if (rField_is_Ring_2toM(currRing)) return false;
    31   if (rField_is_Ring_ModN(currRing)) return false;
    32   if (rField_is_Ring_Z(currRing))    return false;
    33   return true;
    34 }
    3521
    3622/* returns true iff the given polyArray has only number entries;
     
    5339  {
    5440    nfPolyArray[i] = pCopy(polyArray[i]);
    55     if (iSB != 0) nfPolyArray[i] = kNF(iSB, currRing->qideal, nfPolyArray[i]);
     41    if (iSB != NULL)
     42    {
     43      poly tmp = kNF(iSB, currRing->qideal, nfPolyArray[i]);
     44      pDelete(&nfPolyArray[i]);
     45      nfPolyArray[i]=tmp;
     46    }
    5647    if (nfPolyArray[i] == NULL)
    5748    {
     
    9182  IntMinorProcessor mp;
    9283  mp.defineMatrix(rowCount, columnCount, intMatrix);
    93   int *myRowIndices=new int[rowCount];
     84  int *myRowIndices=(int*)omAlloc(rowCount*sizeof(int));
    9485  for (int j = 0; j < rowCount; j++) myRowIndices[j] = j;
    95   int *myColumnIndices=new int[columnCount];
     86  int *myColumnIndices=(int*)omAlloc(columnCount*sizeof(int));
    9687  for (int j = 0; j < columnCount; j++) myColumnIndices[j] = j;
    9788  mp.defineSubMatrix(rowCount, myRowIndices, columnCount, myColumnIndices);
     
    129120  else                      jjj = idCopyFirstK(iii, collectedMinors);
    130121  idDelete(&iii);
    131   delete[] myColumnIndices;
    132   delete[] myRowIndices;
     122  omFree(myColumnIndices);
     123  omFree(myRowIndices);
    133124  return jjj;
    134125}
     
    146137  PolyMinorProcessor mp;
    147138  mp.defineMatrix(rowCount, columnCount, polyMatrix);
    148   int *myRowIndices=new int[rowCount];
     139  int *myRowIndices=(int*)omAlloc(rowCount*sizeof(int));
    149140  for (int j = 0; j < rowCount; j++) myRowIndices[j] = j;
    150   int *myColumnIndices=new int[columnCount];
     141  int *myColumnIndices=(int*)omAlloc(columnCount*sizeof(int));
    151142  for (int j = 0; j < columnCount; j++) myColumnIndices[j] = j;
    152143  mp.defineSubMatrix(rowCount, myRowIndices, columnCount, myColumnIndices);
     
    191182     in iii which come after the computed minors */
    192183  idKeepFirstK(iii, collectedMinors);
    193   delete[] myColumnIndices;
    194   delete[] myRowIndices;
     184  omFree(myColumnIndices);
     185  omFree(myRowIndices);
    195186  return(iii);
    196187}
     
    208199  /* divert to special implementations for pure number matrices and actual
    209200     polynomial matrices: */
    210   int*  myIntMatrix  = new int [rowCount * columnCount];
    211   poly* nfPolyMatrix = new poly[rowCount * columnCount];
     201  int*  myIntMatrix  = (int*)omAlloc(rowCount * columnCount *sizeof(int));
     202  poly* nfPolyMatrix = (poly*)omAlloc(rowCount * columnCount *sizeof(poly));
    212203  if (arrayIsNumberArray(myPolyMatrix, i, rowCount * columnCount,
    213204                         myIntMatrix, nfPolyMatrix, zz))
     
    235226
    236227  /* clean up */
    237   delete [] myIntMatrix;
     228  omFree(myIntMatrix);
    238229  for (int j = 0; j < rowCount * columnCount; j++) pDelete(&nfPolyMatrix[j]);
    239   delete [] nfPolyMatrix;
     230  omFree(nfPolyMatrix);
    240231
    241232  return iii;
     
    279270     (if iSB is present, i.e., not the NULL pointer) */
    280271
    281     poly* nfPolyMatrix = new poly[length];
     272    poly* nfPolyMatrix = (poly*)omAlloc(length*sizeof(poly));
    282273    if (iSB != NULL)
    283274    {
     
    299290    /* clean up */
    300291    for (int j = length-1; j>=0; j--) pDelete(&nfPolyMatrix[j]);
    301     delete [] nfPolyMatrix;
     292    omFree(nfPolyMatrix);
    302293  }
    303294
     
    320311  IntMinorProcessor mp;
    321312  mp.defineMatrix(rowCount, columnCount, intMatrix);
    322   int *myRowIndices=new int[rowCount];
     313  int *myRowIndices=(int*)omAlloc(rowCount*sizeof(int));
    323314  for (int j = 0; j < rowCount; j++) myRowIndices[j] = j;
    324   int *myColumnIndices=new int[columnCount];
     315  int *myColumnIndices=(int*)omAlloc(columnCount*sizeof(int));
    325316  for (int j = 0; j < columnCount; j++) myColumnIndices[j] = j;
    326317  mp.defineSubMatrix(rowCount, myRowIndices, columnCount, myColumnIndices);
     
    360351  else                      jjj = idCopyFirstK(iii, collectedMinors);
    361352  idDelete(&iii);
    362   delete[] myColumnIndices;
    363   delete[] myRowIndices;
     353  omFree(myColumnIndices);
     354  omFree(myRowIndices);
    364355  return jjj;
    365356}
     
    378369  PolyMinorProcessor mp;
    379370  mp.defineMatrix(rowCount, columnCount, polyMatrix);
    380   int *myRowIndices=new int[rowCount];
     371  int *myRowIndices=(int*)omAlloc(rowCount*sizeof(int));
    381372  for (int j = 0; j < rowCount; j++) myRowIndices[j] = j;
    382   int *myColumnIndices=new int[columnCount];
     373  int *myColumnIndices=(int*)omAlloc(columnCount*sizeof(int));
    383374  for (int j = 0; j < columnCount; j++) myColumnIndices[j] = j;
    384375  mp.defineSubMatrix(rowCount, myRowIndices, columnCount, myColumnIndices);
     
    428419  else                      jjj = idCopyFirstK(iii, collectedMinors);
    429420  idDelete(&iii);
    430   delete[] myColumnIndices;
    431   delete[] myRowIndices;
     421  omFree(myColumnIndices);
     422  omFree(myRowIndices);
    432423  return jjj;
    433424}
     
    446437  /* divert to special implementation when myPolyMatrix has only number
    447438     entries: */
    448   int*  myIntMatrix  = new int [rowCount * columnCount];
    449   poly* nfPolyMatrix = new poly[rowCount * columnCount];
     439  int*  myIntMatrix  = (int*)omAlloc(rowCount * columnCount *sizeof(int));
     440  poly* nfPolyMatrix = (poly*)omAlloc(rowCount * columnCount *sizeof(poly));
    450441  if (arrayIsNumberArray(myPolyMatrix, iSB, rowCount * columnCount,
    451442                         myIntMatrix, nfPolyMatrix, zz))
     
    459450
    460451  /* clean up */
    461   delete [] myIntMatrix;
     452  omFree(myIntMatrix);
    462453  for (int j = 0; j < rowCount * columnCount; j++) pDelete(&nfPolyMatrix[j]);
    463   delete [] nfPolyMatrix;
     454  omFree(nfPolyMatrix);
    464455
    465456  return iii;
     
    480471  poly* myPolyMatrix = (poly*)(mat->m);
    481472  int length = rowCount * columnCount;
    482   poly* nfPolyMatrix = new poly[length];
     473  poly* nfPolyMatrix = (poly*)omAlloc(length*sizeof(poly));
    483474  ideal iii; /* the ideal to be filled and returned */
    484475
     
    487478  for (int i = 0; i < length; i++)
    488479  {
    489     nfPolyMatrix[i] = pCopy(myPolyMatrix[i]);
    490     if (iSB != 0) nfPolyMatrix[i] = kNF(iSB, currRing->qideal,
    491                                         nfPolyMatrix[i]);
     480    if (iSB==NULL)
     481      nfPolyMatrix[i] = pCopy(myPolyMatrix[i]);
     482    else
     483      nfPolyMatrix[i] = kNF(iSB, currRing->qideal, myPolyMatrix[i]);
    492484  }
    493485
     
    498490  /* clean up */
    499491  for (int j = 0; j < length; j++) pDelete(&nfPolyMatrix[j]);
    500   delete [] nfPolyMatrix;
     492  omFree(nfPolyMatrix);
    501493
    502494  return iii;
     
    534526  bool l = false; /* Laplace without caching */
    535527  // bool c = false; /* Laplace with caching */
    536   if (currRingIsOverIntegralDomain())
     528  if (rField_is_Domain(currRing))
    537529  { /* the field case or ring Z */
    538530    if      (minorSize <= 2)                                     b = true;
    539531    else if (vars <= 2)                                          b = true;
    540     else if (currRingIsOverField() && (vars == 3)
     532    else if ((!rField_is_Ring(currRing)) && (vars == 3)
    541533             && (currRing->cf->ch >= 2) && (currRing->cf->ch <= NV_MAX_PRIME))
    542534          b = true;
     
    547539    else
    548540    { /* k == 0, i.e., all minors are requested */
    549       int minorCount = binom(rowCount, minorSize);
    550       minorCount *= binom(columnCount, minorSize);
    551       // if      ((minorSize >= 3) && (vars <= 4)
    552       //          && (minorCount >= 100))                           c = true;
    553       // else if ((minorSize >= 3) && (vars >= 5)
    554       //          && (minorCount >= 40))                            c = true;
    555       /*else*/                                                      l = true;
     541      l = true;
    556542    }
    557543  }
Note: See TracChangeset for help on using the changeset viewer.