realroot_doc 0.1.1
eenv Struct Reference

#include <tensor_eenv.hpp>

List of all members.

Public Member Functions

Static Public Member Functions

Public Attributes

Friends


Detailed Description

Definition at line 9 of file tensor_eenv.hpp.


Constructor & Destructor Documentation

eenv ( ) [inline]

constructors

Definition at line 72 of file tensor_eenv.hpp.

Referenced by eenv::common(), and eenv::eenv().

: data(0) {};
eenv ( const sparse::monomial_seq< C, O > &  mpl) [inline]

Definition at line 435 of file tensor_eenv_fcts.hpp.

References vd::d, eenv::eenv(), mmx::tensor::mescan(), vd::n, mmx::nbvar(), eenv::nvr(), eenv::szs(), and eenv::vrs().

  {
    int nvr = nbvar (mpol);
    vd lenv[nvr];
    int last = -1;
    typename sparse::monomial_seq < C, O >::const_iterator it;
    for (it = mpol.begin (); it != mpol.end (); mescan (last, lenv, *it++)) ;
    if ( last == -1 ) 
      { 
        nvr = 1; int szs = 1; 
        new (this) eenv(1,&szs,0);
        return; 
      };
    int c = last;
    nvr = 0;
    do
      {
        c = lenv[c].n;
        nvr++;
      }
    while (c != last);
    int vrs[nvr];
    int szs[nvr];
    c = last;

    int k = 0;
    do
      {
        vrs[k] = c;
        szs[k] = lenv[c].d + 1;
        c = lenv[c].n;
        lenv[vrs[k]].n = -1;
        lenv[vrs[k]].d = 0;
        k++;
      }
    while (c != last);
    new (this) eenv (nvr, szs, vrs );
  };
eenv ( int *  data)
eenv ( int  nvr_,
int const *  szs_ = 0,
int const *  vrs_ = 0,
int *  mem = 0 
) [inline]

create an allocated but uninitialized environement sizes and names given by szs_ and vrs_

Definition at line 151 of file tensor_eenv_fcts.hpp.

References eenv::construct().

    :data(new int[msz(nvr_)])
  {
    construct (nvr_, szs_, vrs_, mem);
  };
eenv ( const eenv e) [inline]

copy constructors

Definition at line 157 of file tensor_eenv_fcts.hpp.

References eenv::data.

                                   :data(e.data) { 
    //    data = e.data; 
    if ( data ) data[0]++; 
  };
~eenv ( ) [inline]

Definition at line 149 of file tensor_eenv_fcts.hpp.

References eenv::dealloc().

{ dealloc (); };

Member Function Documentation

int * alloc ( int  nvr_) [inline]

Definition at line 33 of file tensor_eenv_fcts.hpp.

References eenv::data, and eenv::msz().

Referenced by eenv::cdup(), and eenv::construct().

                                   { 
    //    return this->data = new int[msz (nvr_)]; 
    //    data = new int[eenv::msz (nvr_)]; 
    new (data)int[eenv::msz (nvr_)]; 
    return data;
  }
eenv & cdup ( ) [inline]

Definition at line 95 of file tensor_eenv_fcts.hpp.

References eenv::alloc(), eenv::copy(), eenv::data, eenv::msz(), and eenv::nvr().

Referenced by eenv::szs().

  {
    if (data[0] == 1)
      return *this;
    //    std::cout<<"cdup"<<std::endl;
    data[0]--;
    int *sv = data;
    int _sz = msz();
    data = alloc (nvr ());
    std::copy (sv, sv + _sz, data);
    return *this;
  };
eenv common ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 211 of file tensor_eenv_fcts.hpp.

References eenv::cstr(), eenv::eenv(), eenv::hasvar(), mmx::max(), eenv::mrgvrs(), eenv::nvr(), eenv::szs(), and eenv::vrs().

Referenced by mmx::tensor::add(), and mmx::tensor::sub().

  {
      if ( a == b ) return eenv(a);
    int v, lva, lvb;
    eenv oenv (mrgvrs (a, b));

    const int *ovr = oenv.vrs ();
    const int *aszs = a.szs ();
    const int *bszs = b.szs ();
    int *oszs = oenv.szs ();

    for (v = 0; v < oenv.nvr (); v++)
      {
        if (a.hasvar (lva, ovr[v]))
          {
            if (b.hasvar (lvb, ovr[v]))
              {
                oszs[v] = std::max(aszs[lva], bszs[lvb]);
              }
            else
              oszs[v] = aszs[lva];
          }
        else
          {
            if (b.hasvar (lvb, ovr[v]))
              oszs[v] = bszs[lvb];
            else
              std::cout << "erreur dans common\n";
          };
      };

    oenv.cstr ();
    return oenv;
  };
