ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
f6arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f6arr.cpp 1832 2014-04-03 23:24:02Z 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(ADWARN_DEV)
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       #ifdef SAFE_ARRAYS
00197       if (i < indexmin() || i > indexmax())
00198       {
00199         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00200         "dvar5_array& dvar6_array::operator()(int i)",
00201         indexmin(), indexmax(), i);
00202       }
00203       #endif
00204       return t[i];
00205     }
00206 
00211     dvar5_array& dvar6_array::operator [] (int i)
00212     {
00213       #ifdef SAFE_ARRAYS
00214       if (i < indexmin() || i > indexmax())
00215       {
00216         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00217         "dvar5_array& dvar6_array::operator[](int i)",
00218         indexmin(), indexmax(), i);
00219       }
00220       #endif
00221       return t[i];
00222     }
00223 
00228     dvar4_array& dvar6_array::operator ( ) (int i ,int j)
00229     {
00230       #ifdef SAFE_ARRAYS
00231       if (i < indexmin() || i > indexmax())
00232       {
00233         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00234         "dvar5_array& dvar6_array::operator()(int i, int j)",
00235         indexmin(), indexmax(), i);
00236       }
00237       #endif
00238       return elem(i)(j);
00239     }
00240 
00245     dvar3_array& dvar6_array::operator ( ) (int i,int j,int k)
00246     {
00247       #ifdef SAFE_ARRAYS
00248       if (i < indexmin() || i > indexmax())
00249       {
00250         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00251         "dvar5_array& dvar6_array::operator()(int i, int j, int k)",
00252         indexmin(), indexmax(), i);
00253       }
00254       #endif
00255       return elem(i)(j,k);
00256     }
00257 
00262     dvar_matrix& dvar6_array::operator ( ) (int i,int j,int k,int l)
00263     {
00264       #ifdef SAFE_ARRAYS
00265       if (i < indexmin() || i > indexmax())
00266       {
00267         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00268         "dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l)",
00269         indexmin(), indexmax(), i);
00270       }
00271       #endif
00272       return elem(i)(j,k,l);
00273     }
00274 
00279     dvar_vector& dvar6_array::operator ( ) (int i,int j,int k,int l,int m)
00280     {
00281       #ifdef SAFE_ARRAYS
00282       if (i < indexmin() || i > indexmax())
00283       {
00284         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00285       "dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)",
00286         indexmin(), indexmax(), i);
00287       }
00288       #endif
00289       return elem(i)(j,k,l,m);
00290     }
00291 
00296     prevariable dvar6_array::operator ( ) (int i,int j,int k,int l,int m,
00297       int n)
00298     {
00299       #ifdef SAFE_ARRAYS
00300       if (i < indexmin() || i > indexmax())
00301       {
00302         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00303 "prevariable dvar6_array::operator()(int i, int j, int k, int l, int m, int n)",
00304         indexmin(), indexmax(), i);
00305       }
00306       #endif
00307       return elem(i)(j,k,l,m,n);
00308     }
00309 
00314 const dvar5_array& dvar6_array::operator()(int i) const
00315     {
00316       #ifdef SAFE_ARRAYS
00317         if (i<indexmin()||i>indexmax())
00318         { cerr << "Error  index out of bounds in\n"
00319             "dvar5_array& dvar6_array::operator ( )" << endl;
00320           ad_exit(1);
00321         }
00322       #endif
00323       return t[i];
00324     }
00325 
00330 const dvar5_array& dvar6_array::operator[](int i) const
00331     {
00332       #ifdef SAFE_ARRAYS
00333         if (i<indexmin()||i>indexmax())
00334         { cerr << "Error  index out of bounds in\n"
00335             "dvar5_array& dvar6_array::operator []" << endl;
00336           ad_exit(1);
00337         }
00338       #endif
00339       return t[i];
00340     }
00341 
00346 const dvar4_array& dvar6_array::operator()(int i ,int j) const
00347     {
00348       #ifdef SAFE_ARRAYS
00349         if (i<indexmin()||i>indexmax())
00350         { cerr << "Error hslice index out of bounds in\n"
00351             "dvar_matrix& dvar6_array::operator ( )" << endl;
00352           ad_exit(1);
00353         }
00354       #endif
00355       return elem(i)(j);
00356     }
00357 
00362 const dvar3_array& dvar6_array::operator()(int i, int j, int k) const
00363     {
00364       #ifdef SAFE_ARRAYS
00365         if (i<indexmin()||i>indexmax())
00366         { cerr << "Error hslice index out of bounds in\n"
00367           "dvar_vector& dvar4_array::operator ( )" << endl;
00368           ad_exit(1);
00369         }
00370       #endif
00371       return elem(i)(j,k);
00372     }
00373 
00378 const dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l) const
00379     {
00380       #ifdef SAFE_ARRAYS
00381         if (i<indexmin()||i>indexmax())
00382         { cerr << "Error hslice index out of bounds in\n"
00383             "dvar-vector& dvar4_array::operator ( )"  << endl;
00384           ad_exit(1);
00385         }
00386       #endif
00387       return elem(i)(j,k,l);
00388     }
00389 
00394 const dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)
00395   const
00396     {
00397       #ifdef SAFE_ARRAYS
00398         if (i<indexmin()||i>indexmax())
00399         { cerr << "Error hslice index out of bounds in\n"
00400             "prevariable& dvar4_array::operator ( )"  << endl;
00401           ad_exit(1);
00402         }
00403       #endif
00404       return elem(i)(j,k,l,m);
00405     }
00406 
00411 const prevariable dvar6_array::operator()(int i, int j, int k, int l, int m,
00412   int n) const
00413     {
00414       #ifdef SAFE_ARRAYS
00415         if (i<indexmin()||i>indexmax())
00416         { cerr << "Error hslice index out of bounds in\n"
00417             "prevariable& dvar4_array::operator ( )"  << endl;
00418           ad_exit(1);
00419         }
00420       #endif
00421       return elem(i)(j,k,l,m,n);
00422     }
00423 #endif
00424 
00429 dvar6_array::dvar6_array(int hsl,int hsu)
00430 {
00431   allocate(hsl,hsu);
00432 }
00433 
00434 
00439 dvar6_array::dvar6_array(int hsl,int hsu,int sl,int sh,int nrl,
00440    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00441 {
00442   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00443 }
00444 
00449 dvar6_array::dvar6_array(const ad_integer& hsl,const ad_integer& hsu,
00450   const index_type& sl,const index_type& sh,const index_type& nrl,
00451   const index_type& nrh,const index_type& ncl,const index_type& nch,
00452   const index_type& l5,const index_type& u5,
00453   const index_type& l6,const index_type& u6)
00454 {
00455   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00456 }
00457 
00462 void dvar6_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00463    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00464  {
00465    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00466    {
00467      cerr << " Error allocating memory in dvar5_array contructor\n";
00468      ad_exit(21);
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    for (int i=hsl; i<=hsu; i++)
00478    {
00479      (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00480    }
00481  }
00482 
00487  void dvar6_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00488   const index_type& sl,const index_type& sh,const index_type& nrl,
00489    const index_type& nrh,const index_type& ncl,const index_type& nch,
00490    const index_type& l5,const index_type& u5,
00491    const index_type& l6,const index_type& u6)
00492  {
00493    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00494    {
00495      cerr << " Error allocating memory in dvar5_array contructor\n";
00496    }
00497 
00498    int ss=size();
00499    if ( (t = new dvar5_array[ss]) == 0)
00500    {
00501      cerr << " Error allocating memory in dvar5_array contructor\n";
00502      ad_exit(21);
00503    }
00504    t -= indexmin();
00505    int il=hsl;
00506    int iu=hsu;
00507    for (int i=il; i<=iu; i++)
00508    {
00509      t[i].allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00510         ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
00511    }
00512  }
00513 
00518  void dvar6_array::allocate(int hsl,int hsu)
00519  {
00520    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00521    {
00522      cerr << " Error allocating memory in dvar5_array contructor\n";
00523    }
00524 
00525    int ss=size();
00526    if ( (t = new dvar5_array[ss]) == 0)
00527    {
00528      cerr << " Error allocating memory in dvar5_array contructor\n";
00529      ad_exit(21);
00530    }
00531    t -= indexmin();
00532    int il=hsl;
00533    int iu=hsu;
00534    for (int i=il; i<=iu; i++)
00535    {
00536      t[i].allocate();
00537    }
00538  }