Skip to content

Commit

Permalink
Bug fixed in idMinors (wrong ring at idDelete) + code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Motsak committed May 27, 2015
1 parent bf36c43 commit 49b7480
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions kernel/ideals.cc
Expand Up @@ -1780,52 +1780,68 @@ ideal idMinors(matrix a, int ar, ideal R)
return (result);
}
#else
/*2
* compute all ar-minors of the matrix a
* the caller of mpRecMin
* the elements of the result are not in R (if R!=NULL)
*/


/// compute all ar-minors of the matrix a
/// the caller of mpRecMin
/// the elements of the result are not in R (if R!=NULL)
ideal idMinors(matrix a, int ar, ideal R)
{
int elems=0;
int r=a->nrows,c=a->ncols;
int i;
matrix b;
ideal result,h;
ring origR=currRing;
ring tmpR;
long bound;

const ring origR=currRing;
id_Test((ideal)a, origR);

const int r = a->nrows;
const int c = a->ncols;

if((ar<=0) || (ar>r) || (ar>c))
{
Werror("%d-th minor, matrix is %dx%d",ar,r,c);
return NULL;
}
h = id_Matrix2Module(mp_Copy(a,origR),origR);
bound = sm_ExpBound(h,c,r,ar,origR);
idDelete(&h);
tmpR=sm_RingChange(origR,bound);
b = mpNew(r,c);
for (i=r*c-1;i>=0;i--)
{
if (a->m[i])

ideal h = id_Matrix2Module(mp_Copy(a,origR),origR);
long bound = sm_ExpBound(h,c,r,ar,origR);
id_Delete(&h, origR);

ring tmpR = sm_RingChange(origR,bound);

matrix b = mpNew(r,c);

for (int i=r*c-1;i>=0;i--)
if (a->m[i] != NULL)
b->m[i] = prCopyR(a->m[i],origR,tmpR);
}

id_Test( (ideal)b, tmpR);

if (R!=NULL)
{
R = idrCopyR(R,origR,tmpR);
R = idrCopyR(R,origR,tmpR); // TODO: overwrites R? memory leak?
//if (ar>1) // otherwise done in mpMinorToResult
//{
// matrix bb=(matrix)kNF(R,currRing->qideal,(ideal)b);
// bb->rank=b->rank; bb->nrows=b->nrows; bb->ncols=b->ncols;
// idDelete((ideal*)&b); b=bb;
//}
id_Test( R, tmpR);
}
result=idInit(32,1);
if(ar>1) mp_RecMin(ar-1,result,elems,b,r,c,NULL,R,tmpR);
else mp_MinorToResult(result,elems,b,r,c,R,tmpR);
idDelete((ideal *)&b);


ideal result = idInit(32,1);

int elems = 0;

if(ar>1)
mp_RecMin(ar-1,result,elems,b,r,c,NULL,R,tmpR);
else
mp_MinorToResult(result,elems,b,r,c,R,tmpR);

id_Test( (ideal)b, tmpR);

id_Delete((ideal *)&b, tmpR);

if (R!=NULL) idDelete(&R);

idSkipZeroes(result);
rChangeCurrRing(origR);
result = idrMoveR(result,tmpR,origR);
Expand Down

0 comments on commit 49b7480

Please sign in to comment.