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