Developer documentation

tensor_bernstein_fcts.hpp
Go to the documentation of this file.
1 #ifndef realroot_MPOLDSE_BERNSTEIN_C
2 #define realroot_MPOLDSE_BERNSTEIN_C
3 //====================================================================
4 namespace mmx {
5 
6 namespace tensor
7 {
8  template< class C > inline void
9  binoms( bernstein<C>& mpl ) {
10  binoms( mpl.begin(), mpl.env, binomials<C>::default_ ) ;
11  }
12 
13  template < class C > inline void
15  {
17  };
18 
19  template < class C > inline void
21  {
23  };
24 
25  template < class C > inline void
26  convertb2m ( monomials<C> & mpl ) {
28  }
29 
30  template < class C > inline void
33  };
34 
35  template < class C , class V> inline void
36  convertm2b (bernstein < C > &mpl, const V& bx) {
37  convertm2b (mpl);
38  for(unsigned i=0;i<bx.size();i+=2)
39  restrict(mpl,i/2,bx[i],bx[i+1]);
40  };
41 
42  template < class C > void
43  elevate (bernstein < C > &r, const eenv & elev)
44  {
45  bernstein < C > tmp (elev);
46  tensor::binoms (tmp);
47  scale (r);
48  tensor::conv(r, tmp);
49  uscale (r);
50  };
51 
52  template < class C > void
53  add (bernstein < C > &mpl, const C & c)
54  {
55  vct::scadd (mpl.begin (), c, mpl.esz (), 1);
56  };
57 
58  template < class C > void
59  add (bernstein < C > &r, const bernstein < C > &a, const C & c)
60  {
61  if (r.env != a.env)
62  add (r = a, c);
63  else
64  vct::scadd (r.begin (), a.begin (), c, r.esz (), 1);
65  };
66 
67  template < class C > void
68  add (bernstein < C > &r, const C & c, const bernstein < C > &a) {
69  add(r,a,c);
70  }
71 
72  template<class C> void
73  rewrite( bernstein<C>& r, const eenv& newe )
74  {
75  if ( newe == r.env ) return;
76  eenv elenv = eenv::elevation (newe, r.env);
77  elevate (r, elenv) ;
78  };
79 
80  template < class C > void
82  {
83  eenv cm(eenv::common(r.env,a.env));
84  if ( r.env != cm ) { rewrite(r,cm); };
85  if ( a.env == cm )
86  {
87  vct::padd (r.begin (), a.begin (), r.esz (), 1, 1);
88  }
89  else
90  {
91  bernstein<C> tmp(a);
92  rewrite(tmp,cm);
93  vct::padd (r.begin (), tmp.begin (), r.esz (), 1, 1);
94  };
95  };
96 
97 
98 template < class C > void
100  add (r=a, b);
101 }
102 
103 
104 template < class C > void
106  eenv cm(eenv::common(r.env,a.env));
107  if ( r.env != cm ) { rewrite(r,cm); };
108  if ( a.env == cm )
109  {
110  vct::psub (r.begin (), a.begin (), r.esz (), 1, 1);
111  }
112  else
113  {
114  bernstein<C> tmp(a);
115  rewrite(tmp,cm);
116  vct::psub (r.begin (), tmp.begin (), r.esz (), 1, 1);
117  };
118 }
119 
120 
121 template < class C > void
123  sub (r = a, b);
124 }
125 
126 template < class C > void
127 sub (bernstein < C > &mpl, const C & c) {
128  vct::scsub (mpl.begin (), c, mpl.esz (), 1);
129 }
130 
131 template < class C > void
132 sub (bernstein < C > &mpl, const C & c, const bernstein < C > &a) {
133  add(mpl,a,-c);
134 }
135 
136 template < class C > void
137 sub (bernstein < C > &mpl, const bernstein < C > &a, const C& c) {
138  add(mpl,a,-c);
139 }
140 
141 template < class C > void
143  bernstein < C > a_ (a);
144  scale (a_);
145  bernstein < C > b_ (b);
146  scale (b_);
147  tensor::conv (r, a_, b_);
148  uscale (r);
149 };
150 
151 template < class C > void
153  bernstein < C > a_;
154  r.swap (a_);
155  scale (a_);
156  bernstein < C > b_ (a);
157  scale (b_);
158  tensor::conv (r, a_, b_);
159  uscale (r);
160 };
161 
162 template < class C > inline void
163 mul (bernstein < C > &r, const bernstein < C > &a, const C &c) {
164  mul(r=a,c);
165 };
166 
167 template < class C > inline void
168 mul (bernstein < C > &r, const C &c, const bernstein < C > &a) {
169  mul(r=a,c);
170 };
171 
172 template < class C > void
173 mul (bernstein < C > &r, const C &c) {
174  vct::scmul(r.begin (),c, r.esz (), 1);
175 }
176 
177 template < class C > inline void
178 div (bernstein < C > &r, const bernstein < C > &a, const C &c) {
179  div(r=a,c);
180 }
181 
182 template < class C > bernstein < C >::bernstein (const eenv & e): base_type(e) {};
183 
184 template < class C > bernstein < C >::bernstein (const eenv & e, const C & c):
185  base_type(e,c){};
186 
187 template < class C >
188 bernstein < C >::bernstein (int nvr, const int *szs, const int *vrs): base_type(nvr,szs,vrs)
189 {
190 }
191 
192 template < class C > bernstein < C >::bernstein (const C & x) : base_type(x) {}
193 
194 template < class Result, class Coeff, class Parameters > inline
195 void eval (Result & result, const bernstein < Coeff > & controls , const Parameters & parameters )
196 {
197  levalb (result, controls.begin (), controls.env,parameters);
198 };
199 
200 template < class Coeff> inline
201 void eval (Coeff& result, const bernstein < Coeff > & controls , const Coeff & v)
202 {
203  Coeff tmp[controls.env.sz()];
204  std::copy (controls.begin(), controls.end(), tmp);
205  decasteljau (tmp , controls.env.sz(), v, 1);
206  result=tmp[0];
207 };
208 
209 template < class Result, class Coeff, class Parameters > inline
210 void eval (Result & result, const bernstein < Coeff > & controls , const Parameters & parameters , unsigned n) {
211  //assert(parameters.size()<n);
212  levalb( result, controls.begin (), controls.env, parameters );
213 };
214 
215 template < class Result, class Coeff, class Parameters > inline
216 void subs0 (Result *result, const bernstein < Coeff > & controls , const Parameters & parameters )
217 {
218  subs0b( result, controls.begin (), controls.env, parameters );
219 };
220 
221 template < class C > void
222 casteljau (bernstein < C > &a, bernstein < C > &b, const C & t, int v)
223 {
224  if (a.env != b.env)
225  realloc (a, b.env);
226  casteljau (a.begin (), b.begin (), t, v);
227 };
228 
229 template < class C > void
231  const bernstein < C > &source, const C & t, int v)
232 {
233  casteljau (left, right = source, t, v);
234 };
235 
236 
237  template < class C > void
239  {
240  if (a.env != b.env)
241  realloc (a, b.env);
242  casteljau (a.begin (), b.begin (), v);
243  };
244 
245  template < class C > void
247  const bernstein < C > &source, int v)
248  {
249  casteljau (left, right = source, v);
250  };
251 
252  template < class C >
253  std::ostream & operator<< (std::ostream & o, const bernstein < C > &mpl)
254  {
255  o << "bernstein object:\n";
256  o << "\t(addresses) o: " << &mpl << " e: " << mpl.env.data << "d: " << mpl.
257  begin () << std::endl;
258  o << "\t(eenv)" << mpl.env << std::endl;
259  o << "\t(data)";
260  array::print (o, mpl.data);
261  o << std::endl;
262  o << ":object bernstein\n";
263  return o;
264  };
265 
266  template<class C> void
267  assign( monomials<C>& monoms, const bernstein<C>& controls )
268  {
269  monoms = controls;
270  tensor::convertb2m(monoms);
271  };
272 
273 
274 // template < class C, class O, class R > void
275 // convert (mpoldst < C, O, R > &mpol, const bernstein < C > &mpl)
276 // {
277 // monomials<C> tmp;
278 // assign(tmp,mpl);
279 // convert(mpol,tmp);
280 // };
281 
282  template < class C > void
283  cfdump (std::ostream & o, const bernstein < C > &mpl)
284  {
285  for (const C * a = mpl.begin (); a != mpl.end (); o << " " << *a++){}
286  };
287 
288  template <class OSTREAM, class C > void
289  mprint (OSTREAM & o, const bernstein < C > &mpl)
290  {
291  monomials < C > mp (0);
292  convert (mp, mpl);
293  o << mp;
294 
295  };
296 
297  template<class OSTREAM, class C > void
298  print(OSTREAM& o , const bernstein<C>& mpl ) {
299  monomials<C> mp(mpl);
300  convertb2m(mp);
301  print(o,mp);
302  };
303 
304  template<class OSTREAM, class C > void inline
305  print(OSTREAM& o , const bernstein<C>& mpl , const variables& v) {
306  monomials<C> mp(mpl);
307  convertb2m(mp);
308  print(o,mp,v);
309  };
310 
311  template < class C > bool bernstein < C >::operator== (const bernstein & mpl) const
312  {
313  return base_type::operator==(mpl);
314  };
315 
316  template<class C> inline
317  void diff( bernstein<C>& res, const bernstein<C>& src, int v )
318  {
319  clear( res, eenv::diff(src.env,v) );
320  bdiff( res.begin(), src.env, src.begin(), v );
321  };
322 
323  template<class C>
325  {
326  this->~bernstein<C>();
327  new (this) bernstein<C>(x);
328  return *this;
329  };
330 
331  template<class C,class T> //inline
332  void split( bernstein<C>& l, bernstein<C>& r, int v, const T& t )
333  {
334  if ( l.env != r.env ) { realloc(l,r.env); };
335  bsplit( l.begin(), r.begin(), r.env, t, r.env.localv(v) );
336  };
337 
338 
339  template<class C> inline
340  void split( bernstein<C>& l, bernstein<C>& r, int v )
341  {
342  if ( l.env != r.env ) { realloc(l,r.env); };
343  bsplit2( l.begin(), r.begin(), r.env, r.env.localv(v) );
344  };
345 
346  template<class C,class T>
347  void restrict( bernstein<C>& rst, int v, const T& a, const T& b ) {
348  v = rst.env.vridx(v);
349  if (v < rst.env.nvr())
350  brestrict( rst.begin(), rst.env, v, a, b );
351  };
352 
353 template<class C> inline
354 void lface ( bernstein<C>& f, const bernstein<C>& src, int v )
355 {
356  lface( f.begin(), src.env, src.begin(), v );
357 };
358 
359 
360 template<class C> inline
361 void rface ( bernstein<C>& f, const bernstein<C>& src, int v )
362 {
363  rface( f.begin(), src.env, src.begin(), v );
364 };
365 
366 
367 template<class C> inline
368 void face ( bernstein<C>& f, const bernstein<C>& src, int v, int n )
369 {
370  assert(n==0||n==1);
371  eenv fenv(face_env(src.env,src.env.localv(v)));
372  if ( f.env != fenv ) realloc( f, fenv );
373  if ( n ) rface( f, src, src.env.localv(v) );
374  else lface( f, src, src.env.localv(v) );
375 };
376 
377 
378 }
379 
380 
381 namespace let {
382  template<class C, class U> void assign(C& p, const U& q);
383 
384  template<class C, class U>
386  {
387  p.env=q.env;
388  p.data = typename tensor::bernstein<C>::vector_type(q.data.size());
389  for(unsigned i=0;i<q.data.size();i++) assign(p.data[i],q.data[i]);
390  }
391 
392  template<class C, class D> inline void
394  {
395  b = tensor::bernstein<C>(m.env);
396  for(int i=0;i<m.size();i++) b[i] =as<C>(m[i]);
398  }
399 
400  template<class C, class D, class O> inline void
401  assign( tensor::bernstein<C>& b, const sparse::monomial_seq<D,O>& m)
402  {
403  b = tensor::bernstein<C>(m);
404  }
405  template<class C, class D, class O, class DOM> inline void
406  assign( tensor::bernstein<C>& b, const sparse::monomial_seq<D,O>& m, const DOM& dom)
407  {
408  b = tensor::bernstein<C>(m,dom);
409  }
410 
411 }//namespace let
412 
413 } //namespace mmx
414 //====================================================================
416 //====================================================================
417 #endif /* realroot_MPOLDSE_BERNSTEIN_C */
bool operator==(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:88
void casteljau(bernstein< C > &a, bernstein< C > &b, const C &t, int v)
Definition: tensor_bernstein_fcts.hpp:222
void bsplit2(C *l, C *r, const eenv &env, int v)
Definition: tensor_eenv_loops.hpp:428
void bsplit(C *l, C *r, const eenv &env, const T &t, int v)
Definition: tensor_eenv_loops.hpp:399
void uscale(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:20
const C & b
Definition: Interval_glue.hpp:25
void add(bernstein< C > &mpl, const C &c)
Definition: tensor_bernstein_fcts.hpp:53
void swap(monomials< C > &a)
Definition: tensor_monomials.hpp:88
void subs0(Result *result, const bernstein< Coeff > &controls, const Parameters &parameters)
Definition: tensor_bernstein_fcts.hpp:216
void clear(monomials< C > &monoms)
Definition: tensor_monomials_fcts.hpp:87
static eenv elevation(const eenv &a, const eenv &b)
Definition: tensor_eenv_fcts.hpp:366
void mul(bernstein< C > &r, const bernstein< C > &a, const bernstein< C > &b)
Definition: tensor_bernstein_fcts.hpp:142
void elevate(bernstein< C > &r, const eenv &elev)
Definition: tensor_bernstein_fcts.hpp:43
void restrict(bernstein< C > &rst, int v, const T &a, const T &b)
Definition: tensor_bernstein_fcts.hpp:347
int size() const
Definition: tensor_monomials.hpp:72
static eenv common(const eenv &a, const eenv &b)
Definition: tensor_eenv_fcts.hpp:211
void rewrite(bernstein< C > &r, const eenv &newe)
Definition: tensor_bernstein_fcts.hpp:73
Definition: tensor_eenv.hpp:9
int localv(int i) const
Definition: tensor_eenv.hpp:61
void assign(monomials< C > &monoms, const bernstein< C > &controls)
Definition: tensor_bernstein_fcts.hpp:267
eenv face_env(const eenv &e, int lv)
Definition: tensor_monomials_fcts.hpp:428
void eval(Result &result, const bernstein< Coeff > &controls, const Parameters &parameters)
Definition: tensor_bernstein_fcts.hpp:195
void scsub(A *a, const B &b, unsigned n, int s=1)
Definition: tensor_vctops.hpp:74
void sub(bernstein< C > &r, const bernstein< C > &a)
Definition: tensor_bernstein_fcts.hpp:105
vector_type data
Definition: tensor_monomials.hpp:32
C * begin()
Definition: tensor_monomials.hpp:47
int nvr() const
number of variables
Definition: tensor_eenv_fcts.hpp:9
int vridx(int i) const
Definition: tensor_eenv.hpp:62
TMPL void copy(Polynomial &r, const Polynomial &a)
Copy of a in r.
Definition: sparse_monomials.hpp:613
C * end()
Definition: tensor_monomials.hpp:48
UPOL convert(const MPOL &p, unsigned v)
Definition: tensor_convert.hpp:73
void brestrict(C *src, const eenv &env, int v, const T &a, const T &b)
Definition: tensor_eenv_loops.hpp:489
void cfdump(std::ostream &o, const bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:283
Definition: tensor_monomials.hpp:18
void binoms(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:9
TMPL void face(Polynomial &r, const Polynomial &p, int v, int f)
Definition: polynomial_fcts.hpp:188
void print(OSTREAM &o, const bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:298
static eenv diff(const eenv &b, int lv)
Definition: tensor_eenv_fcts.hpp:270
void scadd(A *a, const B &b, unsigned n, int s=1)
Definition: tensor_vctops.hpp:62
TMPL void split(Polynomial &r, Polynomial &p, int v)
Definition: polynomial_fcts.hpp:193
int sz() const
return the total number of coefficients of the dense representation
Definition: tensor_eenv_fcts.hpp:16
base_type::vector_type vector_type
Definition: tensor_bernstein.hpp:17
void padd(A *a, const B *b, unsigned sz, int sta=1, int stb=1)
Definition: tensor_vctops.hpp:13
void mprint(OSTREAM &o, const bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:289
TMPL Polynomial diff(const Polynomial &p, int v)
Definition: tensor_bernstein.hpp:79
void decasteljau(real_t *r, unsigned sz, const value_t &t, int str=1)
Definition: tensor_eenv_loops.hpp:70
Definition: binomials.hpp:68
int esz() const
Definition: tensor_monomials.hpp:71
const C & c
Definition: Interval_glue.hpp:45
double C
Definition: solver_mv_fatarcs.cpp:16
void convertm2b(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:31
void lface(bernstein< C > &f, const bernstein< C > &src, int v)
Definition: tensor_bernstein_fcts.hpp:354
bernstein & operator=(const C &x)
Definition: tensor_bernstein_fcts.hpp:324
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
void convertb2m(monomials< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:26
void psub(A *a, const B *b, unsigned sz, int sta=1, int stb=1)
Definition: tensor_vctops.hpp:26
void levalb(R &result, const C *data, const eenv &env, const P &p)
Definition: tensor_eenv_loops.hpp:80
void scale(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:14
void div(bernstein< C > &r, const bernstein< C > &a, const C &c)
Definition: tensor_bernstein_fcts.hpp:178
Definition: array.hpp:12
void conv(MPLBASE0 &r, const MPLBASE1 &a)
Definition: tensor_convert.hpp:62
void rface(bernstein< C > &f, const bernstein< C > &src, int v)
Definition: tensor_bernstein_fcts.hpp:361
Definition: variables.hpp:65
void realloc(monomials< C > &mpl, const eenv &nenv)
Definition: tensor_monomials_fcts.hpp:77
eenv env
Definition: tensor_monomials.hpp:31
void scmul(A *a, const B &b, unsigned n, int s=1)
Definition: tensor_vctops.hpp:98
Definition: tensor_bernstein.hpp:13
OS & print(OS &os, const R &v)
Output function for general vectors: [v1, v2, ...].
Definition: array.hpp:39
#define assert(expr, msg)
Definition: shared_object.hpp:57
Home