Changeset e68029 in git


Ignore:
Timestamp:
Jan 19, 2022, 9:40:11 AM (17 months ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '23b0a9c07070b684aa12355009488dc00d9501e3')
Children:
3882094d003ecd5487dfad0aa941dee9d650a30e
Parents:
844f3006400f1bbcfdb84aa86a873413a954da98
Message:
rref for smatrix and ntl
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/extra.cc

    r844f30 re68029  
    12391239  #endif
    12401240/* ====== rref ============================*/
    1241   #ifdef HAVE_FLINT
     1241  #if defined(HAVE_FLINT) || defined(HAVE_NTL)
    12421242  if(strcmp(sys_cmd,"rref")==0)
    12431243  {
    12441244    const short t1[]={1,MATRIX_CMD};
    1245     if (iiCheckTypes(h,t1,1))
     1245    const short t2[]={1,SMATRIX_CMD};
     1246    if (iiCheckTypes(h,t1,0))
    12461247    {
    12471248      matrix M=(matrix)h->Data();
     1249      #if defined(HAVE_FLINT)
    12481250      res->data=(void*)singflint_rref(M,currRing);
     1251      #elif defined(HAVE_NTL)
     1252      res->data=(void*)singntl_rref(M,currRing);
     1253      #endif
    12491254      res->rtyp=MATRIX_CMD;
    12501255      return FALSE;
    12511256    }
    1252     else
    1253     {
    1254       WerrorS("expected system(\"rref\",<matrix>)");
     1257    else if (iiCheckTypes(h,t2,1))
     1258    {
     1259      ideal M=(ideal)h->Data();
     1260      #if defined(HAVE_FLINT)
     1261      res->data=(void*)singflint_rref(M,currRing);
     1262      #elif defined(HAVE_NTL)
     1263      res->data=(void*)singntl_rref(M,currRing);
     1264      #endif
     1265      res->rtyp=SMATRIX_CMD;
     1266      return FALSE;
     1267    }
     1268    else
     1269    {
     1270      WerrorS("expected system(\"rref\",<matrix>/<smatrix>)");
    12551271      return TRUE;
    12561272    }
  • libpolys/polys/clapsing.cc

    r844f30 re68029  
    2424#include "polys/flint_mpoly.h"
    2525
     26#ifdef HAVE_NTL
     27#include <NTL/config.h>
     28#ifdef NTL_STD_CXX
     29#ifdef NOSTREAMIO
     30#  ifdef HAVE_IOSTREAM
     31#    include <iostream>
     32#    define OSTREAM std::ostream
     33#    define ISTREAM std::istream
     34#  elif defined(HAVE_IOSTREAM_H)
     35#    include <iostream.h>
     36#    define OSTREAM ostream
     37#    define ISTREAM istream
     38#  endif
     39#endif /* ! NOSTREAMIO */
     40#endif
     41#include <NTL/mat_ZZ.h>
     42#include <NTL/mat_lzz_p.h>
     43
     44#ifdef NTL_CLIENT               // in <NTL/tools.h>: using of name space NTL
     45NTL_CLIENT
     46#endif
     47
     48#endif
    2649
    2750//#include "polys.h"
     
    19711994#endif
    19721995
     1996#ifdef HAVE_NTL
     1997matrix singntl_rref(matrix  m, const ring R)
     1998{
     1999  int r=m->rows();
     2000  int c=m->cols();
     2001  int i,j;
     2002  matrix M=mpNew(r,c);
     2003  if (rField_is_Zp(R))
     2004  {
     2005    zz_p::init(rChar(R));
     2006    mat_zz_p *NTLM=new mat_zz_p;
     2007    NTLM->SetDims(r,c);
     2008    for(i=r;i>0;i--)
     2009    {
     2010      for(j=c;j>0;j--)
     2011      {
     2012        poly h=MATELEM(m,i,j);
     2013        if ((h!=NULL)
     2014        && (p_Totaldegree(h,R)==0))
     2015        {
     2016          (*NTLM)(i,j)=(long)p_GetCoeff(h,R);
     2017        }
     2018        else
     2019        {
     2020          WerrorS("smatrix for rref is not constant");
     2021          return M;
     2022        }
     2023      }
     2024    }
     2025    gauss(*NTLM);
     2026    for(i=r;i>0;i--)
     2027    {
     2028      for(j=c;j>0;j--)
     2029      {
     2030        number n=n_Init(rep((*NTLM)(i,j)),R->cf);
     2031        if(!n_IsZero(n,R->cf))
     2032        {
     2033          poly p=p_NSet(n,R);
     2034          p_SetComp(p,i,R);
     2035          M->m[j]=p_Add_q(M->m[j],p,R);
     2036        }
     2037      }
     2038    }
     2039    delete NTLM;
     2040  }
     2041  else
     2042  {
     2043    WerrorS("not implemented for these coefficients");
     2044  }
     2045  return M;
     2046}
     2047#endif
     2048
     2049#ifdef HAVE_NTL
     2050ideal singntl_rref(ideal  m, const ring R) /*assume smatrix m*/
     2051{
     2052  int r=m->rank;
     2053  int c=m->ncols;
     2054  int i,j;
     2055  ideal M=idInit(c,r);
     2056  if (rField_is_Zp(R))
     2057  {
     2058    zz_p::init(rChar(R));
     2059    mat_zz_p *NTLM=new mat_zz_p;
     2060    NTLM->SetDims(r,c);
     2061    for(j=c;j>0;j--)
     2062    {
     2063      poly h=m->m[j];
     2064      while(h!=NULL)
     2065      {
     2066        i=p_GetComp(h,R);
     2067        if (p_Totaldegree(h,R)==0)
     2068          (*NTLM)(i,j)=(long)p_GetCoeff(h,R);
     2069        else
     2070        {
     2071          WerrorS("smatrix for rref is not constant");
     2072          return M;
     2073        }
     2074        pIter(h);
     2075      }
     2076    }
     2077    gauss(*NTLM);
     2078    for(i=r;i>0;i--)
     2079    {
     2080      for(j=c;j>0;j--)
     2081      {
     2082        number n=n_Init(rep((*NTLM)(i,j)),R->cf);
     2083        if(!n_IsZero(n,R->cf))
     2084        {
     2085          poly p=p_NSet(n,R);
     2086          p_SetComp(p,i,R);
     2087          M->m[j]=p_Add_q(M->m[j],p,R);
     2088        }
     2089      }
     2090    }
     2091    delete NTLM;
     2092  }
     2093  else
     2094  {
     2095    WerrorS("not implemented for these coefficients");
     2096  }
     2097  return M;
     2098}
     2099#endif
     2100
    19732101#if defined(HAVE_NTL) || defined(HAVE_FLINT)
    19742102ideal singclap_absFactorize ( poly f, ideal & mipos, intvec ** exps, int & numFactors, const ring r)
  • libpolys/polys/clapsing.h

    r844f30 re68029  
    4444intvec* singntl_LLL(intvec* A);
    4545
     46#ifdef HAVE_NTL
     47ideal  singntl_rref(ideal  m, const ring R) /*assume smatrix m*/;
     48matrix singntl_rref(matrix  m, const ring R);
     49#endif
     50
    4651ideal singclap_absFactorize ( poly f, ideal & mipos, intvec ** exps, int & n, const ring r);
    4752
  • 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{
  • libpolys/polys/flintconv.h

    r844f30 re68029  
    6767
    6868matrix singflint_rref(matrix  m, const ring R);
     69ideal  singflint_rref(ideal  m, const ring R);
    6970#if __FLINT_RELEASE >= 20500
    7071void convSingPFlintnmod_poly_t(nmod_poly_t result, const poly p, const ring r);
Note: See TracChangeset for help on using the changeset viewer.