My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
libpolys
misc
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
19
int64vec::int64vec
(
int64vec
* iv)
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
30
int64vec::int64vec
(
intvec
* iv)
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
41
int64vec::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
56
char
*
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
99
char
*
int64vec::String
(
int
dim
)
100
{
101
return
iv64String
(0, 0,
dim
);
102
}
103
104
void
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
119
void
int64vec::operator*=
(
int64
intop)
120
{
121
for
(
int
i
=
row
*
col
-1;
i
>=0;
i
--) {
v
[
i
] *= intop; }
122
}
123
124
void
int64vec::operator/=
(
int64
intop)
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
138
int
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
172
int64vec
*
iv64Add
(
int64vec
* a,
int64vec
*
b
)
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
202
int64vec
*
iv64Sub
(
int64vec
* a,
int64vec
*
b
)
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
238
static int64 iv64Gcd(int, int);
239
static int64 iv64L1Norm(intvec *);
240
241
242
// The following two functions seem to be never used. Remove?
243
static 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
264
static 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
*/
auxiliary.h
All the auxiliary stuff.
ABS
static int ABS(int v)
Definition
auxiliary.h:113
int64
long int64
Definition
auxiliary.h:68
si_max
static int si_max(const int a, const int b)
Definition
auxiliary.h:125
si_min
static int si_min(const int a, const int b)
Definition
auxiliary.h:126
l
int l
Definition
cfEzgcd.cc:100
i
int i
Definition
cfEzgcd.cc:132
b
CanonicalForm b
Definition
cfModGcd.cc:4111
int64vec
Definition
int64vec.h:24
int64vec::col
int col
Definition
int64vec.h:28
int64vec::show
void show(int mat=0, int spaces=0)
Definition
int64vec.cc:104
int64vec::compare
int compare(const int64vec *o) const
Definition
int64vec.cc:138
int64vec::length
int length() const
Definition
int64vec.h:64
int64vec::int64vec
int64vec(int l=1)
Definition
int64vec.h:31
int64vec::v
int64 * v
Definition
int64vec.h:26
int64vec::String
char * String(int dim=2)
Definition
int64vec.cc:99
int64vec::row
int row
Definition
int64vec.h:27
int64vec::iv64String
char * iv64String(int not_mat=1, int mat=0, int spaces=0, int dim=2)
Definition
int64vec.cc:56
int64vec::operator*=
void operator*=(int64 intop)
Definition
int64vec.cc:119
int64vec::rows
int rows() const
Definition
int64vec.h:66
int64vec::cols
int cols() const
Definition
int64vec.h:65
int64vec::operator/=
void operator/=(int64 intop)
Definition
int64vec.cc:124
intvec
Definition
intvec.h:24
intvec::cols
int cols() const
Definition
intvec.h:96
intvec::rows
int rows() const
Definition
intvec.h:97
StringAppend
#define StringAppend
Definition
emacs.cc:79
s
const CanonicalForm int s
Definition
facAbsFact.cc:51
j
int j
Definition
facHensel.cc:110
iv64Add
int64vec * iv64Add(int64vec *a, int64vec *b)
Definition
int64vec.cc:172
iv64Sub
int64vec * iv64Sub(int64vec *a, int64vec *b)
Definition
int64vec.cc:202
int64vec.h
intvec.h
omAlloc
#define omAlloc(size)
Definition
omAllocDecl.h:210
omFree
#define omFree(addr)
Definition
omAllocDecl.h:261
NULL
#define NULL
Definition
omList.c:12
StringSetS
void StringSetS(const char *st)
Definition
reporter.cc:128
StringAppendS
void StringAppendS(const char *st)
Definition
reporter.cc:107
PrintNSpaces
void PrintNSpaces(const int n)
Definition
reporter.cc:368
PrintS
void PrintS(const char *s)
Definition
reporter.cc:288
StringEndS
char * StringEndS()
Definition
reporter.cc:151
dim
int dim(ideal I, ring r)
Definition
tropicalStrategy.cc:23
Generated on
for My Project by
doxygen 1.17.0
for
Singular