void construct ( int  nvr_,
int const *  szs_,
int const *  vrs_,
int *  mem 
) [inline]

Definition at line 40 of file tensor_eenv_fcts.hpp.

References eenv::alloc(), eenv::copy(), eenv::cstr(), eenv::data, eenv::msz(), and eenv::nvr().

Referenced by eenv::eenv().

  {
#ifdef EENV_DEBUG
    std::cout << "eenv::construct begin\n";
    std::cout <<nvr_<<" "<<mem<<" "<<msz (nvr_)<<std::endl;
#endif
    data = (mem==0)?alloc(nvr_):mem;
    data[0] = 1; 
    data[1] = nvr_;
    if (vrs_)
      {
        std::pair<int,int> tmp[ nvr_ ];
        for ( int i = 0; i < nvr_; i ++ ) { 
          tmp[i].first  = vrs_[i]; 
          tmp[i].second = szs_[i]; 
        }
        std::sort(tmp,tmp+nvr_);
        for ( int i = 0; i < nvr(); i ++ ) { 
          data[2+nvr()+i] = tmp[i].first;    // vrs()[i] = tmp[i].first; 
          data[2+i] = tmp[i].second;   // szs()[i] = tmp[i].second; 
        };
        cstr ();
      }
    else
      if (szs_)
        {
          std::copy (szs_, szs_ + nvr_, data+2); //szs();
          cstr ();
          /*gcc-bug       for (int v = 0; v < nvr (); vrs()[v] = v ++ ); */
          for (int v = 0; v < nvr () ; data[2+nvr()+v] = v, v++ ) ;
        };
  };
eenv & copy ( eenv e,
const eenv b 
) [inline, static]

Definition at line 85 of file tensor_eenv_fcts.hpp.

References eenv::data, and eenv::dealloc().

Referenced by eenv::cdup(), eenv::construct(), eenv::mrgvrs(), and eenv::operator=().

  {    
    //    std::cout<<"copy"<<std::endl;
    e.dealloc ();
    e.data = b.data;
    if (e.data)
      e.data[0]++;
    return e;
  };
void cstr ( ) [inline]

Definition at line 117 of file tensor_eenv_fcts.hpp.

References eenv::data, eenv::nvr(), and eenv::szs_data().

Referenced by eenv::common(), eenv::construct(), eenv::diff(), eenv::mul(), and eenv::rewrite().

  {
#ifdef EENV_DEBUG
    std::cout << "eenv::cstr()" << std::endl;
#endif
    int i, s = 2+2*nvr()+1;//* _st(str());
    const int *_sz(szs_data()); //data+2
    for ( i = nvr()-2, data[s+nvr()-1] = 1; i >= -1; data[s+i]=_sz[i+1]*data[s+i+1], i-- ) ;
#ifdef EENV_DEBUG
    std::cout << (*this) << std::endl;
#endif
    //    std::cout << "esz= " << _st[-1] << std::endl;
  };
void cvrs ( )
void dealloc ( ) [inline]

Definition at line 83 of file tensor_eenv_fcts.hpp.

References eenv::data.

Referenced by eenv::copy(), eenv::new_copy(), and eenv::~eenv().

{ if (data && (--data[0] == 0) ) delete[] data; };
eenv diff ( const eenv b,
int  lv 
) [inline, static]

Definition at line 270 of file tensor_eenv_fcts.hpp.

References eenv::cstr(), mmx::max(), eenv::new_copy(), and eenv::szs().

Referenced by mmx::tensor::diff().

  {
    //    const int * bszs = b.szs();
    eenv oenv; eenv::new_copy(oenv,b);
    int *oszs = oenv.szs();
    oszs[lv] = std::max (oszs[lv] - 1, 1);
    oenv.cstr ();
    return oenv;
  };
eenv elevation ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 366 of file tensor_eenv_fcts.hpp.

References eenv::hasvar(), eenv::nvr(), eenv::szs(), and eenv::vrs().

