ADMB Documentation  11.1.2503
 All Classes Files Functions Variables Typedefs Friends Defines
f6arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f6arr.cpp 1940 2014-04-28 21:08:34Z johnoel $
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 dvar6_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  dvar6_array::dvar6_array(const dvar6_array& _m2)
00033  {
00034    dvar6_array& m2=(dvar6_array&) _m2;
00035    if (m2.shape)
00036    {
00037      shape=m2.shape;
00038      (shape->ncopies)++;
00039      t = m2.t;
00040    }
00041    else
00042    {
00043      shape=NULL;
00044      t=NULL;
00045    }
00046  }
00047 
00052  dvar6_array::dvar6_array(const d6_array& _m2)
00053  {
00054    d6_array& m2=(d6_array&) _m2;
00055    allocate(m2);
00056    (*this)=m2;
00057  }
00058 
00063  void dvar6_array::deallocate()
00064  {
00065    if (shape)
00066    {
00067      if (shape->ncopies)
00068      {
00069        (shape->ncopies)--;
00070      }
00071      else
00072      {
00073        t += indexmin();
00074        delete [] t;
00075        t=NULL;
00076        delete shape;
00077        shape=NULL;
00078      }
00079    }
00080 #if defined(SAFE_ALL)
00081    else
00082    {
00083      cerr << "Warning -- trying to deallocate an unallocated dvar4_array"<<endl;
00084    }
00085 #endif
00086  }
00087 
00091 dvar6_array::~dvar6_array()
00092 {
00093   deallocate();
00094 }
00095 
00100  dvar6_array& dvar6_array::operator=(const dvar6_array& m)
00101  {
00102    int mmin=indexmin();
00103    int mmax=indexmax();
00104    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00105    {
00106      cerr << "Incompatible bounds in"
00107       " dvar4_array& dvar4_array:: operator =  (const dvar4_array& m)"
00108       << endl;
00109      ad_exit(1);
00110     }
00111    for (int i=mmin; i<=mmax; i++)
00112    {
00113      (*this)(i)=m(i);
00114    }
00115    return *this;
00116  }
00117 
00122  dvar6_array& dvar6_array::operator=(const d6_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       " dvar6_array& dvar6_array:: operator=(const d6_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  void dvar6_array::allocate(const dvar6_array& m1)
00145  {
00146    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00147        == 0)
00148    {
00149      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00150    }
00151    int ss=size();
00152    if ( (t = new dvar5_array[ss]) == 0)
00153    {
00154      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00155      ad_exit(21);
00156    }
00157    t -= indexmin();
00158    for (int i=indexmin(); i<=indexmax(); i++)
00159    {
00160      t[i].allocate(m1[i]);
00161    }
00162  }
00163 
00168  void dvar6_array::allocate(const d6_array& m1)
00169  {
00170    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00171        == 0)
00172    {
00173      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00174    }
00175    int ss=size();
00176    if ( (t = new dvar5_array[ss]) == 0)
00177    {
00178      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00179      ad_exit(21);
00180    }
00181    t -= indexmin();
00182    for (int i=indexmin(); i<=indexmax(); i++)
00183    {
00184      t[i].allocate(m1[i]);
00185    }
00186  }
00187 
00188   #ifndef OPT_LIB
00189 
00194     dvar5_array& dvar6_array::operator ( ) (int i)
00195     {
00196       if (i < indexmin() || i > indexmax())
00197       {
00198         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00199         "dvar5_array& dvar6_array::operator()(int i)",
00200         indexmin(), indexmax(), i);
00201       }
00202       return t[i];
00203     }
00204 
00209     dvar5_array& dvar6_array::operator [] (int i)
00210     {
00211       if (i < indexmin() || i > indexmax())
00212       {
00213         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00214         "dvar5_array& dvar6_array::operator[](int i)",
00215         indexmin(), indexmax(), i);
00216       }
00217       return t[i];
00218     }
00219 
00224     dvar4_array& dvar6_array::operator ( ) (int i ,int j)
00225     {
00226       if (i < indexmin() || i > indexmax())
00227       {
00228         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00229         "dvar5_array& dvar6_array::operator()(int i, int j)",
00230         indexmin(), indexmax(), i);
00231       }
00232       return elem(i)(j);
00233     }
00234 
00239     dvar3_array& dvar6_array::operator ( ) (int i,int j,int k)
00240     {
00241       if (i < indexmin() || i > indexmax())
00242       {
00243         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00244         "dvar5_array& dvar6_array::operator()(int i, int j, int k)",
00245         indexmin(), indexmax(), i);
00246       }
00247       return elem(i)(j,k);
00248     }
00249 
00254     dvar_matrix& dvar6_array::operator ( ) (int i,int j,int k,int l)
00255     {
00256       if (i < indexmin() || i > indexmax())
00257       {
00258         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00259         "dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l)",
00260         indexmin(), indexmax(), i);
00261       }
00262       return elem(i)(j,k,l);
00263     }
00264 
00269     dvar_vector& dvar6_array::operator ( ) (int i,int j,int k,int l,int m)
00270     {
00271       if (i < indexmin() || i > indexmax())
00272       {
00273         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00274       "dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)",
00275         indexmin(), indexmax(), i);
00276       }
00277       return elem(i)(j,k,l,m);
00278     }
00279 
00284     prevariable dvar6_array::operator ( ) (int i,int j,int k,int l,int m,
00285       int n)
00286     {
00287       if (i < indexmin() || i > indexmax())
00288       {
00289         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00290 "prevariable dvar6_array::operator()(int i, int j, int k, int l, int m, int n)",
00291         indexmin(), indexmax(), i);
00292       }
00293       return elem(i)(j,k,l,m,n);
00294     }
00295 
00300 const dvar5_array& dvar6_array::operator()(int i) const
00301     {
00302         if (i<indexmin()||i>indexmax())
00303         { cerr << "Error  index out of bounds in\n"
00304             "dvar5_array& dvar6_array::operator ( )" << endl;
00305           ad_exit(1);
00306         }
00307       return t[i];
00308     }
00309 
00314 const dvar5_array& dvar6_array::operator[](int i) const
00315     {
00316         if (i<indexmin()||i>indexmax())
00317         { cerr << "Error  index out of bounds in\n"
00318             "dvar5_array& dvar6_array::operator []" << endl;
00319           ad_exit(1);
00320         }
00321       return t[i];
00322     }
00323 
00328 const dvar4_array& dvar6_array::operator()(int i ,int j) const
00329     {
00330         if (i<indexmin()||i>indexmax())
00331         { cerr << "Error hslice index out of bounds in\n"
00332             "dvar_matrix& dvar6_array::operator ( )" << endl;
00333           ad_exit(1);
00334         }
00335       return elem(i)(j);
00336     }
00337 
00342 const dvar3_array& dvar6_array::operator()(int i, int j, int k) const
00343     {
00344         if (i<indexmin()||i>indexmax())
00345         { cerr << "Error hslice index out of bounds in\n"
00346           "dvar_vector& dvar4_array::operator ( )" << endl;
00347           ad_exit(1);
00348         }
00349       return elem(i)(j,k);
00350     }
00351 
00356 const dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l) const
00357     {
00358         if (i<indexmin()||i>indexmax())
00359         { cerr << "Error hslice index out of bounds in\n"
00360             "dvar-vector& dvar4_array::operator ( )"  << endl;
00361           ad_exit(1);
00362         }
00363       return elem(i)(j,k,l);
00364     }
00365 
00370 const dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)
00371   const
00372     {
00373         if (i<indexmin()||i>indexmax())
00374         { cerr << "Error hslice index out of bounds in\n"
00375             "prevariable& dvar4_array::operator ( )"  << endl;
00376           ad_exit(1);
00377         }
00378       return elem(i)(j,k,l,m);
00379     }
00380 
00385 const prevariable dvar6_array::operator()(int i, int j, int k, int l, int m,
00386   int n) const
00387     {
00388         if (i<indexmin()||i>indexmax())
00389         { cerr << "Error hslice index out of bounds in\n"
00390             "prevariable& dvar4_array::operator ( )"  << endl;
00391           ad_exit(1);
00392         }
00393       return elem(i)(j,k,l,m,n);
00394     }
00395 #endif
00396 
00401 dvar6_array::dvar6_array(int hsl,int hsu)
00402 {
00403   allocate(hsl,hsu);
00404 }
00405 
00406 
00411 dvar6_array::dvar6_array(int hsl,int hsu,int sl,int sh,int nrl,
00412    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00413 {
00414   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00415 }
00416 
00421 dvar6_array::dvar6_array(const ad_integer& hsl,const ad_integer& hsu,
00422   const index_type& sl,const index_type& sh,const index_type& nrl,
00423   const index_type& nrh,const index_type& ncl,const index_type& nch,
00424   const index_type& l5,const index_type& u5,
00425   const index_type& l6,const index_type& u6)
00426 {
00427   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00428 }
00429 
00434 void dvar6_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00435    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00436  {
00437    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00438    {
00439      cerr << " Error allocating memory in dvar5_array contructor\n";
00440      ad_exit(21);
00441    }
00442    int ss=size();
00443    if ( (t = new dvar5_array[ss]) == 0)
00444    {
00445      cerr << " Error allocating memory in dvar5_array contructor\n";
00446      ad_exit(21);
00447    }
00448    t -= indexmin();
00449    for (int i=hsl; i<=hsu; i++)
00450    {
00451      (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00452    }
00453  }
00454 
00459  void dvar6_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00460   const index_type& sl,const index_type& sh,const index_type& nrl,
00461    const index_type& nrh,const index_type& ncl,const index_type& nch,
00462    const index_type& l5,const index_type& u5,
00463    const index_type& l6,const index_type& u6)
00464  {
00465    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00466    {
00467      cerr << " Error allocating memory in dvar5_array contructor\n";
00468    }
00469 
00470    int ss=size();
00471    if ( (t = new dvar5_array[ss]) == 0)
00472    {
00473      cerr << " Error allocating memory in dvar5_array contructor\n";
00474      ad_exit(21);
00475    }
00476    t -= indexmin();
00477    int il=hsl;
00478    int iu=hsu;
00479    for (int i=il; i<=iu; i++)
00480    {
00481      t[i].allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00482         ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
00483    }
00484  }
00485 
00490  void dvar6_array::allocate(int hsl,int hsu)
00491  {
00492    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00493    {
00494      cerr << " Error allocating memory in dvar5_array contructor\n";
00495    }
00496 
00497    int ss=size();
00498    if ( (t = new dvar5_array[ss]) == 0)
00499    {
00500      cerr << " Error allocating memory in dvar5_array contructor\n";
00501      ad_exit(21);
00502    }
00503    t -= indexmin();
00504    int il=hsl;
00505    int iu=hsu;
00506    for (int i=il; i<=iu; i++)
00507    {
00508      t[i].allocate();
00509    }
00510  }