realroot_doc 0.1.1
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: {SIGNATURE} typename index_t; typename value_type; typename iterator; typename const_iterator;. 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: {SIGNATURE} 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; {SIGNATURE}


Function Documentation

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

Addition of two vectors.

Definition at line 155 of file array.hpp.

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

Referenced by mmx::add(), add(), msimplify(), and mmx::mul().

  {
    int asz, bsz;
    asz = a.size(), bsz = b.size();
    if ( asz < bsz  ) 
      { 
        a.resize(bsz);
        add_i(a.begin(),a.end(),b.begin()); 
        copy_range(a,b,asz,bsz);
      }
    else 
      {
        //      PRINT_DEBUG("add");
        add_n(a,b,bsz);
        //      add_i(a.begin(),a.begin()+bsz,b.begin());
      }
  }
void mmx::array::add ( V &  r,
const W &  a,
const X &  b 
) [inline]

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

Definition at line 201 of file array.hpp.

References add_g().

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

Specialisation of the function @ when =V@. Inplace addition is used when =a@ or =b@.

Definition at line 209 of file array.hpp.

References add(), and add_g().

  {
    if(&r==&a) { add(r,b); return; };
    if(&r==&b) { add(r,a); return; };
    add_g(r,a,b);
  }
void mmx::array::add_g ( V &  r,
const W &  a,
const X &  b 
)

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

Definition at line 180 of file array.hpp.

References add_n(), and copy_range().

Referenced by add().

  {  
    int asz, bsz, rsz;
    asz = a.size(), bsz = b.size(), rsz = r.size();
    if ( asz > bsz ) 
      {
        if ( asz > rsz ) r.resize(asz);
        add_n(r,a,b,bsz);
        copy_range(r,a,bsz,asz);
      }
    else
      { 
        if ( bsz > rsz ) r.resize(bsz);
        add_n(r,a,b,asz); 
        copy_range(r,b,asz,bsz); 
      };
  }
void mmx::array::add_i ( VI  a,
VI  ea,
WI  b 
)

Definition at line 151 of file array.hpp.

Referenced by add().

{ for ( ; a != ea; *a += *b, ++a, ++b ){} };
void mmx::array::add_n ( V &  a,
const W &  b,
int  n 
)

Definition at line 149 of file array.hpp.

Referenced by add(), and add_g().

{for ( int i = 0; i < n; a[i] += b[i], i ++ ){} }
void mmx::array::add_n ( V &  a,
const W &  b,
const X &  c,
int  n 
) [inline]

Definition at line 174 of file array.hpp.

{ for ( int i = 0; i < n; a[i] = b[i]+c[i], i ++ ){} };
void mmx::array::apply_mult ( R &  result,
const S &  a,
const C &  m 
) [inline]

Definition at line 343 of file array.hpp.

  { 
    typedef typename S::const_iterator  const_iterator;
    typedef typename R::iterator        iterator;
    result.resize(a.size());
    const_iterator b=a.begin(); iterator i=result.begin();
    for(; b!=a.end(); ++i, ++b) *i = (*b) * m;
  }
void mmx::array::assign ( Ra &  a,
const Rb &  b 
) [inline]

Definition at line 426 of file array.hpp.

References assign_i().

  {
    a.resize( b.size() );
    assign_i( a.begin(), a.end(), b.begin() );
  };
void mmx::array::assign_i ( Ia  a,
Ia  eda,
Ib  b 
) [inline]

Definition at line 420 of file array.hpp.

References mmx::let::assign().

Referenced by assign().

  {
    for ( ; a != eda; ++a, ++b  ) let::assign(*a,*b);
  };
void mmx::array::copy_range ( V &  v,
const W &  w,
int  a,
int  b 
) [inline]

Definition at line 147 of file array.hpp.

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

{ for ( int i = a; i < b; v[i] = w[i], i ++ ){} }
void mmx::array::div ( V &  a,
const W &  c 
)

Inplace scalar division.

Definition at line 335 of file array.hpp.

