mmx::array Namespace Reference

Module for generic functions on vectors. Generic implementations for vectors are gathered in the namespace array. These are generic functions, that can be used to build new linear classes. The type R must provide the following definitions or methods:. More...

Functions


Detailed Description

Module for generic functions on vectors. Generic implementations for vectors are gathered in the namespace array. These are generic functions, that can be used to build new linear classes. The type R must provide the following definitions or methods:.

     typename  index_t;
     typename  value_type;
     typename  iterator;
     typename  const_iterator;

     index_t this->size();
     value_type this->operator[](index_t);

     iterator begin();
     iterator end();
     const_iterator begin() const;
     const_iterator end()   const;

Function Documentation

void mmx::array::add ( V &  r,
const V &  a,
const V &  b 
) [inline]

Specialisation of the function add when W=V. Inplace addition is used when r=a or r=b.

Definition at line 208 of file array.hpp.

References add(), and add_g().

00209   {
00210     if(&r==&a) { add(r,b); return; };
00211     if(&r==&b) { add(r,a); return; };
00212     add_g(r,a,b);
00213   }

void mmx::array::add ( V &  r,
const W &  a,
const X &  b 
) [inline]

Addition of two vectors. r should be allocated to the correct size and with 0 entries.

Definition at line 200 of file array.hpp.

References add_g().

00201   {
00202     add_g(r,a,b);
00203   }

void mmx::array::add ( V &  a,
const W &  b 
) [inline]

Addition of two vectors.

Definition at line 154 of file array.hpp.

References add_i(), add_n(), and copy_range().

Referenced by mmx::add(), add(), box_rep< C >::min_grad(), msimplify(), mmx::mul(), and seq2b().

00155   {
00156     int asz, bsz;
00157     asz = a.size(), bsz = b.size();
00158     if ( asz < bsz  ) 
00159       { 
00160         a.resize(bsz);
00161         add_i(a.begin(),a.end(),b.begin()); 
00162         copy_range(a,b,asz,bsz);
00163       }
00164     else 
00165       {
00166         //      PRINT_DEBUG("add");
00167         add_n(a,b,bsz);
00168         //      add_i(a.begin(),a.begin()+bsz,b.begin());
00169       }
00170   }

void mmx::array::add_g ( V &  r,
const W &  a,
const X &  b 
) [inline]

Addition of two vectors. r should be allocated to the correct size and with 0 entries.

Definition at line 179 of file array.hpp.

References add_n(), and copy_range().

Referenced by add().

00180   {  
00181     int asz, bsz, rsz;
00182     asz = a.size(), bsz = b.size(), rsz = r.size();
00183     if ( asz > bsz ) 
00184       {
00185         if ( asz > rsz ) r.resize(asz);
00186         add_n(r,a,b,bsz);
00187         copy_range(r,a,bsz,asz);
00188       }
00189     else
00190       { 
00191         if ( bsz > rsz ) r.resize(bsz);
00192         add_n(r,a,b,asz); 
00193         copy_range(r,b,asz,bsz); 
00194       };
00195   }

void mmx::array::add_i ( VI  a,
VI  ea,
WI  b 
) [inline]

Definition at line 150 of file array.hpp.

Referenced by add().

00150 { for ( ; a != ea; *a += *b, ++a, ++b ){} };

void mmx::array::add_n ( V &  a,
const W &  b,
const X &  c,
int  n 
) [inline]

Definition at line 173 of file array.hpp.

00173 { for ( int i = 0; i < n; a[i] = b[i]+c[i], i ++ ){} };

void mmx::array::add_n ( V &  a,
const W &  b,
int  n 
) [inline]

Definition at line 148 of file array.hpp.

Referenced by add(), and add_g().

00148 {for ( int i = 0; i < n; a[i] += b[i], i ++ ){} }

void mmx::array::apply_mult ( R &  result,
const S &  a,
const C &  m 
) [inline]

Definition at line 342 of file array.hpp.

