My Project  debian-1:4.1.1-p2+ds-4build3
int64vec.cc
Go to the documentation of this file.
1 /*****************************************
2 * Computer Algebra System SINGULAR *
3 *****************************************/
4 /*
5 * ABSTRACT: class int64vec: lists/vectors of int64
6 */
7 
8 
9 #include "misc/auxiliary.h"
10 
11 
12 
13 #include "misc/int64vec.h"
14 #include "misc/intvec.h"
15 #include "omalloc/omalloc.h"
16 
17 /*0 implementation*/
18 
19 
21 {
22  row = iv->rows();
23  col = iv->cols();
24  v = (int64 *)omAlloc(sizeof(int64)*row*col);
25  for (int i=0; i<row*col; i++)
26  {
27  v[i] = (*iv)[i];
28  }
29 }
30 
32 {
33  row = iv->rows();
34  col = iv->cols();
35  v = (int64 *)omAlloc(sizeof(int64)*row*col);
36  for (int i=0; i<row*col; i++)
37  {
38  v[i] = (int64)((*iv)[i]);
39  }
40 }
41 
42 int64vec::int64vec(int r, int c, int64 init)
43 {
44  row = r;
45  col = c;
46  int l = r*c;
47  if ((r>0) && (c>0))
48  v = (int64 *)omAlloc(sizeof(int64)*l);
49  else
50  v = NULL;
51  for (int i=0; i<l; i++)
52  {
53  v[i] = init;
54  }
55 }
56 
57 char * int64vec::iv64String(int not_mat, int /*mat*/, int spaces, int dim)
58 {
59  StringSetS("");
60  if ((col == 1)&&(not_mat))
61  {
62  int i=0;
63  for (; i<row-1; i++)
64  {
65  StringAppend("%lld,",v[i]);
66  }
67  if (i<row)
68  {
69  StringAppend("%lld",v[i]);
70  }
71  }
72  else
73  {
74  for (int j=0; j<row; j++)
75  {
76  if (j<row-1)
77  {
78  for (int i=0; i<col; i++)
79  {
80  StringAppend("%lld%c",v[j*col+i],',');
81  }
82  }
83  else
84  {
85  for (int i=0; i<col; i++)
86  {
87  StringAppend("%lld%c",v[j*col+i],i<col-1 ? ',' : ' ');
88  }
89  }
90  if (j+1<row)
91  {
92  if (dim > 1) StringAppendS("\n");
93  if (spaces>0) StringAppend("%-*.*s",spaces,spaces," ");
94  }
95  }
96  }
97  return StringEndS();
98 }
99 
101 {
102  return iv64String(0, 0, dim);
103 }
104 
105 void int64vec::show(int notmat,int spaces)
106 {
107  char *s=iv64String(notmat,spaces);
108  if (spaces>0)
109  {
110  PrintNSpaces(spaces);
111  PrintS(s);
112  }
113  else
114  {
115  PrintS(s);
116  }
117  omFree(s);
118 }
119 
121 {
122  for (int i=row*col-1; i>=0; i--) { v[i] *= intop; }
123 }
124 
126 {
127  if (intop == 0) return;
128  int64 bb=ABS(intop);
129  for (int i=row*col-1; i>=0; i--)
130  {
131  int64 r=v[i];
132  int64 c=r%bb;
133  if (c<0) c+=bb;
134  r=(r-c)/intop;
135  v[i]=r;
136  }
137 }
138 
139 int int64vec::compare(const int64vec* op) const
140 {
141  if ((col!=1) ||(op->cols()!=1))
142  {
143  if((col!=op->cols())
144  || (row!=op->rows()))
145  return -2;
146  }
147  int i;
148  for (i=0; i<si_min(length(),op->length()); i++)
149  {
150  if (v[i] > (*op)[i])
151  return 1;
152  if (v[i] < (*op)[i])
153  return -1;
154  }
155  // this can only happen for int64vec: (i.e. col==1)
156  for (; i<row; i++)
157  {
158  if (v[i] > 0)
159  return 1;
160  if (v[i] < 0)
161  return -1;
162  }
163  for (; i<op->rows(); i++)
164  {
165  if (0 > (*op)[i])
166  return 1;
167  if (0 < (*op)[i])
168  return -1;
169  }
170  return 0;
171 }
172 
174 {
175  int64vec * iv;
176  int64 mn, ma, i;
177  if (a->cols() != b->cols()) return NULL;
178  mn = si_min(a->rows(),b->rows());
179  ma = si_max(a->rows(),b->rows());
180  if (a->cols() == 1)
181  {
182  iv = new int64vec(ma);
183  for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] + (*b)[i];
184  if (ma > mn)
185  {
186  if (ma == a->rows())
187  {
188  for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
189  }
190  else
191  {
192  for(i=mn; i<ma; i++) (*iv)[i] = (*b)[i];
193  }
194  }
195  return iv;
196  }
197  if (mn != ma) return NULL;
198  iv = new int64vec(a);
199  for (i=0; i<mn*a->cols(); i++) { (*iv)[i] += (*b)[i]; }
200  return iv;
201 }
202 
204 {
205  int64vec * iv;
206  int mn, ma,i;
207  if (a->cols() != b->cols()) return NULL;
208  mn = si_min(a->rows(),b->rows());
209  ma = si_max(a->rows(),b->rows());
210  if (a->cols() == 1)
211  {
212  iv = new int64vec(ma);
213  for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] - (*b)[i];
214  if (ma > mn)
215  {
216  if (ma == a->rows())
217  {
218  for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
219  }
220  else
221  {
222  for(i=mn; i<ma; i++) (*iv)[i] = -(*b)[i];
223  }
224  }
225  return iv;
226  }
227  if (mn != ma) return NULL;
228  iv = new int64vec(a);
229  for (i=0; i<mn*a->cols(); i++) { (*iv)[i] -= (*b)[i]; }
230  return iv;
231 }
232 
233 
234 /*
235  * The following two functions are never used.
236  * Remove?
237 
238 // def. internals
239 static int64 iv64Gcd(int, int);
240 static int64 iv64L1Norm(intvec *);
241 
242 
243 // The following two functions seem to be never used. Remove?
244 static int64 iv64Gcd(int64 a,int64 b)
245 {
246  int64 x;
247 
248  if (a<0) a=-a;
249  if (b<0) b=-b;
250  if (b>a)
251  {
252  x=b;
253  b=a;
254  a=x;
255  }
256  while (b!=0)
257  {
258  x = a % b;
259  a = b;
260  b = x;
261  }
262  return a;
263 }
264 
265 static int64 iv64L1Norm(int64vec *w)
266 {
267  int i;
268  int64 j, s = 0;
269 
270  for (i=w->rows()-1;i>=0;i--)
271  {
272  j = (*w)[i];
273  if (j>0)
274  s += j;
275  else
276  s -= j;
277  }
278  return s;
279 }
280 */
dim
int dim(ideal I, ring r)
Definition: tropicalStrategy.cc:23
si_min
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
omalloc.h
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:107
j
int j
Definition: facHensel.cc:105
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
int64vec::col
int col
Definition: int64vec.h:27
auxiliary.h
int64vec::row
int row
Definition: int64vec.h:26
StringEndS
char * StringEndS()
Definition: reporter.cc:151
ABS
static int ABS(int v)
Definition: auxiliary.h:110
b
CanonicalForm b
Definition: cfModGcd.cc:4044
int64vec::rows
int rows() const
Definition: int64vec.h:65
i
int i
Definition: cfEzgcd.cc:125
int64vec
Definition: int64vec.h:21
int64vec::operator/=
void operator/=(int64 intop)
Definition: int64vec.cc:125
PrintS
void PrintS(const char *s)
Definition: reporter.cc:284
intvec
Definition: intvec.h:21
int64vec::length
int length() const
Definition: int64vec.h:63
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
int64vec::iv64String
char * iv64String(int not_mat=1, int mat=0, int spaces=0, int dim=2)
Definition: int64vec.cc:57
intvec.h
int64vec::String
char * String(int dim=2)
Definition: int64vec.cc:100
iv64Add
int64vec * iv64Add(int64vec *a, int64vec *b)
Definition: int64vec.cc:173
int64vec::show
void show(int mat=0, int spaces=0)
Definition: int64vec.cc:105
int64vec::v
int64 * v
Definition: int64vec.h:25
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:128
si_max
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
intvec::cols
int cols() const
Definition: intvec.h:95
int64
long int64
Definition: auxiliary.h:66
int64vec::int64vec
int64vec(int l=1)
Definition: int64vec.h:30
int64vec::cols
int cols() const
Definition: int64vec.h:64
iv64Sub
int64vec * iv64Sub(int64vec *a, int64vec *b)
Definition: int64vec.cc:203
NULL
#define NULL
Definition: omList.c:10
l
int l
Definition: cfEzgcd.cc:93
int64vec::operator*=
void operator*=(int64 intop)
Definition: int64vec.cc:120
intvec::rows
int rows() const
Definition: intvec.h:96
StringAppend
#define StringAppend
Definition: emacs.cc:79
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
int64vec::compare
int compare(const int64vec *o) const
Definition: int64vec.cc:139
PrintNSpaces
void PrintNSpaces(const int n)
Definition: reporter.cc:364
int64vec.h