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().

00072 : data(0) {};

eenv ( const sparse::monomial_seq< C, O > &  mpl  )  [inline]

Definition at line 439 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().

00440   {
00441     int nvr = nbvar (mpol);
00442     vd *lenv = new vd[nvr];
00443     int last = -1;
00444     typename sparse::monomial_seq < C, O >::const_iterator it;
00445     for (it = mpol.begin (); it != mpol.end (); mescan (last, lenv, *it++)) ;
00446     if ( last == -1 ) 
00447       { 
00448         nvr = 1; int szs = 1; 
00449         new (this) eenv(1,&szs,0);
00450         return; 
00451       };
00452     int c = last;
00453     nvr = 0;
00454     do
00455       {
00456         c = lenv[c].n;
00457         nvr++;
00458       }
00459     while (c != last);
00460     int vrs[nvr];
00461     int szs[nvr];
00462     c = last;
00463 
00464     int k = 0;
00465     do
00466       {
00467         vrs[k] = c;
00468         szs[k] = lenv[c].d + 1;
00469         c = lenv[c].n;
00470         lenv[vrs[k]].n = -1;
00471         lenv[vrs[k]].d = 0;
00472         k++;
00473       }
00474     while (c != last);
00475     new (this) eenv (nvr, szs, vrs );
00476 
00477     delete lenv;
00478   };

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 155 of file tensor_eenv_fcts.hpp.

References eenv::construct().

00156     :data(new int[msz(nvr_)])
00157   {
00158     construct (nvr_, szs_, vrs_, mem);
00159   };

eenv ( const eenv e  )  [inline]

copy constructors

Definition at line 161 of file tensor_eenv_fcts.hpp.

References eenv::data.

00161                                    :data(e.data) { 
00162     //    data = e.data; 
00163     if ( data ) data[0]++; 
00164   };

~eenv (  )  [inline]

Definition at line 153 of file tensor_eenv_fcts.hpp.

References eenv::dealloc().