00343   { 
00344     typedef typename S::const_iterator  const_iterator;
00345     typedef typename R::iterator        iterator;
00346     result.resize(a.size());
00347     const_iterator b=a.begin(); iterator i=result.begin();
00348     for(; b!=a.end(); ++i, ++b) *i = (*b) * m;
00349   }

void mmx::array::assign ( Ra &  a,
const Rb &  b 
) [inline]

Definition at line 425 of file array.hpp.

References assign_i().

Referenced by approx(), and box_rep< C >::max_eval().

00426   {
00427     a.resize( b.size() );
00428     assign_i( a.begin(), a.end(), b.begin() );
00429   };

void mmx::array::assign_i ( Ia  a,
Ia  eda,
Ib  b 
) [inline]

Definition at line 419 of file array.hpp.

References mmx::let::assign().

Referenced by assign().

00420   {
00421     for ( ; a != eda; ++a, ++b  ) let::assign(*a,*b);
00422   };

void mmx::array::copy_range ( V &  v,
const W &  w,
int  a,
int  b 
) [inline]

Definition at line 146 of file array.hpp.

Referenced by add(), add_g(), and sub_g().

00146 { for ( int i = a; i < b; v[i] = w[i], i ++ ){} }

void mmx::array::div ( V &  a,
const W &  c 
) [inline]

Inplace scalar division.

Definition at line 334 of file array.hpp.

References div_ext().

00335   {
00336     div_ext(a,c);
00337     //W tmp(c); for(typename V::iterator it=a.begin(); it !=a.end(); ++it) (*it)/=tmp;
00338   }

void mmx::array::div_ext ( V &  a,
const W &  c 
) [inline]

Scalar division.

Definition at line 329 of file array.hpp.

References div_ext_i().

00330   { div_ext_i(a.begin(),a.end(),c); }

void mmx::array::div_ext ( V &  a,
const V &  b,
const SC &  sc 
) [inline]

Scalar division.

Definition at line 319 of file array.hpp.

References div_ext_i().

Referenced by mmx::univariate::div(), and div().

00320   {
00321     if(&a != &b) {
00322       a.resize( b.size() );
00323       div_ext_i(a.begin(),a.end(),b.begin(),sc);
00324     }
00325     else         div_ext_i(a.begin(),a.end(),sc);
00326   }

void mmx::array::div_ext_i ( VI  a,
VI  eda,
VI  b,
const SC &  sc 
) [inline]

Definition at line 315 of file array.hpp.

00316   { for ( ; a < eda; *a = *b / sc, a++, b ++ ){} };

void mmx::array::div_ext_i ( VI  bga,
VI  eda,
const SC &  sc 
) [inline]

Definition at line 312 of file array.hpp.

Referenced by div_ext().

00313   { for ( ; bga < eda; *bga /= sc, bga++){} }

void mmx::array::div_ext_n ( V1 &  a,
const V2 &  b,
const SC &  sc,
int  n 
) [inline]

Definition at line 309 of file array.hpp.

00310   { for ( int i = 0; i < n; a[i] = b[i]/sc, i ++ ){} };

void mmx::array::div_ext_n ( V &  a,
const SC &  sc,
int  n 
) [inline]

Definition at line 306 of file array.hpp.

00307   { for ( int i = 0; i < n; a[i] /= sc, i++){} }

bool mmx::array::equal ( const V1 &  v1,
const V2 &  v2 
) [inline]

Definition at line 88 of file array.hpp.

References equal_n().

00089   { return (v1.size() == v2.size()) && equal_n(v1,v2,v1.size()); }

bool mmx::array::equal_n ( const V1 &  v1,
const V2 &  v2,
int  n 
) [inline]

Definition at line 79 of file array.hpp.

Referenced by equal().

00080   {
00081     int i=0;
00082     while(i < n && v1[i] == v2[i]) i++;
00083     return i == n;
00084   };

void mmx::array::init_n ( V &  a,
const C &  v,
int  n 
) [inline]

