-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQpolynomial.hpp
476 lines (410 loc) · 13.9 KB
/
Qpolynomial.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#ifndef ISL_CXX_Qpolynomial_IMPL_H
#define ISL_CXX_Qpolynomial_IMPL_H
#include "isl/Qpolynomial.h"
#include "isl/Aff.hpp"
#include "isl/BasicSet.hpp"
#include "isl/Constraint.hpp"
#include "isl/Point.hpp"
#include "isl/Set.hpp"
#include "isl/Space.hpp"
#include "isl/Term.hpp"
#include "isl/Val.hpp"
#include "isl/Bool.h"
#include "isl/DimType.h"
#include "isl/Format.h"
#include "isl/IslBase.h"
#include "isl/IslException.h"
#include "isl/Stat.h"
#include "isl/polynomial.h"
#include "isl/set.h"
#include <string>
#include <cassert>
namespace isl {
inline isl_qpolynomial *Qpolynomial::GetCopy() const {
return isl_qpolynomial_copy((isl_qpolynomial *)This);
}
inline Qpolynomial &Qpolynomial::operator=(const Qpolynomial &Other) {
isl_qpolynomial *New = Other.GetCopy();
ctx = Other.Context();
isl_qpolynomial_free((isl_qpolynomial *)This);
This = New;
return *this;
}
inline Qpolynomial Qpolynomial::zeroOnDomain(const Space &dim) {
const Ctx &_ctx = dim.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_zero_on_domain((dim).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_zero_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::oneOnDomain(const Space &dim) {
const Ctx &_ctx = dim.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_one_on_domain((dim).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_one_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::inftyOnDomain(const Space &dim) {
const Ctx &_ctx = dim.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_infty_on_domain((dim).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_infty_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::neginftyOnDomain(const Space &dim) {
const Ctx &_ctx = dim.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_neginfty_on_domain((dim).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_neginfty_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::nanOnDomain(const Space &dim) {
const Ctx &_ctx = dim.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_nan_on_domain((dim).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_nan_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::valOnDomain(const Space &space, const Val &val) {
const Ctx &_ctx = val.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_val_on_domain((space).GetCopy(), (val).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_val_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::varOnDomain(const Space &dim, DimType type, unsigned int pos) {
const Ctx &_ctx = dim.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_var_on_domain((dim).GetCopy(), (enum isl_dim_type)type, pos);
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_var_on_domain returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::fromConstraint(const Constraint &c, DimType type, unsigned int pos) {
const Ctx &_ctx = c.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_from_constraint((c).GetCopy(), (enum isl_dim_type)type, pos);
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_from_constraint returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::fromTerm(const Term &term) {
const Ctx &_ctx = term.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_from_term((term).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_from_term returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial Qpolynomial::fromAff(const Aff &aff) {
const Ctx &_ctx = aff.Context();
_ctx.lock();
isl_qpolynomial *That = isl_qpolynomial_from_aff((aff).GetCopy());
_ctx.unlock();
if (_ctx.hasError()) {
handleError("isl_qpolynomial_from_aff returned a NULL pointer.");
}
return Qpolynomial(_ctx, That);
}
inline Qpolynomial::~Qpolynomial() {
isl_qpolynomial_free((isl_qpolynomial *)This);
This = nullptr;
}
/// rief Release ownership of the wrapped object.
///
/// You are on your own now buddy.
/// The wrapper cannot be used anymore after calling Give()
///
///@return the wrapped isl object.
inline isl_qpolynomial *Qpolynomial::Give() {
isl_qpolynomial *res = (isl_qpolynomial *)This;
This = nullptr;
return res;
}
/// \brief Unwrap the stored isl object.
/// \returns A the wrapped isl object.
inline isl_qpolynomial *Qpolynomial::Get() const { return (isl_qpolynomial *)This;
}
inline Qpolynomial Qpolynomial::add(const Qpolynomial &qp2) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_add((*this).GetCopy(), (qp2).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_add returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::addDims(DimType type, unsigned int n) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_add_dims((*this).GetCopy(), (enum isl_dim_type)type, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_add_dims returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::alignParams(const Space &model) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_align_params((*this).GetCopy(), (model).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_align_params returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline int Qpolynomial::asPolynomialOnDomain(const BasicSet &bset, const std::function<int(isl_basic_set *, isl_qpolynomial *, void *)> && fn, void * user) const {
ctx.lock();
int res = isl_qpolynomial_as_polynomial_on_domain((*this).Get(), (bset).Get(), get_fn_ptr<11>(fn), user);
ctx.unlock();
return res;
}
inline unsigned int Qpolynomial::dim(DimType type) const {
ctx.lock();
unsigned int res = isl_qpolynomial_dim((*this).Get(), (enum isl_dim_type)type);
ctx.unlock();
return res;
}
inline Qpolynomial Qpolynomial::dropDims(DimType type, unsigned int first, unsigned int n) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_drop_dims((*this).GetCopy(), (enum isl_dim_type)type, first, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_drop_dims returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Val Qpolynomial::eval(const Point &pnt) const {
ctx.lock();
isl_val * res = isl_qpolynomial_eval((*this).GetCopy(), (pnt).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_eval returned a NULL pointer.");
}
return Val(ctx, res);
}
inline Stat Qpolynomial::foreachTerm(const std::function<isl_stat(isl_term *, void *)> && fn, void * user) const {
ctx.lock();
isl_stat res = isl_qpolynomial_foreach_term((*this).Get(), get_fn_ptr<12>(fn), user);
ctx.unlock();
return (Stat)res;
}
inline Val Qpolynomial::getConstantVal() const {
ctx.lock();
isl_val * res = isl_qpolynomial_get_constant_val((*this).Get());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_get_constant_val returned a NULL pointer.");
}
return Val(ctx, res);
}
inline Space Qpolynomial::getDomainSpace() const {
ctx.lock();
isl_space * res = isl_qpolynomial_get_domain_space((*this).Get());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_get_domain_space returned a NULL pointer.");
}
return Space(ctx, res);
}
inline Space Qpolynomial::getSpace() const {
ctx.lock();
isl_space * res = isl_qpolynomial_get_space((*this).Get());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_get_space returned a NULL pointer.");
}
return Space(ctx, res);
}
inline Qpolynomial Qpolynomial::gist(const Set &context) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_gist((*this).GetCopy(), (context).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_gist returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::gistParams(const Set &context) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_gist_params((*this).GetCopy(), (context).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_gist_params returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::homogenize() const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_homogenize((*this).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_homogenize returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::insertDims(DimType type, unsigned int first, unsigned int n) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_insert_dims((*this).GetCopy(), (enum isl_dim_type)type, first, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_insert_dims returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Bool Qpolynomial::involvesDims(DimType type, unsigned int first, unsigned int n) const {
ctx.lock();
isl_bool res = isl_qpolynomial_involves_dims((*this).Get(), (enum isl_dim_type)type, first, n);
ctx.unlock();
return (Bool)res;
}
inline Bool Qpolynomial::isInfty() const {
ctx.lock();
isl_bool res = isl_qpolynomial_is_infty((*this).Get());
ctx.unlock();
return (Bool)res;
}
inline Bool Qpolynomial::isNan() const {
ctx.lock();
isl_bool res = isl_qpolynomial_is_nan((*this).Get());
ctx.unlock();
return (Bool)res;
}
inline Bool Qpolynomial::isNeginfty() const {
ctx.lock();
isl_bool res = isl_qpolynomial_is_neginfty((*this).Get());
ctx.unlock();
return (Bool)res;
}
inline Bool Qpolynomial::isZero() const {
ctx.lock();
isl_bool res = isl_qpolynomial_is_zero((*this).Get());
ctx.unlock();
return (Bool)res;
}
inline Qpolynomial Qpolynomial::moveDims(DimType dst_type, unsigned int dst_pos, DimType src_type, unsigned int src_pos, unsigned int n) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_move_dims((*this).GetCopy(), (enum isl_dim_type)dst_type, dst_pos, (enum isl_dim_type)src_type, src_pos, n);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_move_dims returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::mul(const Qpolynomial &qp2) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_mul((*this).GetCopy(), (qp2).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_mul returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::neg() const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_neg((*this).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_neg returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Bool Qpolynomial::plainIsEqual(const Qpolynomial &qp2) const {
ctx.lock();
isl_bool res = isl_qpolynomial_plain_is_equal((*this).Get(), (qp2).Get());
ctx.unlock();
return (Bool)res;
}
inline Qpolynomial Qpolynomial::pow(unsigned int power) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_pow((*this).GetCopy(), power);
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_pow returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::projectDomainOnParams() const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_project_domain_on_params((*this).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_project_domain_on_params returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::scaleVal(const Val &v) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_scale_val((*this).GetCopy(), (v).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_scale_val returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::setDimName(DimType type, unsigned int pos, std::string s) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_set_dim_name((*this).GetCopy(), (enum isl_dim_type)type, pos, s.c_str());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_set_dim_name returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline int Qpolynomial::sgn() const {
ctx.lock();
int res = isl_qpolynomial_sgn((*this).Get());
ctx.unlock();
return res;
}
inline Qpolynomial Qpolynomial::sub(const Qpolynomial &qp2) const {
ctx.lock();
isl_qpolynomial * res = isl_qpolynomial_sub((*this).GetCopy(), (qp2).GetCopy());
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_sub returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
inline Qpolynomial Qpolynomial::substitute(DimType type, unsigned int first, unsigned int n, std::unique_ptr<Qpolynomial> * subs) const {
ctx.lock();
isl_qpolynomial * _subs = nullptr;
isl_qpolynomial * res = isl_qpolynomial_substitute((*this).GetCopy(), (enum isl_dim_type)type, first, n, (subs) ? &_subs : nullptr);
if(subs) {
if (ctx.hasError()) {
handleError("subs became a NULL pointer.");
}
Qpolynomial _tmp_subs = Qpolynomial(ctx, _subs);
subs->reset(new Qpolynomial(_tmp_subs));
}
ctx.unlock();
if (ctx.hasError()) {
handleError("isl_qpolynomial_substitute returned a NULL pointer.");
}
return Qpolynomial(ctx, res);
}
} // namespace isl
#endif //ISL_CXX_Qpolynomial_IMPL_H