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