Definition at line 94 of file array.hpp.

Referenced by set_cst().

00094                                           { 
00095     for ( int i = 0; i < n; a[i] = v, i ++ ) {} };

R::value_type mmx::array::innerprod ( const S &  v,
const R &  w 
) [inline]

Definition at line 379 of file array.hpp.

00380   {
00381     typename R::value_type r =0;
00382     for(unsigned int i=0; i <v.size(); i++){r += (v[i]*w[i]);}
00383     return r;
00384   }

R::value_type mmx::array::innerprod_n ( const S &  v,
const R &  w,
unsigned  n 
) [inline]

Innerproduct of two vectors.

Definition at line 371 of file array.hpp.

00372   {
00373     typename R::value_type r = 0;
00374     for ( unsigned i = 0; i < n; r += v[i]*w[i], i++ ) {}
00375     return r;
00376   };

void mmx::array::lcm_denominator ( U &  r,
const R &  v 
) [inline]

Definition at line 400 of file array.hpp.

References mmx::denominator(), and mmx::lcm().

00401   {
00402     for(unsigned i=0; i <v.size(); i++)
00403       {
00404         r = lcm(r,denominator(v[i]));
00405       }
00406   }

R::value_type mmx::array::max_abs ( const R &  v  )  [inline]

Definition at line 387 of file array.hpp.

Referenced by binary_sleeve_subdivision< K >::init_pol().

00388   {
00389     typename R::value_type r=0;
00390     for(unsigned i=0; i <(unsigned)v.size(); i++)
00391       {
00392         if(r>v[i]) r=v[i];
00393         else if(r>-v[i]) r=-v[i];
00394       }
00395     return r;
00396   }

void mmx::array::mul_ext ( V &  a,
const W &  c 
) [inline]

Definition at line 301 of file array.hpp.

References mul_ext_i().

00301                                     {
00302     mul_ext_i(a.begin(),a.end(),c);
00303   }

void mmx::array::mul_ext ( V &  a,
const V &  b,
const W &  c 
) [inline]

Scalar multiplication.

Definition at line 291 of file array.hpp.

References mul_ext_i().

Referenced by mmx::univariate::mul().

00292   {
00293     if(&a != &b) {
00294       a.resize( b.size() );
00295       mul_ext_i(a.begin(),a.end(),b.begin(),c);
00296     }
00297     else 
00298       mul_ext_i(a.begin(),a.end(),c);
00299   }

void mmx::array::mul_ext_i ( VI  bga,
VI  eda,
VII  bgb,
const W &  c 
) [inline]

Definition at line 286 of file array.hpp.

00287   { for ( VI a = bga; a != eda; *a = *bgb * c, ++bgb, ++a ){} };

void mmx::array::mul_ext_i ( VI  bga,
VI  eda,
const W &  c 
) [inline]

Definition at line 283 of file array.hpp.

Referenced by mul_ext().

00284     { for ( VI i = bga; i != eda; *i *= c, ++i  ){} };

void mmx::array::mul_ext_n ( V &  a,
const W &  b,
const S &  c,
int  n 
) [inline]

Definition at line 280 of file array.hpp.

00281   { for ( int i = 0; i < n; a[i] = b[i]*c, i++ ){} };

void mmx::array::mul_ext_n ( V &  a,
const W &  c,
int  n 
) [inline]

Definition at line 277 of file array.hpp.

00278   { for ( int i = 0; i < n; a[i] = a[i]*c, i ++ ){} };

void mmx::array::neg ( V &  a,
const V &  b 
) [inline]

Definition at line 139 of file array.hpp.

References neg_i().

00140   { 
00141     a.resize( b.size() );
00142     neg_i( a.begin(), a.end(), b.begin() ); 
00143   };

void mmx::array::neg ( V &  v  )  [inline]

Definition at line 137 of file array.hpp.

References neg_i().

00137 { neg_i(v.begin(),v.end()); };

void mmx::array::neg_i ( VI  a,
VI  eda,
VI  b 
) [inline]

