callgfanlib_conversion.cc
Go to the documentation of this file.
1 #include <gfanlib/gfanlib.h>
2 
3 #include <coeffs/bigintmat.h>
4 #include <coeffs/longrat.h>
5 #include <coeffs/numbers.h>
6 
7 #include <Singular/ipid.h> // for coeffs_BIGINT
8 
9 number integerToNumber(const gfan::Integer &I)
10 {
11  mpz_t i;
12  mpz_init(i);
13  I.setGmp(i);
14  long m = 268435456;
15  if(mpz_cmp_si(i,m))
16  {
17  int temp = (int) mpz_get_si(i);
18  return n_Init(temp,coeffs_BIGINT);
19  }
20  else
21  return n_InitMPZ(i,coeffs_BIGINT);
22 }
23 
24 bigintmat* zVectorToBigintmat(const gfan::ZVector &zv)
25 {
26  int d=zv.size();
27  bigintmat* bim = new bigintmat(1,d,coeffs_BIGINT);
28  for(int i=1;i<=d;i++)
29  {
30  number temp = integerToNumber(zv[i-1]);
31  bim->set(1,i,temp);
32  n_Delete(&temp,coeffs_BIGINT);
33  }
34  return bim;
35 }
36 
37 bigintmat* zMatrixToBigintmat(const gfan::ZMatrix &zm)
38 {
39  int d=zm.getHeight();
40  int n=zm.getWidth();
41  bigintmat* bim = new bigintmat(d,n,coeffs_BIGINT);
42  for(int i=1;i<=d;i++)
43  for(int j=1; j<=n; j++)
44  {
45  number temp = integerToNumber(zm[i-1][j-1]);
46  bim->set(i,j,temp);
47  n_Delete(&temp,coeffs_BIGINT);
48  }
49  return bim;
50 }
51 
52 gfan::Integer* numberToInteger(const number &n)
53 {
54  if (SR_HDL(n) & SR_INT)
55  return new gfan::Integer(SR_TO_INT(n));
56  else
57  return new gfan::Integer(n->z);
58 }
59 
60 gfan::ZMatrix* bigintmatToZMatrix(const bigintmat &bim)
61 {
62  int d=bim.rows();
63  int n=bim.cols();
64  gfan::ZMatrix* zm = new gfan::ZMatrix(d,n);
65  for(int i=0;i<d;i++)
66  for(int j=0;j<n;j++)
67  {
68  number temp = BIMATELEM(bim, i+1, j+1);
69  gfan::Integer* gi = numberToInteger(temp);
70  (*zm)[i][j] = *gi;
71  delete gi;
72  }
73  return zm;
74 }
75 
76 gfan::ZVector* bigintmatToZVector(const bigintmat &bim)
77 {
78  gfan::ZVector* zv=new gfan::ZVector(bim.cols());
79  for(int j=0; j<bim.cols(); j++)
80  {
81  number temp = BIMATELEM(bim, 1, j+1);
82  gfan::Integer* gi = numberToInteger(temp);
83  (*zv)[j] = *gi;
84  n_Delete(&temp,coeffs_BIGINT);
85  delete gi;
86  }
87  return zv;
88 }
89 
90 gfan::ZVector intStar2ZVector(const int d, const int* i)
91 {
92  gfan::ZVector zv(d);
93  for(int j=0; j<d; j++)
94  zv[j]=i[j+1];
95  return zv;
96 }
97 
98 gfan::ZVector expvToZVector(const int n, const int* expv)
99 {
100  gfan::ZVector zv(n);
101  for(int i=0; i<n; i++)
102  zv[i]=gfan::Integer(expv[i+1]);
103  return zv;
104 }
105 
106 gfan::ZVector wvhdlEntryToZVector(const int n, const int* wvhdl0)
107 {
108  gfan::ZVector zv(n);
109  for(int j=0; j<n; j++)
110  zv[j]=wvhdl0[j];
111  return zv;
112 }
113 
114 int* ZVectorToIntStar(const gfan::ZVector &v, bool &overflow)
115 {
116  int* w = (int*) omAlloc(v.size()*sizeof(int));
117  for (unsigned i=0; i<v.size(); i++)
118  {
119  if (!v[i].fitsInInt())
120  {
121  omFree(w);
122  WerrorS("intoverflow converting gfan:ZVector to int*");
123  overflow = true;
124  return NULL;
125  }
126  w[i]=v[i].toInt();
127  }
128  return w;
129 }
130 
131 char* toString(gfan::ZMatrix const &zm)
132 {
133  bigintmat* bim = zMatrixToBigintmat(zm);
134  char* s = bim->StringAsPrinted();
135  if (s==NULL)
136  s = (char*) omAlloc0(sizeof(char));
137  delete bim;
138  return s;
139 }
140 
141 gfan::ZFan* toFanStar(std::set<gfan::ZCone> setOfCones)
142 {
143  if (setOfCones.size() > 0)
144  {
145  std::set<gfan::ZCone>::iterator cone = setOfCones.begin();
146  gfan::ZFan* zf = new gfan::ZFan(cone->ambientDimension());
147  for (std::set<gfan::ZCone>::iterator cone = setOfCones.begin(); cone!=setOfCones.end(); cone++)
148  zf->insert(*cone);
149  return zf;
150  }
151  else
152  return new gfan::ZFan(gfan::ZFan::fullFan(currRing->N));
153 }
154 
155 std::set<gfan::ZVector> rays(std::set<gfan::ZCone> setOfCones)
156 {
157  std::set<gfan::ZVector> setOfRays;
158  for (std::set<gfan::ZCone>::iterator cone = setOfCones.begin(); cone!=setOfCones.end(); cone++)
159  {
160  gfan::ZMatrix raysOfCone = cone->extremeRays();
161  for (int i=0; i<raysOfCone.getHeight(); i++)
162  setOfRays.insert(raysOfCone[i]);
163  }
164  return setOfRays;
165 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
std::set< gfan::ZVector > rays(std::set< gfan::ZCone > setOfCones)
char * toString(gfan::ZMatrix const &zm)
Matrices of numbers.
Definition: bigintmat.h:51
int rows() const
Definition: bigintmat.h:146
gfan::ZFan * toFanStar(std::set< gfan::ZCone > setOfCones)
BOOLEAN fullFan(leftv res, leftv args)
Definition: bbfan.cc:229
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
bigintmat * zMatrixToBigintmat(const gfan::ZMatrix &zm)
gfan::ZVector wvhdlEntryToZVector(const int n, const int *wvhdl0)
char * StringAsPrinted()
Returns a string as it would have been printed in the interpreter.
Definition: bigintmat.cc:452
int * ZVectorToIntStar(const gfan::ZVector &v, bool &overflow)
void WerrorS(const char *s)
Definition: feFopen.cc:24
bigintmat * zVectorToBigintmat(const gfan::ZVector &zv)
coeffs coeffs_BIGINT
Definition: ipid.cc:54
#define omAlloc(size)
Definition: omAllocDecl.h:210
void set(int i, int j, number n, const coeffs C=NULL)
replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
Definition: bigintmat.cc:96
gfan::Integer * numberToInteger(const number &n)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
int j
Definition: myNF.cc:70
#define omFree(addr)
Definition: omAllocDecl.h:261
gfan::ZMatrix * bigintmatToZMatrix(const bigintmat &bim)
gfan::ZVector intStar2ZVector(const int d, const int *i)
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
Definition: coeffs.h:546
int cols() const
Definition: bigintmat.h:145
int m
Definition: cfEzgcd.cc:119
number integerToNumber(const gfan::Integer &I)
int i
Definition: cfEzgcd.cc:123
gfan::ZVector expvToZVector(const int n, const int *expv)
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:134
#define SR_TO_INT(SR)
Definition: longrat.h:70
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:68
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define SR_HDL(A)
Definition: tgb.cc:35
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:459
gfan::ZVector * bigintmatToZVector(const bigintmat &bim)
#define omAlloc0(size)
Definition: omAllocDecl.h:211