ADMB Documentation  11.1.1015
 All Classes Files Functions Variables Typedefs Friends Defines
f6arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f6arr.cpp 542 2012-07-10 21:04:06Z 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    else
00081    { 
00082 #    if defined(SAFE_ALL)
00083     // cerr << "Warning -- trying to deallocate an unallocated dvar4_array"<<endl;
00084 #    endif
00085    }
00086  }
00087 
00092  dvar6_array::~dvar6_array() 
00093  {
00094    deallocate();
00095  }
00096 
00101  dvar6_array& dvar6_array::operator=(const dvar6_array& m)
00102  {
00103    int mmin=indexmin();
00104    int mmax=indexmax();
00105    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00106    { 
00107      cerr << "Incompatible bounds in"
00108       " dvar4_array& dvar4_array:: operator =  (const dvar4_array& m)"
00109       << endl;
00110      ad_exit(1);
00111     }
00112    for (int i=mmin; i<=mmax; i++)
00113    {
00114      (*this)(i)=m(i);
00115    }
00116    return *this;
00117  }
00118 
00123  dvar6_array& dvar6_array::operator=(const d6_array& m)
00124  {
00125    int mmin=indexmin();
00126    int mmax=indexmax();
00127    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00128    { 
00129      cerr << "Incompatible bounds in"
00130       " dvar6_array& dvar6_array:: operator=(const d6_array& m)"
00131       << endl;
00132      ad_exit(1);
00133     }
00134    for (int i=mmin; i<=mmax; i++)
00135    {
00136      (*this)(i)=m(i);
00137    }
00138    return *this;
00139  }
00140 
00145  void dvar6_array::allocate(const dvar6_array& m1)
00146  {
00147    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00148        == 0)
00149    {
00150      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00151    }
00152    int ss=size();
00153    if ( (t = new dvar5_array[ss]) == 0)
00154    {
00155      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00156      ad_exit(21);
00157    }
00158    t -= indexmin();
00159    for (int i=indexmin(); i<=indexmax(); i++)
00160    {
00161      t[i].allocate(m1[i]);
00162    }
00163  }
00164 
00169  void dvar6_array::allocate(const d6_array& m1)
00170  {
00171    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00172        == 0)
00173    {
00174      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00175    }
00176    int ss=size();
00177    if ( (t = new dvar5_array[ss]) == 0)
00178    {
00179      cerr << " Error allocating memory in dvar5_array contructor" << endl;
00180      ad_exit(21);
00181    }
00182    t -= indexmin();
00183    for (int i=indexmin(); i<=indexmax(); i++)
00184    {
00185      t[i].allocate(m1[i]);
00186    }
00187  }
00188 
00189   #ifndef OPT_LIB
00190 
00195     dvar5_array& dvar6_array::operator ( ) (int i)
00196     {
00197       #ifdef SAFE_ARRAYS
00198       if (i < indexmin() || i > indexmax())
00199       { 
00200         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds", "dvar5_array& dvar6_array::operator()(int i)", indexmin(), indexmax(), i);
00201       }
00202       #endif
00203       return t[i];
00204     }
00205 
00210     dvar5_array& dvar6_array::operator [] (int i)
00211     {
00212       #ifdef SAFE_ARRAYS
00213       if (i < indexmin() || i > indexmax())
00214       { 
00215         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds", "dvar5_array& dvar6_array::operator[](int i)", indexmin(), indexmax(), i);
00216       }
00217       #endif
00218       return t[i];
00219     }
00220 
00225     dvar4_array& dvar6_array::operator ( ) (int i ,int j)
00226     {
00227       #ifdef SAFE_ARRAYS
00228       if (i < indexmin() || i > indexmax())
00229       { 
00230         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds", "dvar5_array& dvar6_array::operator()(int i, int j)", indexmin(), indexmax(), i);
00231       }
00232       #endif
00233       return elem(i)(j);
00234     }
00235 
00240     dvar3_array& dvar6_array::operator ( ) (int i,int j,int k)
00241     {
00242       #ifdef SAFE_ARRAYS
00243       if (i < indexmin() || i > indexmax())
00244       { 
00245         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds", "dvar5_array& dvar6_array::operator()(int i, int j, int k)", indexmin(), indexmax(), i);
00246       }
00247       #endif
00248       return elem(i)(j,k);
00249     }
00250 
00255     dvar_matrix& dvar6_array::operator ( ) (int i,int j,int k,int l)
00256     {
00257       #ifdef SAFE_ARRAYS
00258       if (i < indexmin() || i > indexmax())
00259       { 
00260         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds", "dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l)", indexmin(), indexmax(), i);
00261       }
00262       #endif
00263       return elem(i)(j,k,l);
00264     }
00265 
00270     dvar_vector& dvar6_array::operator ( ) (int i,int j,int k,int l,int m)
00271     {
00272       #ifdef SAFE_ARRAYS
00273       if (i < indexmin() || i > indexmax())
00274       { 
00275         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds", "dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m)", indexmin(), indexmax(), i);
00276       }
00277       #endif
00278       return elem(i)(j,k,l,m);
00279     }
00280 
00285     prevariable dvar6_array::operator ( ) (int i,int j,int k,int l,int m,
00286       int n)
00287     {
00288       #ifdef SAFE_ARRAYS
00289       if (i < indexmin() || i > indexmax())
00290       { 
00291         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds", "prevariable dvar6_array::operator()(int i, int j, int k, int l, int m, int n)", indexmin(), indexmax(), i);
00292       }
00293       #endif
00294       return elem(i)(j,k,l,m,n);
00295     }
00296 
00297    #ifdef USE_CONST
00298 
00303 const dvar5_array& dvar6_array::operator()(int i) const
00304     {
00305       #ifdef SAFE_ARRAYS
00306         if (i<indexmin()||i>indexmax())
00307         { cerr << "Error  index out of bounds in\n"
00308             "dvar5_array& dvar6_array::operator ( )" << endl;
00309           ad_exit(1);
00310         }
00311       #endif
00312       return t[i];
00313     }
00314 
00319 const dvar5_array& dvar6_array::operator[](int i) const
00320     {
00321       #ifdef SAFE_ARRAYS
00322         if (i<indexmin()||i>indexmax())
00323         { cerr << "Error  index out of bounds in\n"
00324             "dvar5_array& dvar6_array::operator []" << endl;
00325           ad_exit(1);
00326         }
00327       #endif
00328       return t[i];
00329     }
00330 
00335 const dvar4_array& dvar6_array::operator()(int i ,int j) const
00336     {
00337       #ifdef SAFE_ARRAYS
00338         if (i<indexmin()||i>indexmax())
00339         { cerr << "Error hslice index out of bounds in\n"
00340             "dvar_matrix& dvar6_array::operator ( )" << endl;
00341           ad_exit(1);
00342         }
00343       #endif
00344       return elem(i)(j);
00345     }
00346 
00351 const dvar3_array& dvar6_array::operator()(int i, int j, int k) const
00352     {
00353       #ifdef SAFE_ARRAYS
00354         if (i<indexmin()||i>indexmax())
00355         { cerr << "Error hslice index out of bounds in\n"
00356       "dvar_vector& dvar4_array::operator ( )" << endl;
00357           ad_exit(1);
00358         }
00359       #endif
00360       return elem(i)(j,k);
00361     }
00362 
00367 const dvar_matrix& dvar6_array::operator()(int i, int j, int k, int l) const
00368     {
00369       #ifdef SAFE_ARRAYS
00370         if (i<indexmin()||i>indexmax())
00371         { cerr << "Error hslice index out of bounds in\n"
00372             "dvar-vector& dvar4_array::operator ( )"  << endl;
00373           ad_exit(1);
00374         }
00375       #endif
00376       return elem(i)(j,k,l);
00377     }
00378 
00383 const dvar_vector& dvar6_array::operator()(int i, int j, int k, int l, int m) const
00384     {
00385       #ifdef SAFE_ARRAYS
00386         if (i<indexmin()||i>indexmax())
00387         { cerr << "Error hslice index out of bounds in\n"
00388             "prevariable& dvar4_array::operator ( )"  << endl;
00389           ad_exit(1);
00390         }
00391       #endif
00392       return elem(i)(j,k,l,m);
00393     }
00394 
00399 const prevariable dvar6_array::operator()(int i, int j, int k, int l, int m, int n) const
00400     {
00401       #ifdef SAFE_ARRAYS
00402         if (i<indexmin()||i>indexmax())
00403         { cerr << "Error hslice index out of bounds in\n"
00404             "prevariable& dvar4_array::operator ( )"  << endl;
00405           ad_exit(1);
00406         }
00407       #endif
00408       return elem(i)(j,k,l,m,n);
00409     }
00410 
00411 
00412    #endif
00413   #endif
00414 
00419 dvar6_array::dvar6_array(int hsl,int hsu)
00420 {
00421   allocate(hsl,hsu);
00422 }
00423 
00424 
00429 dvar6_array::dvar6_array(int hsl,int hsu,int sl,int sh,int nrl,
00430    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00431 {
00432   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00433 }
00434 
00439 dvar6_array::dvar6_array(const ad_integer& hsl,const ad_integer& hsu,
00440   const index_type& sl,const index_type& sh,const index_type& nrl,
00441   const index_type& nrh,const index_type& ncl,const index_type& nch,
00442   const index_type& l5,const index_type& u5,
00443   const index_type& l6,const index_type& u6)
00444 {
00445   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00446 }
00447 
00452 void dvar6_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00453    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00454  {
00455    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00456    {
00457      cerr << " Error allocating memory in dvar5_array contructor\n";
00458      ad_exit(21);
00459    }
00460    int ss=size();
00461    if ( (t = new dvar5_array[ss]) == 0)
00462    {
00463      cerr << " Error allocating memory in dvar5_array contructor\n";
00464      ad_exit(21);
00465    }
00466    t -= indexmin();
00467    for (int i=hsl; i<=hsu; i++)
00468    {
00469      (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00470    }
00471  }
00472 
00477  void dvar6_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00478   const index_type& sl,const index_type& sh,const index_type& nrl,
00479    const index_type& nrh,const index_type& ncl,const index_type& nch,
00480    const index_type& l5,const index_type& u5,
00481    const index_type& l6,const index_type& u6)
00482  {
00483    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00484    {
00485      cerr << " Error allocating memory in dvar5_array contructor\n";
00486    }
00487 
00488    int ss=size();
00489    if ( (t = new dvar5_array[ss]) == 0)
00490    {
00491      cerr << " Error allocating memory in dvar5_array contructor\n";
00492      ad_exit(21);
00493    }
00494    t -= indexmin();
00495    int il=hsl;
00496    int iu=hsu;
00497    for (int i=il; i<=iu; i++)
00498    {
00499      t[i].allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00500         ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
00501    }
00502  }
00503 
00508  void dvar6_array::allocate(int hsl,int hsu)
00509  {
00510    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00511    {
00512      cerr << " Error allocating memory in dvar5_array contructor\n";
00513    }
00514 
00515    int ss=size();
00516    if ( (t = new dvar5_array[ss]) == 0)
00517    {
00518      cerr << " Error allocating memory in dvar5_array contructor\n";
00519      ad_exit(21);
00520    }
00521    t -= indexmin();
00522    int il=hsl;
00523    int iu=hsu;
00524    for (int i=il; i<=iu; i++)
00525    {
00526      t[i].allocate();
00527    }
00528  }