00153 { 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().

00033                                    { 
00034     //    return this->data = new int[msz (nvr_)]; 
00035     //    data = new int[eenv::msz (nvr_)]; 
00036     new (data)int[eenv::msz (nvr_)]; 
00037     return data;
00038   }

eenv & cdup (  )  [inline]

Definition at line 99 of file tensor_eenv_fcts.hpp.

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

Referenced by eenv::szs().

00100   {
00101     if (data[0] == 1)
00102       return *this;
00103     //    std::cout<<"cdup"<<std::endl;
00104     data[0]--;
00105     int *sv = data;
00106     int _sz = msz();
00107     data = alloc (nvr ());
00108     std::copy (sv, sv + _sz, data);
00109     return *this;
00110   };

eenv common ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 215 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().

00216   {
00217       if ( a == b ) return eenv(a);
00218     int v, lva, lvb;
00219     eenv oenv (mrgvrs (a, b));
00220 
00221     const int *ovr = oenv.vrs ();
00222     const int *aszs = a.szs ();
00223     const int *bszs = b.szs ();
00224     int *oszs = oenv.szs ();
00225 
00226     for (v = 0; v < oenv.nvr (); v++)
00227       {
00228         if (a.hasvar (lva, ovr[v]))
00229           {
00230             if (b.hasvar (lvb, ovr[v]))
00231               {
00232                 oszs[v] = std::max(aszs[lva], bszs[lvb]);
00233               }
00234             else
00235               oszs[v] = aszs[lva];
00236           }
00237         else
00238           {
00239             if (b.hasvar (lvb, ovr[v]))
00240               oszs[v] = bszs[lvb];
00241             else
00242               std::cout << "erreur dans common\n";
00243           };
00244       };
00245 
00246     oenv.cstr ();
00247     return oenv;
00248   };

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().

00042   {
00043 #ifdef EENV_DEBUG
00044     std::cout << "eenv::construct begin\n";
00045     std::cout <<nvr_<<" "<<mem<<" "<<msz (nvr_)<<std::endl;
00046 #endif
00047     data = (mem==0)?alloc(nvr_):mem;
00048     data[0] = 1; 
00049     data[1] = nvr_;
00050     if (vrs_)
00051       {
00052         std::pair<int,int> *tmp = new std::pair<int, int>[nvr_];
00053 
00054         for ( int i = 0; i < nvr_; i ++ ) { 
00055           tmp[i].first  = vrs_[i]; 
00056           tmp[i].second = szs_[i]; 
00057         }
00058 
00059         std::sort(tmp,tmp+nvr_);
00060         for ( int i = 0; i < nvr(); i ++ ) { 
00061           data[2+nvr()+i] = tmp[i].first;    // vrs()[i] = tmp[i].first; 
00062           data[2+i] = tmp[i].second;   // szs()[i] = tmp[i].second; 
00063         };
00064         cstr ();
00065 
00066         delete tmp;
00067       }
00068     else
00069       if (szs_)
00070         {
00071           std::copy (szs_, szs_ + nvr_, data+2); //szs();
00072           cstr ();
00073           /*gcc-bug       for (int v = 0; v < nvr (); vrs()[v] = v ++ ); */
00074           for (int v = 0; v < nvr () ; data[2+nvr()+v] = v, v++ ) ;
00075         };
00076   };

eenv & copy ( eenv e,
const eenv b 
) [inline, static]

Definition at line 89 of file tensor_eenv_fcts.hpp.

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

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

00090   {    
00091     //    std::cout<<"copy"<<std::endl;
00092     e.dealloc ();
00093     e.data = b.data;
00094     if (e.data)
00095       e.data[0]++;
00096     return e;
00097   };

void cstr (  )  [inline]

Definition at line 121 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().

00122   {
00123 #ifdef EENV_DEBUG
00124     std::cout << "eenv::cstr()" << std::endl;
00125 #endif
00126     int i, s = 2+2*nvr()+1;//* _st(str());
00127     const int *_sz(szs_data()); //data+2
00128     for ( i = nvr()-2, data[s+nvr()-1] = 1; i >= -1; data[s+i]=_sz[i+1]*data[s+i+1], i-- ) ;
00129 #ifdef EENV_DEBUG
00130     std::cout << (*this) << std::endl;
00131 #endif
00132     //    std::cout << "esz= " << _st[-1] << std::endl;
00133   };

void cvrs (  ) 
void dealloc (  )  [inline]

Definition at line 87 of file tensor_eenv_fcts.hpp.

References eenv::data.

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

00087 { if (data && (--data[0] == 0) ) delete[] data; };

eenv diff ( const eenv b,
int  lv 
) [inline, static]

Definition at line 274 of file tensor_eenv_fcts.hpp.

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

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

00275   {
00276     //    const int * bszs = b.szs();
00277     eenv oenv; eenv::new_copy(oenv,b);
00278     int *oszs = oenv.szs();
00279     oszs[lv] = std::max (oszs[lv] - 1, 1);
00280     oenv.cstr ();
00281     return oenv;
00282   };

eenv elevation ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 370 of file tensor_eenv_fcts.hpp.

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

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

00371   {
00372     int nszs[o.nvr ()];
00373     const int * ovrs = o.vrs();
00374     const int * oszs = o.szs ();
00375     const int * iszs = i.szs ();
00376     int lv;
00377     for (int v = 0; v < o.nvr (); v++)
00378       if (i.hasvar (lv, ovrs[v]))
00379         nszs[v] = oszs[v] - iszs[lv] + 1;
00380       else
00381         nszs[v] = oszs[v];
00382     eenv tmp(o.nvr (), nszs, o.vrs ());
00383     //    std::cout << " tmp = " << tmp << std::endl;
00384     return tmp;
00385   };

bool equal ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 78 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().

00079   {
00080         if (a.data == b.data)     return true;
00081         
00082         for (int i = 1; i < 2 + 2 * a.nvr (); i++)
00083             if (a.data[i] != b.data[i]) return false;
00084         return true;
00085   };

bool equiv ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 480 of file tensor_eenv_fcts.hpp.

References eenv::equal().

00481   {
00482     return equal(a,b);
00483   };

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 135 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().

00136   {
00137     int g, d, m;
00138     const int * _vr = vrs();
00139     if ((gv < _vr[0]) || (gv > _vr[(d=nvr())-1])) return false;
00140     if ( gv == _vr[g = 0] ) { lv = 0; return true; };
00141     if ( gv == _vr[d=nvr()-1]) { lv = nvr()-1; return true;};
00142     do
00143       {
00144         m = (g + d) / 2;
00145         if ( _vr[m]  == gv ) { lv = m; return true; };
00146         if ( _vr[m] < gv ) g = m; else d = m;
00147       }
00148     while (d - g > 1);
00149     return false;
00150   };

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().

00061 { return i; };

int mnvr (  )  const [inline]

Definition at line 68 of file tensor_eenv.hpp.

References eenv::vrs().

00068 { return vrs()[0]; };

eenv mrgvrs ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 166 of file tensor_eenv_fcts.hpp.

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

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

00167   {
00168     
00169     unsigned c = 0;
00170     int va, vb;
00171     int prv = (int) (-1);
00172     int anvr = a.nvr ();
00173     int bnvr = b.nvr ();
00174     const int * avr = a.vrs();
00175     const int * bvr = b.vrs() ;
00176     //const eenv::vr_t * agvr = a.gvr ();
00177     // const eenv::vr_t * bgvr = b.gvr ();
00178 
00179     int tmp[anvr + bnvr];
00180 
00181     c = va = vb = 0;
00182 
00183     do
00184       {
00185         if ( avr[va] <= bvr[vb] )
00186           {
00187             if ( avr[va] != prv ) tmp[c++] = prv = avr[va];
00188             va++;
00189             continue;
00190           };
00191 
00192         if ( bvr[vb] < avr[va] )
00193           {
00194             if ( bvr[vb] != prv ) tmp[c++] = prv = bvr[vb];
00195             vb++;
00196             continue;
00197           };
00198       }
00199     while (va < anvr && vb < bnvr);
00200 
00201     if (va < anvr) for (; va < anvr; va++)
00202       if ( avr[va] != prv ) tmp[c++] = avr[va];
00203     
00204     if (vb < bnvr) for (; vb < bnvr; vb++)
00205       if ( bvr[vb] != prv ) tmp[c++] = bvr[vb];
00206     
00207     eenv oenv (c);
00208 
00209 
00210     std::copy(tmp,tmp+oenv.nvr(),oenv.vrs());
00211     return oenv;
00212   };

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().

00029 { return eenv::msz (nvr ()); };

int msz ( int  nvr_  )  [inline, static]

Definition at line 28 of file tensor_eenv_fcts.hpp.

Referenced by eenv::new_copy().

00028 { return 1 + 1 + nvr_ + nvr_ + nvr_ + 1 + 2 * nvr_; };

eenv mul ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 250 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().

00251   {
00252 
00253     int v, lva, lvb;
00254     eenv oenv (mrgvrs (a, b));
00255     //  std::cout << " mrgvrs = " << oenv << std::endl;
00256     int *oszs = oenv.szs ();
00257     const int *ovrs = oenv.vrs ();
00258     const int *aszs = a.szs ();
00259     const int *bszs = b.szs ();
00260 
00261     for (v = 0; v < oenv.nvr (); v++)
00262       {
00263         oszs[v] = 0;
00264         if (a.hasvar (lva, ovrs[v]))
00265           oszs[v] += aszs[lva] - 1;
00266         if (b.hasvar (lvb, ovrs[v]))
00267           oszs[v] += bszs[lvb] - 1;
00268         oszs[v]++;
00269       };
00270     oenv.cstr ();
00271     return oenv;
00272   };

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().

00067 { return vrs()[nvr()-1]; };

void new_copy ( eenv e,
const eenv b 
) [inline, static]

Definition at line 112 of file tensor_eenv_fcts.hpp.

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

Referenced by eenv::diff().

00113   {    
00114     e.dealloc ();
00115     unsigned sz = b.msz();
00116     e.data = new int[sz];
00117     for(unsigned i=0;i<sz;i++) e.data[i]=b.data[i];
00118     e.data[0]=1;
00119   }

int nvr (  )  const [inline]
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 299 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().

00301   {
00302     //  std::cout << oenv << std::endl;
00303     //  std::cout << ienv << std::endl;
00304     int v;
00305     unsigned c;
00306     int vmap_[ienv.nvr ()];
00307     unsigned addi, addo;
00308     if (!vmap (vmap_, oenv, ienv))
00309       return false;
00310     if (isupp)
00311       for (c = 0; c < nsp; osupp[c] = addo, c++)
00312         for (addi = isupp[c], addo = 0, v = ienv.nvr () - 1; addi;
00313              addi /= ienv.sz (v), v--)
00314           addo += (addi % ienv.sz (v)) * oenv.st (vmap_[v]);
00315     else
00316       {
00317         const int *istr = ienv.str ();
00318         const int *ostr = oenv.str ();
00319         osupp[0] = 0;
00320         for (v = 0; v < ienv.nvr (); v++)
00321           for (int j = 0; j < istr[-1]; j += istr[v - 1])
00322             for (int i = j + istr[v]; i < j + istr[v - 1]; i += istr[v])
00323               osupp[i] = osupp[i - istr[v]] + ostr[vmap_[v]];
00324       };
00325     return true;
00326   };

bool operator!= ( const eenv a  )  const [inline]

Definition at line 365 of file tensor_eenv_fcts.hpp.

References eenv::equal().

00366   {
00367     return !eenv::equal (*this, e);
00368   };

bool operator< ( const eenv b  )  const [inline]

Definition at line 31 of file tensor_eenv_fcts.hpp.

References eenv::sz().

00031 { return sz () < b.sz (); };

eenv & operator= ( const eenv e  )  [inline]

Definition at line 165 of file tensor_eenv_fcts.hpp.

References eenv::copy().

00165 { return copy (*this, e); };

bool operator== ( const eenv a  )  const [inline]

Definition at line 360 of file tensor_eenv_fcts.hpp.

References eenv::equal().

00361   {
00362     return eenv::equal (*this, e);
00363   };

eenv rewrite ( const eenv o,
const eenv i 
) [inline, static]

Definition at line 486 of file tensor_eenv_fcts.hpp.

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

00487   {
00488     int vmap_[ o.nvr() ];
00489     if ( ! vmap( vmap_, o, i ) ) { std::cerr << "vmap error(rewrite)\n"; exit(1); };
00490     eenv tmp(o);
00491     for ( int v = 0; v < o.nvr(); v ++ ) tmp.szs()[v] = 1;
00492     for ( int v = 0; v < i.nvr(); v ++ ) tmp.szs()[vmap_[v]] = i.szs()[v];
00493     tmp.cstr();
00494     return tmp;
00495   };

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().

00024 { 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().

00022 { return vrs () + nvr () + 1; };

int * str (  )  [inline]
bool subset ( const eenv a,
const eenv b 
) [inline, static]

Definition at line 348 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().

00349   {
00350     const int *avrs = a.vrs ();
00351     const int *aszs = a.szs ();
00352     const int *bszs = b.szs ();
00353     int lv;
00354     for (int i = 0; i < a.nvr (); i++)
00355       if ((!b.hasvar (lv, avrs[i])) || aszs[i] > bszs[lv])
00356         return false;
00357     return true;
00358   };

void swap ( eenv e  )  [inline]

Definition at line 7 of file tensor_eenv_fcts.hpp.

References eenv::data.

00007 { 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().

00015 { return szs ()[v]; };

int sz (  )  const [inline]
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.

00011 { return data + 2; };

int * szs (  )  [inline]
int * szs_data (  )  [inline]

Definition at line 13 of file tensor_eenv_fcts.hpp.

References eenv::data.

Referenced by eenv::cstr().

00013 { 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 284 of file tensor_eenv_fcts.hpp.

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

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

00285   {
00286     for (int v = 0; v < i.nvr (); v++)
00287       {
00288         int lv;
00289         if (!o.hasvar (lv, i.vr (v)))
00290           {
00291             return false;
00292           };
00293         vmap[v] = lv;
00294       };
00295     return true;
00296   };

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().

00026 { 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().

00062                               {
00063       int j; 
00064       for(j=0;j< nvr() && vrs()[j]!= i;j++) {}
00065       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().

00019 { return szs () + nvr (); };

int * vrs (  )  [inline]
void vswap ( int *  perm  ) 

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


Friends And Related Function Documentation

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

Member Data Documentation

int* data

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

Generated on 6 Dec 2012 for realroot by  doxygen 1.6.1