ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
f5arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 #include "admb_messages.h"
00013 
00018  void dvar5_array::initialize(void)
00019  {
00020    int mmin=indexmin();
00021    int mmax=indexmax();
00022    for (int i=mmin; i<=mmax; i++)
00023    {
00024      (*this)(i).initialize();
00025    }
00026  }
00027 
00032  dvar5_array dvar5_array::sub(int nrl,int nrh)
00033  {
00034    if (allocated(*this))
00035    {
00036      dvar5_array tmp(nrl,nrh);
00037      for (int i=nrl; i<=nrh; i++)
00038      {
00039        tmp[i].shallow_copy((*this)(i));
00040      }
00041      return tmp;
00042    }
00043    else
00044    {
00045      return *this;
00046    }
00047  }
00048 
00053  dvar5_array::dvar5_array(const dvar5_array& _m2)
00054  {
00055    dvar5_array& m2=(dvar5_array&) _m2;
00056    if (m2.shape)
00057    {
00058      shape=m2.shape;
00059      (shape->ncopies)++;
00060      t = m2.t;
00061    }
00062    else
00063    {
00064      shape=NULL;
00065      t=NULL;
00066    }
00067  }
00068 
00073  dvar5_array::dvar5_array(const d5_array& _m2)
00074  {
00075    d5_array& m2=(d5_array&) _m2;
00076    allocate(m2);
00077    (*this)=m2;
00078  }
00079 
00084  void dvar5_array::deallocate()
00085  {
00086    if (shape)
00087    {
00088      if (shape->ncopies)
00089      {
00090        (shape->ncopies)--;
00091      }
00092      else
00093      {
00094        t += indexmin();
00095        delete [] t;
00096        t=NULL;
00097        delete shape;
00098        shape=NULL;
00099      }
00100    }
00101 #if defined(SAFE_ALL)
00102    else
00103    {
00104      cerr << "Warning -- trying to deallocate an unallocated dvar4_array"<<endl;
00105    }
00106 #endif
00107  }
00108 
00113  dvar5_array::~dvar5_array()
00114  {
00115    deallocate();
00116  }
00117 
00122  dvar5_array& dvar5_array::operator=(const dvar5_array& m)
00123  {
00124    int mmin=indexmin();
00125    int mmax=indexmax();
00126    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00127    {
00128      cerr << "Incompatible bounds in"
00129       " dvar4_array& dvar4_array:: operator=(const dvar4_array& m)"
00130       << endl;
00131      ad_exit(1);
00132     }
00133    for (int i=mmin; i<=mmax; i++)
00134    {
00135      (*this)(i)=m(i);
00136    }
00137    return *this;
00138  }
00139 
00144 dvar5_array& dvar5_array::operator=(const d5_array& m)
00145  {
00146    int mmin=indexmin();
00147    int mmax=indexmax();
00148    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00149    {
00150      cerr << "Incompatible bounds in"
00151       " dvar4_array& dvar4_array:: operator =  (const dvar4_array& m)"
00152       << endl;
00153      ad_exit(1);
00154     }
00155    for (int i=mmin; i<=mmax; i++)
00156    {
00157      (*this)(i)=m(i);
00158    }
00159    return *this;
00160  }
00161 
00166 void dvar5_array::allocate(const dvar5_array& m1)
00167  {
00168    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00169        == 0)
00170    {
00171      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00172    }
00173    int ss=size();
00174    if ( (t = new dvar4_array[ss]) == 0)
00175    {
00176      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00177      ad_exit(21);
00178    }
00179    t -= indexmin();
00180    for (int i=indexmin(); i<=indexmax(); i++)
00181    {
00182      t[i].allocate(m1[i]);
00183    }
00184  }
00185 
00190 void dvar5_array::allocate(const d5_array& m1)
00191  {
00192    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00193        == 0)
00194    {
00195      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00196    }
00197    int ss=size();
00198    if ( (t = new dvar4_array[ss]) == 0)
00199    {
00200      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00201      ad_exit(21);
00202    }
00203    t -= indexmin();
00204    for (int i=indexmin(); i<=indexmax(); i++)
00205    {
00206      t[i].allocate(m1[i]);
00207    }
00208  }
00209 
00210   #ifndef OPT_LIB
00211 
00216     dvar4_array& dvar5_array::operator ( ) (int i)
00217     {
00218       if (i < indexmin() || i > indexmax())
00219       {
00220        ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00221        "dvar3_array& dvar5_array::operator () (int i)",
00222        indexmin(), indexmax(), i);
00223       }
00224       return t[i];
00225     }
00226 
00231     dvar4_array& dvar5_array::operator [] (int i)
00232     {
00233       if (i < indexmin() || i > indexmax())
00234       {
00235        ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00236        "dvar3_array& dvar5_array::operator [] (int i)",
00237        indexmin(), indexmax(), i);
00238       }
00239       return t[i];
00240     }
00241 
00246     dvar3_array& dvar5_array::operator ( ) (int i ,int j)
00247     {
00248       if (i < indexmin() || i > indexmax())
00249       {
00250        ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00251        "dvar3_array& dvar5_array::operator ( ) (int i,int j)",
00252        indexmin(), indexmax(), i);
00253       }
00254       return elem(i)(j);
00255     }
00256 
00261     dvar_matrix& dvar5_array::operator ( ) (int i,int j,int k)
00262     {
00263       if (i < indexmin() || i > indexmax())
00264       {
00265        ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00266        "dvar_matrix& dvar5_array::operator ( ) (int i,int j,int k)",
00267        indexmin(), indexmax(), i);
00268       }
00269       return elem(i)(j,k);
00270     }
00271 
00276     dvar_vector& dvar5_array::operator ( ) (int i,int j,int k,int l)
00277     {
00278       if (i < indexmin() || i > indexmax())
00279       {
00280        ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00281        "dvar_vector& dvar5_array::operator ( ) (int i,int j,int k,int l)",
00282        indexmin(), indexmax(), i);
00283       }
00284       return elem(i)(j,k,l);
00285     }
00286 
00291     prevariable dvar5_array::operator ( ) (int i,int j,int k,int l,int m)
00292     {
00293       if (i < indexmin() || i > indexmax())
00294       {
00295        ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00296        "prevariable dvar5_array::operator ( ) (int i,int j,int k,int l,int m)",
00297        indexmin(), indexmax(), i);
00298       }
00299       return elem(i)(j,k,l,m);
00300     }
00301 
00306 const dvar4_array& dvar5_array::operator()(int i) const
00307     {
00308         if (i<indexmin()||i>indexmax())
00309         { cerr << "Error  index out of bounds in\n"
00310             "dvar4_array& dvar5_array::operator ( )" << endl;
00311           ad_exit(1);
00312         }
00313       return t[i];
00314     }
00315 
00320 const dvar4_array& dvar5_array::operator[](int i) const
00321     {
00322         if (i<indexmin()||i>indexmax())
00323         { cerr << "Error  index out of bounds in\n"
00324             "dvar4_array& dvar5_array::operator []" << endl;
00325           ad_exit(1);
00326         }
00327       return t[i];
00328     }
00329 
00334 const dvar3_array& dvar5_array::operator()(int i, int j) const
00335     {
00336         if (i<indexmin()||i>indexmax())
00337         { cerr << "Error index out of bounds in\n"
00338             "dvar3_array& dvar5_array::operator ( )" << endl;
00339           ad_exit(1);
00340         }
00341       return elem(i)(j);
00342     }
00343 
00348 const dvar_matrix& dvar5_array::operator()(int i, int j, int k) const
00349     {
00350         if (i<indexmin()||i>indexmax())
00351         { cerr << "Error index out of bounds in\n"
00352             "dvar3_array& dvar5_array::operator ( )" << endl;
00353           ad_exit(1);
00354         }
00355       return elem(i)(j,k);
00356     }
00357 
00362 const dvar_vector& dvar5_array::operator()(int i, int j, int k, int l) const
00363     {
00364         if (i<indexmin()||i>indexmax())
00365         { cerr << "Error hslice index out of bounds in\n"
00366             "dvar_vector& dvar5_array::operator ( )"  << endl;
00367           ad_exit(1);
00368         }
00369       return elem(i)(j,k,l);
00370     }
00371 
00376 const prevariable dvar5_array::operator()(int i, int j, int k, int l, int m)
00377   const
00378     {
00379         if (i<indexmin()||i>indexmax())
00380         { cerr << "Error hslice index out of bounds in\n"
00381             "dvar_vector& dvar5_array::operator ( )"  << endl;
00382           ad_exit(1);
00383         }
00384       return elem(i)(j,k,l,m);
00385     }
00386 #endif
00387 
00392 dvar5_array::dvar5_array(int hsl,int hsu,int sl,int sh,int nrl,
00393    int nrh,int ncl,int nch,int l5,int u5)
00394 {
00395   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5);
00396 }
00397 
00402 dvar5_array::dvar5_array(const ad_integer& hsl,const ad_integer& hsu,
00403   const index_type& sl,const index_type& sh,const index_type& nrl,
00404   const index_type& nrh,const index_type& ncl,const index_type& nch,
00405   const index_type& l5,const index_type& u5)
00406 {
00407   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5);
00408 }
00409 
00414 void dvar5_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00415    int nrh,int ncl,int nch,int l5,int u5)
00416  {
00417    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00418    {
00419      cerr << " Error allocating memory in dvar5_array contructor\n";
00420      ad_exit(21);
00421    }
00422    int ss=size();
00423    if ( (t = new dvar4_array[ss]) == 0)
00424    {
00425      cerr << " Error allocating memory in dvar5_array contructor\n";
00426      ad_exit(21);
00427    }
00428    t -= indexmin();
00429    for (int i=hsl; i<=hsu; i++)
00430    {
00431      (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5);
00432    }
00433  }
00434 
00439  dvar5_array::dvar5_array(int hsl,int hsu)
00440  {
00441    allocate(hsl,hsu);
00442  }
00443 
00448  void dvar5_array::allocate(int hsl,int hsu)
00449  {
00450    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00451    {
00452      cerr << " Error allocating memory in dvar5_array contructor\n";
00453      ad_exit(21);
00454    }
00455    int ss=size();
00456    if ( (t = new dvar4_array[ss]) == 0)
00457    {
00458      cerr << " Error allocating memory in dvar5_array contructor\n";
00459      ad_exit(21);
00460    }
00461    t -= indexmin();
00462    for (int i=indexmin(); i<=indexmax(); i++)
00463    {
00464      t[i].allocate();
00465    }
00466  }
00467 
00472  void dvar5_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00473   const index_type& sl,const index_type& sh,const index_type& nrl,
00474    const index_type& nrh,const index_type& ncl,const index_type& nch,
00475    const index_type& l5,const index_type& u5)
00476  {
00477    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00478    {
00479      cerr << " Error allocating memory in dvar5_array contructor\n";
00480    }
00481 
00482    int ss=size();
00483    if ( (t = new dvar4_array[ss]) == 0)
00484    {
00485      cerr << " Error allocating memory in dvar5_array contructor\n";
00486      ad_exit(21);
00487    }
00488    t -= indexmin();
00489    int il=hsl;
00490    int iu=hsu;
00491    for (int i=il; i<=iu; i++)
00492    {
00493      t[i].allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00494         ncl(i),nch(i),l5(i),u5(i));
00495    }
00496  }