barvinok_ehrhart_options.h: fix name of isl_args structure in declaration
[barvinok.git] / genfun_constructor.cc
blobfc429a1c8077594a5044e114ac3d3917a1241b9b
1 #include "genfun_constructor.h"
3 gf_base *gf_base::create(Polyhedron *context, unsigned dim, unsigned nparam,
4 barvinok_options *options)
6 gf_base *red;
7 if (options->incremental_specialization == 2)
8 red = new partial_bfcounter(context, dim, nparam);
9 else if (options->incremental_specialization == 1)
10 red = new partial_ireducer(context, dim, nparam);
11 else
12 red = new partial_reducer(context, dim, nparam);
13 return red;
16 void partial_ireducer::base(const QQ& c, const vec_ZZ& num, const mat_ZZ& den_f)
18 gf->add(c, num, den_f);
21 void partial_reducer::split(const mat_ZZ& num, vec_ZZ& num_s, mat_ZZ& num_p,
22 const mat_ZZ& den_f, vec_ZZ& den_s, mat_ZZ& den_r)
24 unsigned len = den_f.NumRows(); // number of factors in den
25 unsigned nvar = tmp.length();
27 den_s.SetLength(len);
28 den_r.SetDims(len, lower);
30 for (int r = 0; r < len; ++r) {
31 bool all_zero;
33 for (int k = 0; k < nvar; ++k)
34 tmp[k] = den_f[r][k];
35 den_s[r] = tmp * lambda;
36 all_zero = den_s[r] == 0;
38 for (int k = nvar; k < dim; ++k) {
39 den_r[r][k-nvar] = den_f[r][k];
40 if (all_zero)
41 all_zero = den_r[r][k-nvar] == 0;
43 if (all_zero)
44 throw Orthogonal;
47 num_s.SetLength(num.NumRows());
48 num_p.SetDims(num.NumRows(), lower);
49 for (int i = 0; i < num.NumRows(); ++i) {
50 for (int k = 0; k < nvar; ++k)
51 tmp[k] = num[i][k];
52 num_s[i] = tmp * lambda;
53 for (int k = nvar ; k < dim; ++k)
54 num_p[i][k-nvar] = num[i][k];
58 void partial_reducer::base(const QQ& c, const vec_ZZ& num, const mat_ZZ& den_f)
60 gf->add(c, num, den_f);
63 void partial_reducer::base(const vec_QQ& c, const mat_ZZ& num, const mat_ZZ& den_f)
65 gf->add(new short_rat(c, num, den_f));
68 void partial_bfcounter::base(mat_ZZ& factors, bfc_vec& v)
70 mat_ZZ den;
71 unsigned nf = factors.NumRows();
73 for (int i = 0; i < v.size(); ++i) {
74 bfc_term* bfct = static_cast<bfc_term *>(v[i]);
75 den.SetDims(0, lower);
76 int total_power = 0;
77 int p = 0;
78 for (int j = 0; j < nf; ++j) {
79 total_power += v[i]->powers[j];
80 den.SetDims(total_power, lower);
81 for (int k = 0; k < v[i]->powers[j]; ++k)
82 den[p++] = factors[j];
84 for (int j = 0; j < v[i]->terms.NumRows(); ++j)
85 gf->add(bfct->c[j], v[i]->terms[j], den);
86 delete v[i];