Definition at line 135 of file array.hpp.

00135 { for ( ; a != eda; *a = -(*b), a++, b++  ){} };

void mmx::array::neg_i ( VI  a,
VI  eda 
) [inline]

Definition at line 133 of file array.hpp.

Referenced by neg().

00133 { for ( ; a != eda; *a = -(*a), a++ ){} };

void mmx::array::neg_range ( V &  r,
int  a,
int  b 
) [inline]

Definition at line 129 of file array.hpp.

00130   { for ( int i = a; i < b; r[i] = -r[i], i++ ){} };

void mmx::array::neg_range ( V &  r,
const W &  w,
int  a,
int  b 
) [inline]

Definition at line 125 of file array.hpp.

Referenced by sub(), and sub_g().

00125                                                      { 
00126     for ( int i = a; i < b; r[i] = -w[i], i++ ) {}
00127   }

C mmx::array::norm ( const R &  v,
int  p 
) [inline]

Norm $L_{p}$ of a vector.

Definition at line 362 of file array.hpp.

References C, and mmx::pow().

00363   {
00364     C r=0;
00365     for(typename R::const_iterator it=v.begin(); it !=v.end(); ++it) r+=pow(*it,p);
00366     return pow(r,1/p);
00367   }

C mmx::array::norm ( const R &  v  )  [inline]

The $L_{2}$ norm for vectors.

Definition at line 353 of file array.hpp.

References C, and mmx::sqrt().

00354   {
00355     C r=0;
00356     for(typename R::const_iterator it=v.begin(); it !=v.end(); ++it) r+=(*it)*(*it);
00357     return sqrt(r);
00358   }

OS& mmx::array::print ( OS &  os,
const R &  v,
unsigned  sz 
) [inline]

Output function for general vectors: [v1, v2, ...].

Definition at line 52 of file array.hpp.

00052                                                        {
00053     os <<"[";
00054     unsigned i=0;
00055     if (sz){
00056       os<<v[i]; ++i;
00057       for(; i <sz; ++i) os <<","<<v[i];
00058     }
00059     os <<"]";
00060     return os;
00061   }

OS& mmx::array::print ( OS &  os,
const R &  v 
) [inline]

Output function for general vectors: [v1, v2, ...].

Definition at line 39 of file array.hpp.

00039                                           {
00040     os <<"[";
00041     typename R::const_iterator i=v.begin();
00042     if (v.size()){
00043       os<<*i; ++i;
00044       for(; i != v.end(); ++i) {os <<", "; os<<*i;}
00045     }
00046     os <<"]";
00047     return os;
00048   }

IS& mmx::array::read ( IS &  is,
R &  V 
) [inline]

Input operator for standard vectors. The input format is of the form s c0 c1 ... where s is the number of elements.

Definition at line 68 of file array.hpp.

00068                                    {
00069     typedef typename R::size_type size_type;
00070     size_type s;
00071     is >> s;
00072     V.rep().resize(s);
00073     for(size_type i=0; i< s; ++i) is >> V[i];
00074     return(is);
00075   }

void mmx::array::reverse ( V &  v  )  [inline]

Definition at line 410 of file array.hpp.

References V.

00411   { 
00412     unsigned sz = v.size();
00413     V temp(v);
00414     for (unsigned i = 0; i < sz; ++i)
00415       v[i] = temp[sz-1-i];
00416 }

void mmx::array::reverse ( V &  v,
d 
) [inline]

Reverse the entries of v, from the index 0 to d-1.

Definition at line 119 of file array.hpp.

References mmx::sparse::swap().

00119                            { 
00120     for(I i=0;i<d/2; std::swap(v[i],v[d-1-i]),++i) {}
00121   }

void mmx::array::reverse ( V &  v,
int  n 
) [inline]

Definition at line 115 of file array.hpp.

References reverse_n().

00115 { reverse_n( v, 0, n ); };

