Changeset e68029 in git for libpolys/polys/flintconv.cc


Ignore:
Timestamp:
Jan 19, 2022, 9:40:11 AM (2 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
3882094d003ecd5487dfad0aa941dee9d650a30e
Parents:
844f3006400f1bbcfdb84aa86a873413a954da98
Message:
rref for smatrix and ntl
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/flintconv.cc

    r844f30 re68029  
    391391      {
    392392        poly h=MATELEM(m,i,j);
    393         if (h==NULL)
    394           convSingNFlintN(fmpq_mat_entry(FLINTM,i-1,j-1),n,R->cf);
    395         else if (p_Totaldegree(h,R)==0)
     393        if ((h!=NULL)
     394        && (p_Totaldegree(h,R)==0))
    396395          convSingNFlintN(fmpq_mat_entry(FLINTM,i-1,j-1),pGetCoeff(h),R->cf);
    397         else
    398         {
    399           WerrorS("matrix for rref is nor constant");
    400           return M;
    401         }
     396        else
     397        {
     398          WerrorS("matrix for rref is not constant");
     399          return M;
     400        }
    402401      }
    403402    }
     
    447446}
    448447
     448ideal singflint_rref(ideal  m, const ring R) /*assume smatrix m*/
     449{
     450  int r=m->rank;
     451  int c=m->ncols;
     452  int i,j;
     453  ideal M=idInit(c,r);
     454  if (rField_is_Q(R))
     455  {
     456    fmpq_mat_t FLINTM;
     457    fmpq_mat_init(FLINTM,r,c);
     458    for(j=c;j>0;j--)
     459    {
     460      poly h=m->m[j];
     461      while(h!=NULL)
     462      {
     463        i=p_GetComp(h,R);
     464        if (p_Totaldegree(h,R)==0)
     465          convSingNFlintN(fmpq_mat_entry(FLINTM,i-1,j-1),p_GetCoeff(h,R),R->cf);
     466        else
     467        {
     468          WerrorS("smatrix for rref is not constant");
     469          return M;
     470        }
     471        pIter(h);
     472      }
     473    }
     474    fmpq_mat_rref(FLINTM,FLINTM);
     475    for(i=r;i>0;i--)
     476    {
     477      for(j=c;j>0;j--)
     478      {
     479        number n=convFlintNSingN(fmpq_mat_entry(FLINTM,i-1,j-1),R->cf);
     480        if(!n_IsZero(n,R->cf))
     481        {
     482          poly p=p_NSet(n,R);
     483          p_SetComp(p,i,R);
     484          M->m[j]=p_Add_q(M->m[j],p,R);
     485        }
     486      }
     487    }
     488    fmpq_mat_clear(FLINTM);
     489  }
     490  else if (rField_is_Zp(R))
     491  {
     492    nmod_mat_t FLINTM;
     493    nmod_mat_init(FLINTM,r,c,rChar(R));
     494    for(j=c;j>0;j--)
     495    {
     496      poly h=m->m[j];
     497      while(h!=NULL)
     498      {
     499        i=p_GetComp(h,R);
     500        if (p_Totaldegree(h,R)==0)
     501          nmod_mat_entry(FLINTM,i-1,j-1)=(long)p_GetCoeff(h,R);
     502        else
     503        {
     504          WerrorS("smatrix for rref is not constant");
     505          return M;
     506        }
     507        pIter(h);
     508      }
     509    }
     510    nmod_mat_rref(FLINTM);
     511    for(i=r;i>0;i--)
     512    {
     513      for(j=c;j>0;j--)
     514      {
     515        number n=n_Init(nmod_mat_entry(FLINTM,i-1,j-1),R->cf);
     516        if(!n_IsZero(n,R->cf))
     517        {
     518          poly p=p_NSet(n,R);
     519          p_SetComp(p,i,R);
     520          M->m[j]=p_Add_q(M->m[j],p,R);
     521        }
     522      }
     523    }
     524    nmod_mat_clear(FLINTM);
     525  }
     526  else
     527  {
     528    #if 0
     529    fmpz_t p;
     530    convSingIFlintI(p,rChar(currRing));
     531    fq_nmod_ctx_init(ctx,p,1,"t");
     532    fq_nmod_mat_t FLINTM;
     533    // convert matrix
     534    convSingMFlintFq_nmod_mat(M,FLINTM,ctx,currRing);
     535    // rank
     536    long rk= fq_nmod_mat_rref (FLINTM,ctx);
     537    res->data=(void*)convFlintFq_nmod_matSingM(FLINTM,ctx,currRing);
     538    // clean up
     539    fq_nmod_mat_clear (FLINTM,ctx);
     540    fq_nmod_ctx_clear(ctx);
     541    fmpz_clear(p);
     542    #endif
     543    WerrorS("not implemented for these coefficients");
     544  }
     545  return M;
     546}
     547
    449548bigintmat* singflint_LLL(bigintmat*  m, bigintmat* T)
    450549{
Note: See TracChangeset for help on using the changeset viewer.