References div_ext().

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

  {
    div_ext(a,c);
    //W tmp(c); for(typename V::iterator it=a.begin(); it !=a.end(); ++it) (*it)/=tmp;
  }
void mmx::array::div_ext ( V &  a,
const V &  b,
const SC &  sc 
)

Scalar division.

Definition at line 320 of file array.hpp.

References div_ext_i().

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

  {
    if(&a != &b) {
      a.resize( b.size() );
      div_ext_i(a.begin(),a.end(),b.begin(),sc);
    }
    else         div_ext_i(a.begin(),a.end(),sc);
  }
void mmx::array::div_ext ( V &  a,
const W &  c 
)

Scalar division.

Definition at line 330 of file array.hpp.

References div_ext_i().

  { div_ext_i(a.begin(),a.end(),c); }
void mmx::array::div_ext_i ( VI  bga,
VI  eda,
const SC &  sc 
) [inline]

Definition at line 313 of file array.hpp.

Referenced by div_ext().

  { for ( ; bga < eda; *bga /= sc, bga++){} }
void mmx::array::div_ext_i ( VI  a,
VI  eda,
VI  b,
const SC &  sc 
) [inline]

Definition at line 316 of file array.hpp.

  { for ( ; a < eda; *a = *b / sc, a++, b ++ ){} };
void mmx::array::div_ext_n ( V &  a,
const SC &  sc,
int  n 
) [inline]

Definition at line 307 of file array.hpp.

  { for ( int i = 0; i < n; a[i] /= sc, i++){} }
void mmx::array::div_ext_n ( V1 &  a,
const V2 &  b,
const SC &  sc,
int  n 
)

Definition at line 310 of file array.hpp.

  { for ( int i = 0; i < n; a[i] = b[i]/sc, i ++ ){} };
bool mmx::array::equal ( const V1 &  v1,
const V2 &  v2 
) [inline]

Definition at line 89 of file array.hpp.