Referenced by mmx::tensor::rewrite().

  {
    int nszs[o.nvr ()];
    const int * ovrs = o.vrs();
    const int * oszs = o.szs ();
    const int * iszs = i.szs ();
    int lv;
    for (int v = 0; v < o.nvr (); v++)
      if (i.hasvar (lv, ovrs[v]))
        nszs[v] = oszs[v] - iszs[lv] + 1;
      else
        nszs[v] = oszs[v];
    eenv tmp(o.nvr (), nszs, o.vrs ());
    //    std::cout << " tmp = " << tmp << std::endl;
    return tmp;
  };
bool equal ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 74 of file tensor_eenv_fcts.hpp.

References eenv::data, and eenv::nvr().

Referenced by eenv::equiv(), eenv::operator!=(), monomials< C >::operator==(), eenv::operator==(), and mmx::tensor::realloc().

  {
        if (a.data == b.data)     return true;
        
        for (int i = 1; i < 2 + 2 * a.nvr (); i++)
            if (a.data[i] != b.data[i]) return false;
        return true;
  };
bool equiv ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 474 of file tensor_eenv_fcts.hpp.

References eenv::equal().

  {
    return equal(a,b);
  };
bool hasvar ( int &  lv,
int  gv 
) const [inline]

return true if gv is in the variable set lv is the corresponding local name.

Definition at line 131 of file tensor_eenv_fcts.hpp.

References eenv::nvr(), and eenv::vrs().

Referenced by eenv::common(), eenv::elevation(), eenv::mul(), eenv::subset(), mmx::tensor::varindex(), and eenv::vmap().

  {
    int g, d, m;
    const int * _vr = vrs();
    if ((gv < _vr[0]) || (gv > _vr[(d=nvr())-1])) return false;
    if ( gv == _vr[g = 0] ) { lv = 0; return true; };
    if ( gv == _vr[d=nvr()-1]) { lv = nvr()-1; return true;};
    do
      {
        m = (g + d) / 2;
        if ( _vr[m]  == gv ) { lv = m; return true; };
        if ( _vr[m] < gv ) g = m; else d = m;
      }
    while (d - g > 1);
    return false;
  };
int localv ( int  i) const [inline]

Definition at line 61 of file tensor_eenv.hpp.

Referenced by mmx::tensor::face(), mmx::tensor::slice(), and mmx::tensor::split().

{ return i; };
int mnvr ( ) const [inline]

Definition at line 68 of file tensor_eenv.hpp.

References eenv::vrs().

{ return vrs()[0]; };
eenv mrgvrs ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 162 of file tensor_eenv_fcts.hpp.

References eenv::copy(), eenv::nvr(), and eenv::vrs().

Referenced by eenv::common(), and eenv::mul().

  {
    
    unsigned c = 0;
    int va, vb;
    int prv = (int) (-1);
    int anvr = a.nvr ();
    int bnvr = b.nvr ();
    const int * avr = a.vrs();
    const int * bvr = b.vrs() ;
    //const eenv::vr_t * agvr = a.gvr ();
    // const eenv::vr_t * bgvr = b.gvr ();

    int tmp[anvr + bnvr];

    c = va = vb = 0;

    do
      {
        if ( avr[va] <= bvr[vb] )
          {
            if ( avr[va] != prv ) tmp[c++] = prv = avr[va];
            va++;
            continue;
          };

        if ( bvr[vb] < avr[va] )
          {
            if ( bvr[vb] != prv ) tmp[c++] = prv = bvr[vb];
            vb++;
            continue;
          };
      }
    while (va < anvr && vb < bnvr);

    if (va < anvr) for (; va < anvr; va++)
      if ( avr[va] != prv ) tmp[c++] = avr[va];
    
    if (vb < bnvr) for (; vb < bnvr; vb++)
      if ( bvr[vb] != prv ) tmp[c++] = bvr[vb];
    
    eenv oenv (c);


    std::copy(tmp,tmp+oenv.nvr(),oenv.vrs());
    return oenv;
  };
int msz ( int  nvr_) [inline, static]

Definition at line 28 of file tensor_eenv_fcts.hpp.

Referenced by eenv::new_copy().

{ return 1 + 1 + nvr_ + nvr_ + nvr_ + 1 + 2 * nvr_; };
int msz ( ) const [inline]

memory size used by the eenv representation in bytes.

Definition at line 29 of file tensor_eenv_fcts.hpp.

References eenv::nvr().

Referenced by eenv::alloc(), eenv::cdup(), and eenv::construct().