void mmx::array::reverse_n ( V &  v,
int  a,
int  n 
) [inline]

Reverse the entries of v, from the index a to n-1.

Definition at line 108 of file array.hpp.

References mmx::sparse::swap().

Referenced by reverse().

00109   {
00110     int k = n - a;
00111     for ( int i = 0; i < k/2; std::swap(v[a+i],v[k-1-i]), i ++ ) {}
00112   };

void mmx::array::set ( V &  a,
const W &  b 
) [inline]

Definition at line 103 of file array.hpp.

References V.

00103 {for ( int i = 0; i < (int)a.size(); a[i] = b[i], i ++ ) {} };

void mmx::array::set_cst ( V &  a,
const C &  v 
) [inline]

Set all the entries of a to the values v.

Definition at line 99 of file array.hpp.

References init_n().

Referenced by mmx::univariate::convertm2b(), mmx::univariate::mul(), mmx::univariate::mul_index(), and mmx::univariate::set_monomial().

00099 { init_n(a,v,(int)a.size()); };

void mmx::array::sub ( V &  r,
const V &  a,
const V &  b 
) [inline]

Specialisation of the sub function when W=V. Inplace substraction is used when r=a or r=b.

Definition at line 269 of file array.hpp.

References sub(), and sub_g().

00270   {
00271     if(&r==&a) { sub(r,b); return; };
00272     //    if(&r==&b) { sub(r,a); mul_ext(r,-1); return; };
00273     sub_g(r,a,b);
00274   }

void mmx::array::sub ( V &  r,
const W &  a,
const X &  b 
) [inline]

Substraction of two vectors. r should be allocated to the correct size and with 0 entries.

Definition at line 261 of file array.hpp.

References sub_g().

00262   {
00263     sub_g(r,a,b);
00264   }

void mmx::array::sub ( V &  a,
const W &  b 
) [inline]

Substraction of two vectors.

Definition at line 221 of file array.hpp.

References neg_range(), and sub_n().

Referenced by mmx::div(), and sub().

00222   {
00223     int asz, bsz;
00224     asz = a.size(), bsz = b.size();
00225     if ( asz < bsz  ) 
00226       { 
00227         a.resize(bsz);
00228         sub_n(a,b,asz);
00229         neg_range(a,b,asz,bsz); 
00230       }
00231     else  
00232       sub_n(a,b,bsz);
00233   }

void mmx::array::sub_g ( V &  r,
const W &  a,
const X &  b 
) [inline]

Definition at line 240 of file array.hpp.

References copy_range(), neg_range(), and sub_n().

Referenced by sub().

00241   { 
00242     int asz, bsz, rsz;
00243     asz = a.size(), bsz = b.size(), rsz = r.size();
00244     
00245     if ( asz > bsz ) 
00246       {
00247         if ( asz > rsz ) r.resize(asz);
00248         sub_n(r,a,b,bsz);
00249         copy_range(r,a,bsz,asz);
00250       }
00251     else
00252       { 
00253         if ( bsz > rsz ) r.resize(bsz);
00254         sub_n(r,a,b,asz);
00255         neg_range(r,b,asz,bsz);
00256       };
00257   }

void mmx::array::sub_n ( V &  a,
const W &  b,
const X &  c,
int  n 
) [inline]

Definition at line 236 of file array.hpp.

00236 { for ( int i = 0; i < n; a[i] = b[i]-c[i], i ++ ){} };

void mmx::array::sub_n ( V &  a,
const W &  b,
int  n 
) [inline]

Definition at line 216 of file array.hpp.

Referenced by sub(), and sub_g().

00216 { for ( int i = 0; i < n; a[i] -= b[i], i ++ ){} };

void mmx::array::vaddsc ( R &  r,
const C &  x 
) [inline]

Definition at line 432 of file array.hpp.

00433   { for ( typename R::iterator i = r.begin(); i != r.end(); *i += x, i ++ ){} };


Generated on 6 Dec 2012 for realroot by  doxygen 1.6.1