References equal_n().

  { 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 80 of file array.hpp.

Referenced by equal().

  {
    int i=0;
    while(i < n && v1[i] == v2[i]) i++;
    return i == n;
  };
void mmx::array::init_n ( V &  a,
const C &  v,
int  n 
) [inline]

Definition at line 95 of file array.hpp.

Referenced by set_cst().

                                          { 
    for ( int i = 0; i < n; a[i] = v, i ++ ) {} };
R::value_type mmx::array::innerprod ( const S &  v,
const R &  w 
)

Definition at line 380 of file array.hpp.

  {
    typename R::value_type r =0;
    for(unsigned int i=0; i <v.size(); i++){r += (v[i]*w[i]);}
    return r;
  }
R::value_type mmx::array::innerprod_n ( const S &  v,
const R &  w,
unsigned  n 
)

Innerproduct of two vectors.

Definition at line 372 of file array.hpp.

  {
    typename R::value_type r = 0;
    for ( unsigned i = 0; i < n; r += v[i]*w[i], i++ ) {}
    return r;
  };
void mmx::array::lcm_denominator ( U &  r,
const R &  v 
)

Definition at line 401 of file array.hpp.

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

  {
    for(unsigned i=0; i <v.size(); i++)
      {
        r = lcm(r,denominator(v[i]));
      }
  }
R::value_type mmx::array::max_abs ( const R &  v)

Definition at line 388 of file array.hpp.

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

  {
    typename R::value_type r=0;
    for(unsigned i=0; i <(unsigned)v.size(); i++)
      {
        if(r>v[i]) r=v[i];
        else if(r>-v[i]) r=-v[i];
      }
    return r;
  }
void mmx::array::mul_ext ( V &  a,
const V &  b,
const W &  c 
)

Scalar multiplication.

Definition at line 292 of file array.hpp.

References mul_ext_i().

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

  {
    if(&a != &b) {
      a.resize( b.size() );
      mul_ext_i(a.begin(),a.end(),b.begin(),c);
    }
    else 
      mul_ext_i(a.begin(),a.end(),c);
  }
void mmx::array::mul_ext ( V &  a,
const W &  c 
)

Definition at line 302 of file array.hpp.

References mul_ext_i().

                                    {
    mul_ext_i(a.begin(),a.end(),c);
  }
void mmx::array::mul_ext_i ( VI  bga,
VI  eda,
const W &  c 
) [inline]

Definition at line 284 of file array.hpp.

Referenced by mul_ext().

    { for ( VI i = bga; i != eda; *i *= c, ++i  ){} };
void mmx::array::mul_ext_i ( VI  bga,
VI  eda,
VII  bgb,
const W &  c 
) [inline]

Definition at line 287 of file array.hpp.

  { for ( VI a = bga; a != eda; *a = *bgb * c, ++bgb, ++a ){} };
void mmx::array::mul_ext_n ( V &  a,
const W &  b,
const S &  c,
int  n 
) [inline]

Definition at line 281 of file array.hpp.

  { 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 278 of file array.hpp.

  { for ( int i = 0; i < n; a[i] = a[i]*c, i ++ ){} };
void mmx::array::neg ( V &  v) [inline]

Definition at line 138 of file array.hpp.

References neg_i().

{ neg_i(v.begin(),v.end()); };
void mmx::array::neg ( V &  a,
const V &  b 
) [inline]

Definition at line 140 of file array.hpp.

References neg_i().

  { 
    a.resize( b.size() );
    neg_i( a.begin(), a.end(), b.begin() ); 
  };
void mmx::array::neg_i ( VI  a,
VI  eda 
) [inline]

Definition at line 134 of file array.hpp.

Referenced by neg().

{ for ( ; a != eda; *a = -(*a), a++ ){} };
void mmx::array::neg_i ( VI  a,
VI  eda,
VI  b 
) [inline]

Definition at line 136 of file array.hpp.

{ for ( ; a != eda; *a = -(*b), a++, b++  ){} };
void mmx::array::neg_range ( V &  r,
const W &  w,
int  a,
int  b 
) [inline]

Definition at line 126 of file array.hpp.

Referenced by sub(), and sub_g().

                                                     { 
    for ( int i = a; i < b; r[i] = -w[i], i++ ) {}
  }
void mmx::array::neg_range ( V &  r,
int  a,
int  b 
) [inline]

Definition at line 130 of file array.hpp.

  { for ( int i = a; i < b; r[i] = -r[i], i++ ){} };
C mmx::array::norm ( const R &  v)

The $L_{2}$ norm for vectors.

Definition at line 354 of file array.hpp.

References mmx::sqrt().

  {
    C r=0;
    for(typename R::const_iterator it=v.begin(); it !=v.end(); ++it) r+=(*it)*(*it);
    return sqrt(r);
  }
C mmx::array::norm ( const R &  v,
int  p 
)

Norm $L_{p}$ of a vector.

Definition at line 363 of file array.hpp.

References mmx::pow().

  {
    C r=0;
    for(typename R::const_iterator it=v.begin(); it !=v.end(); ++it) r+=pow(*it,p);
    return pow(r,1/p);
  }
OS& mmx::array::print ( OS &  os,
const R &  v 
) [inline]

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

Definition at line 40 of file array.hpp.

                                          {
    os <<"[";
    typename R::const_iterator i=v.begin();
    if (v.size()){
      os<<*i; ++i;
      for(; i != v.end(); ++i) {os <<", "; os<<*i;}
    }
    os <<"]";
    return os;
  }
OS& mmx::array::print ( OS &  os,
const R &  v,
unsigned  sz 
) [inline]

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

Definition at line 53 of file array.hpp.

                                                       {
    os <<"[";
    unsigned i=0;
    if (sz){
      os<<v[i]; ++i;
      for(; i <sz; ++i) os <<","<<v[i];
    }
    os <<"]";
    return os;
  }
IS& mmx::array::read ( IS &  is,
R &  V 
) [inline]

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

Definition at line 69 of file array.hpp.

                                   {
    typedef typename R::size_type size_type;
    size_type s;
    is >> s;
    V.rep().resize(s);
    for(size_type i=0; i< s; ++i) is >> V[i];
    return(is);
  }
void mmx::array::reverse ( V &  v,
int  n 
)

Definition at line 116 of file array.hpp.

References reverse_n().

{ reverse_n( v, 0, n ); };
void mmx::array::reverse ( V &  v,
d 
)

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

Definition at line 120 of file array.hpp.

References mmx::sparse::swap().

                           { 
    for(I i=0;i<d/2; std::swap(v[i],v[d-1-i]),++i) {}
  }
void mmx::array::reverse ( V &  v) [inline]

Definition at line 411 of file array.hpp.

  { 
    unsigned sz = v.size();
    V temp(v);
    for (unsigned i = 0; i < sz; ++i)
      v[i] = temp[sz-1-i];
}
void mmx::array::reverse_n ( V &  v,
int  a,
int  n 
)

Reverse the entries of @, from the index @ to
-1@.

Definition at line 109 of file array.hpp.

References mmx::sparse::swap().

Referenced by reverse().

  {
    int k = n - a;
    for ( int i = 0; i < k/2; std::swap(v[a+i],v[k-1-i]), i ++ ) {}
  };
void mmx::array::set ( V &  a,
const W &  b 
)

Definition at line 104 of file array.hpp.

{for ( int i = 0; i < (int)a.size(); a[i] = b[i], i ++ ) {} };
void mmx::array::set_cst ( V &  a,
const C &  v 
)

Set all the entries of @ to the values @.

Definition at line 100 of file array.hpp.

References init_n().

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

{ init_n(a,v,(int)a.size()); };
void mmx::array::sub ( V &  r,
const V &  a,
const V &  b 
)

Specialisation of the @ function when =V@. Inplace substraction is used when =a@ or =b@.

Definition at line 270 of file array.hpp.

References sub(), and sub_g().

  {
    if(&r==&a) { sub(r,b); return; };
    //    if(&r==&b) { sub(r,a); mul_ext(r,-1); return; };
    sub_g(r,a,b);
  }
void mmx::array::sub ( V &  r,
const W &  a,
const X &  b 
)

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

Definition at line 262 of file array.hpp.

References sub_g().

  {
    sub_g(r,a,b);
  }
void mmx::array::sub ( V &  a,
const W &  b 
)

Substraction of two vectors.

Definition at line 222 of file array.hpp.

References neg_range(), and sub_n().

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

  {
    int asz, bsz;
    asz = a.size(), bsz = b.size();
    if ( asz < bsz  ) 
      { 
        a.resize(bsz);
        sub_n(a,b,asz);
        neg_range(a,b,asz,bsz); 
      }
    else  
      sub_n(a,b,bsz);
  }
void mmx::array::sub_g ( V &  r,
const W &  a,
const X &  b 
)

Definition at line 241 of file array.hpp.

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

Referenced by sub().

  { 
    int asz, bsz, rsz;
    asz = a.size(), bsz = b.size(), rsz = r.size();
    
    if ( asz > bsz ) 
      {
        if ( asz > rsz ) r.resize(asz);
        sub_n(r,a,b,bsz);
        copy_range(r,a,bsz,asz);
      }
    else
      { 
        if ( bsz > rsz ) r.resize(bsz);
        sub_n(r,a,b,asz);
        neg_range(r,b,asz,bsz);
      };
  }
void mmx::array::sub_n ( V &  a,
const W &  b,
const X &  c,
int  n 
) [inline]

Definition at line 237 of file array.hpp.

{ 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 
)

Definition at line 217 of file array.hpp.

Referenced by sub(), and sub_g().

{ for ( int i = 0; i < n; a[i] -= b[i], i ++ ){} };
void mmx::array::vaddsc ( R &  r,
const C &  x 
) [inline]

Definition at line 433 of file array.hpp.

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