{ return eenv::msz (nvr ()); };
eenv mul ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 246 of file tensor_eenv_fcts.hpp.

References eenv::cstr(), eenv::hasvar(), eenv::mrgvrs(), eenv::nvr(), eenv::szs(), and eenv::vrs().

Referenced by mmx::tensor::conv().

  {

    int v, lva, lvb;
    eenv oenv (mrgvrs (a, b));
    //  std::cout << " mrgvrs = " << oenv << std::endl;
    int *oszs = oenv.szs ();
    const int *ovrs = oenv.vrs ();
    const int *aszs = a.szs ();
    const int *bszs = b.szs ();

    for (v = 0; v < oenv.nvr (); v++)
      {
        oszs[v] = 0;
        if (a.hasvar (lva, ovrs[v]))
          oszs[v] += aszs[lva] - 1;
        if (b.hasvar (lvb, ovrs[v]))
          oszs[v] += bszs[lvb] - 1;
        oszs[v]++;
      };
    oenv.cstr ();
    return oenv;
  };
int mxvr ( ) const [inline]

Definition at line 67 of file tensor_eenv.hpp.

References eenv::nvr(), and eenv::vrs().

Referenced by mmx::tensor::convert(), mmx::tensor::print(), and mmx::tensor::print_flatten().

{ return vrs()[nvr()-1]; };
void new_copy ( eenv e,
const eenv b 
) [inline, static]

Definition at line 108 of file tensor_eenv_fcts.hpp.

References eenv::data, eenv::dealloc(), eenv::msz(), and eenv::sz().

Referenced by eenv::diff().

  {    
    e.dealloc ();
    unsigned sz = b.msz();
    e.data = new int[sz];
    for(unsigned i=0;i<sz;i++) e.data[i]=b.data[i];
    e.data[0]=1;
  }
bool oaddress ( const eenv oenv,
unsigned *  osupp,
const eenv ienv,
unsigned *  isupp = 0,
unsigned  nsp = 0 
) [inline, static]

addresses translation from environment i to environment o

Definition at line 295 of file tensor_eenv_fcts.hpp.

References eenv::nvr(), eenv::st(), eenv::str(), eenv::sz(), and eenv::vmap().

Referenced by mmx::tensor::add(), mmx::tensor::conv(), mmx::tensor::extend(), monomials< C >::operator==(), mmx::tensor::sub(), mmx::tensor::waddm(), and mmx::tensor::wsubm().

  {
    //  std::cout << oenv << std::endl;
    //  std::cout << ienv << std::endl;
    int v;
    unsigned c;
    int vmap_[ienv.nvr ()];
    unsigned addi, addo;
    if (!vmap (vmap_, oenv, ienv))
      return false;
    if (isupp)
      for (c = 0; c < nsp; osupp[c] = addo, c++)
        for (addi = isupp[c], addo = 0, v = ienv.nvr () - 1; addi;
             addi /= ienv.sz (v), v--)
          addo += (addi % ienv.sz (v)) * oenv.st (vmap_[v]);
    else
      {
        const int *istr = ienv.str ();
        const int *ostr = oenv.str ();
        osupp[0] = 0;
        for (v = 0; v < ienv.nvr (); v++)
          for (int j = 0; j < istr[-1]; j += istr[v - 1])
            for (int i = j + istr[v]; i < j + istr[v - 1]; i += istr[v])
              osupp[i] = osupp[i - istr[v]] + ostr[vmap_[v]];
      };
    return true;
  };
bool operator!= ( const eenv a) const [inline]

Definition at line 361 of file tensor_eenv_fcts.hpp.

References eenv::equal().

  {
    return !eenv::equal (*this, e);
  };
bool operator< ( const eenv b) const [inline]

Definition at line 31 of file tensor_eenv_fcts.hpp.

References eenv::sz().

{ return sz () < b.sz (); };
eenv & operator= ( const eenv e) [inline]

Definition at line 161 of file tensor_eenv_fcts.hpp.

References eenv::copy().

{ return copy (*this, e); };
bool operator== ( const eenv a) const [inline]

Definition at line 356 of file tensor_eenv_fcts.hpp.

References eenv::equal().

  {
    return eenv::equal (*this, e);
  };
eenv rewrite ( const eenv o,
const eenv i 
) [inline, static]

Definition at line 480 of file tensor_eenv_fcts.hpp.

References eenv::cstr(), eenv::nvr(), eenv::szs(), and eenv::vmap().

  {
    int vmap_[ o.nvr() ];
    if ( ! vmap( vmap_, o, i ) ) { std::cerr << "vmap error(rewrite)\n"; exit(1); };
    eenv tmp(o);
    for ( int v = 0; v < o.nvr(); v ++ ) tmp.szs()[v] = 1;
    for ( int v = 0; v < i.nvr(); v ++ ) tmp.szs()[vmap_[v]] = i.szs()[v];
    tmp.cstr();
    return tmp;
  };
int st ( int  v) const [inline]

return the stride for variable v

Definition at line 24 of file tensor_eenv_fcts.hpp.

References eenv::str().

Referenced by mmx::tensor::m_diff(), and eenv::oaddress().

{ return str ()[v]; };
const int * str ( ) const [inline]

point to an array representing the stride for each variable

Definition at line 22 of file tensor_eenv_fcts.hpp.

References eenv::nvr(), and eenv::vrs().

{ return vrs () + nvr () + 1; };
bool subset ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 344 of file tensor_eenv_fcts.hpp.

References eenv::hasvar(), eenv::nvr(), eenv::szs(), and eenv::vrs().

Referenced by mmx::tensor::waddm(), and mmx::tensor::wsubm().

  {
    const int *avrs = a.vrs ();
    const int *aszs = a.szs ();
    const int *bszs = b.szs ();
    int lv;
    for (int i = 0; i < a.nvr (); i++)
      if ((!b.hasvar (lv, avrs[i])) || aszs[i] > bszs[lv])
        return false;
    return true;
  };
void swap ( eenv e) [inline]

Definition at line 7 of file tensor_eenv_fcts.hpp.

References eenv::data.

{ std::swap (data, e.data); };
int sz ( int  v) const [inline]

return the order for variable v

Definition at line 15 of file tensor_eenv_fcts.hpp.

References eenv::szs().

{ return szs ()[v]; };
const int * szs ( ) const [inline]

point to an array representing the order for each variable

Definition at line 11 of file tensor_eenv_fcts.hpp.

References eenv::data.

{ return data + 2; };
int * szs_data ( ) [inline]

Definition at line 13 of file tensor_eenv_fcts.hpp.

References eenv::data.

Referenced by eenv::cstr().

{ return data + 2; };
bool vmap ( int *  vmap,
const eenv o,
const eenv i 
) [inline, static]

variable names translation from environment i to environment o

Definition at line 280 of file tensor_eenv_fcts.hpp.

References eenv::hasvar(), eenv::nvr(), and eenv::vr().

Referenced by eenv::oaddress(), and eenv::rewrite().

  {
    for (int v = 0; v < i.nvr (); v++)
      {
        int lv;
        if (!o.hasvar (lv, i.vr (v)))
          {
            return false;
          };
        vmap[v] = lv;
      };
    return true;
  };
int vr ( int  lv) const [inline]

return the global id for variable lv

Definition at line 26 of file tensor_eenv_fcts.hpp.

References eenv::vrs().

Referenced by eenv::vmap().

{ return vrs ()[v]; };
int vridx ( int  i) const [inline]

Definition at line 62 of file tensor_eenv.hpp.

References eenv::nvr(), and eenv::vrs().

Referenced by mmx::tensor::restrict().

                              {
      int j; 
      for(j=0;j< nvr() && vrs()[j]!= i;j++) {}
      return j; };
const int * vrs ( ) const [inline]

point to an array representing the global id for each variable

Definition at line 19 of file tensor_eenv_fcts.hpp.

References eenv::nvr(), and eenv::szs().

{ return szs () + nvr (); };
void vswap ( int *  perm)

Referenced by mmx::tensor::vswap().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const eenv env 
) [friend]

Definition at line 325 of file tensor_eenv_fcts.hpp.

  {
    out << "*eenv*\n";
    out << "\tpos: " << env.data    << "\n";
    out << "\tref: " << env.data[0] << "\n";
    out << "\tnvr: " << env.nvr()   << "\n";
    out << "\tesz: " << env.sz ()   << "\n";
    out << "\tszs: ";
    vct::print (env.szs (), env.nvr (), 1, out);
    out << "\n";
    out << "\tvrs: ";
    vct::print (env.vrs (), env.nvr (), 1, out);
    out << "\n";
    out << "\tstr: ";
    vct::print (env.str (), env.nvr (), 1, out);
    return out;
  };

Member Data Documentation


The documentation for this struct was generated from the following files: