ADMB Documentation  11.1.1920
 All Classes Files Functions Variables Typedefs Friends Defines
d7arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: d7arr.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 <d5arr.hpp>
00013 #include "admb_messages.h"
00014 
00019  void d7_array::initialize(void)
00020  {
00021    int mmin=indexmin();
00022    int mmax=indexmax();
00023    for (int i=mmin; i<=mmax; i++)
00024    {
00025      (*this)(i).initialize();
00026    }
00027  }
00028 
00033  d7_array::d7_array(d7_array& m2)
00034  {
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  void d7_array::deallocate()
00053  {
00054    if (shape)
00055    {
00056      if (shape->ncopies)
00057      {
00058        (shape->ncopies)--;
00059      }
00060      else
00061      {
00062        t += indexmin();
00063        delete [] t;
00064        t=NULL;
00065        delete shape;
00066        shape=NULL;
00067      }
00068    }
00069 #if defined(ADWARN_DEV)
00070    else
00071    {
00072      cerr << "Warning -- trying to deallocate an unallocated d5_array"<<endl;
00073    }
00074 #endif
00075  }
00079 d7_array::~d7_array()
00080 {
00081   deallocate();
00082 }
00087 d7_array& d7_array::operator=(const d7_array& m)
00088  {
00089    int mmin=indexmin();
00090    int mmax=indexmax();
00091    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00092    {
00093      cerr << "Incompatible bounds in"
00094       " d7_array& d7_array:: operator =  (const d7_array& m)"
00095       << endl;
00096      ad_exit(1);
00097     }
00098    for (int i=mmin; i<=mmax; i++)
00099    {
00100      (*this)(i)=m(i);
00101    }
00102    return *this;
00103  }
00104 
00109 void d7_array::allocate(const d7_array& m1)
00110  {
00111    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00112        == 0)
00113    {
00114      cerr << " Error allocating memory in d6_array contructor" << endl;
00115    }
00116    int ss=size();
00117    if ( (t = new d6_array[ss]) == 0)
00118    {
00119      cerr << " Error allocating memory in d6_array contructor" << endl;
00120      ad_exit(21);
00121    }
00122    t -= indexmin();
00123    for (int i=indexmin(); i<=indexmax(); i++)
00124    {
00125      t[i].allocate(m1[i]);
00126    }
00127  }
00128 
00129   #ifndef OPT_LIB
00130 
00135     d6_array& d7_array::operator ( ) (int i)
00136     {
00137       #ifdef SAFE_ARRAYS
00138       if (i < indexmin() || i > indexmax())
00139       {
00140         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00141         "d6_array& d7_array::operator()(int i)", indexmin(), indexmax(), i);
00142       }
00143       #endif
00144       //return t[i];
00145       return elem(i);
00146     }
00147 
00152     d6_array& d7_array::operator [] (int i)
00153     {
00154       #ifdef SAFE_ARRAYS
00155       if (i < indexmin() || i > indexmax())
00156       {
00157         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00158         "d6_array& d7_array::operator[](int i)", indexmin(), indexmax(), i);
00159       }
00160       #endif
00161       return t[i];
00162     }
00163 
00168     d5_array& d7_array::operator ( ) (int i ,int j)
00169     {
00170       #ifdef SAFE_ARRAYS
00171       if (i < indexmin() || i > indexmax())
00172       {
00173         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00174         "d5_array& d7_array::operator()(int i, int j)",
00175         indexmin(), indexmax(), i);
00176       }
00177       #endif
00178       return elem(i)(j);
00179     }
00180 
00185     d4_array& d7_array::operator ( ) (int i,int j,int k)
00186     {
00187       #ifdef SAFE_ARRAYS
00188       if (i < indexmin() || i > indexmax())
00189       {
00190         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00191         "d4_array& d7_array::operator()(int i, int j, int k)",
00192         indexmin(), indexmax(), i);
00193       }
00194       #endif
00195       return elem(i)(j,k);
00196     }
00197 
00202     d3_array& d7_array::operator ( ) (int i,int j,int k,int l)
00203     {
00204       #ifdef SAFE_ARRAYS
00205       if (i < indexmin() || i > indexmax())
00206       {
00207         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00208         "d3_array& d7_array::operator()(int i, int j, int k, int l)",
00209         indexmin(), indexmax(), i);
00210       }
00211       #endif
00212       return elem(i)(j,k,l);
00213     }
00214 
00219     dmatrix& d7_array::operator ( ) (int i,int j,int k,int l,int m)
00220     {
00221       #ifdef SAFE_ARRAYS
00222       if (i < indexmin() || i > indexmax())
00223       {
00224         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00225         "dmatrix& d7_array::operator()(int i, int j, int k, int l, int m)",
00226         indexmin(), indexmax(), i);
00227       }
00228       #endif
00229       return elem(i)(j,k,l,m);
00230     }
00231 
00236     dvector& d7_array::operator ( ) (int i,int j,int k,int l,int m,int n)
00237     {
00238       #ifdef SAFE_ARRAYS
00239       if (i < indexmin() || i > indexmax())
00240       {
00241         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00242       "dvector& d7_array::operator()(int i, int j, int k, int l, int m, int n)",
00243          indexmin(), indexmax(), i);
00244       }
00245       #endif
00246       return elem(i)(j,k,l,m,n);
00247     }
00248 
00253     double& d7_array::operator ( ) (int i,int j,int k,int l,int m,int n,int _p)
00254     {
00255       #ifdef SAFE_ARRAYS
00256       if (i < indexmin() || i > indexmax())
00257       {
00258         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00259 "double& d7_array::operator()(int i, int j,int k,int l, int m, int n, int _p)",
00260         indexmin(), indexmax(), i);
00261       }
00262       #endif
00263       return elem(i)(j,k,l,m,n,_p);
00264     }
00265 
00270 const d6_array& d7_array::operator()(int i) const
00271     {
00272       #ifdef SAFE_ARRAYS
00273         if (i<indexmin()||i>indexmax())
00274         { cerr << "Error  index out of bounds in\n"
00275             "d6_array& d7_array::operator ( )" << endl;
00276           ad_exit(1);
00277         }
00278       #endif
00279       //return t[i];
00280       return elem(i);
00281     }
00282 
00287 const d6_array& d7_array::operator[](int i) const
00288     {
00289       #ifdef SAFE_ARRAYS
00290         if (i<indexmin()||i>indexmax())
00291         { cerr << "Error  index out of bounds in\n"
00292             "d5_array& d7_array::operator []" << endl;
00293           ad_exit(1);
00294         }
00295       #endif
00296       return t[i];
00297     }
00298 
00303 const d5_array& d7_array::operator()(int i,int j) const
00304     {
00305       #ifdef SAFE_ARRAYS
00306         if (i<indexmin()||i>indexmax())
00307         { cerr << "Error hslice index out of bounds in\n"
00308             "d3_array& d5_array::operator ( )" << endl;
00309           ad_exit(1);
00310         }
00311       #endif
00312       return elem(i)(j);
00313     }
00314 
00319 const d4_array& d7_array::operator()(int i, int j, int k) const
00320     {
00321       #ifdef SAFE_ARRAYS
00322         if (i<indexmin()||i>indexmax())
00323         { cerr << "Error hslice index out of bounds in\n"
00324           "dmatrix& d5_array::operator ( )" << endl;
00325           ad_exit(1);
00326         }
00327       #endif
00328       return elem(i)(j,k);
00329     }
00330 
00335 const d3_array& d7_array::operator()(int i, int j, int k, int l) const
00336     {
00337       #ifdef SAFE_ARRAYS
00338         if (i<indexmin()||i>indexmax())
00339         { cerr << "Error hslice index out of bounds in\n"
00340             "double& d5_array::operator ( )"  << endl;
00341           ad_exit(1);
00342         }
00343       #endif
00344       return elem(i)(j,k,l);
00345     }
00346 
00351 const dmatrix& d7_array::operator()(int i, int j, int k, int l, int m) const
00352     {
00353       #ifdef SAFE_ARRAYS
00354         if (i<indexmin()||i>indexmax())
00355         { cerr << "Error hslice index out of bounds in\n"
00356             "double& d5_array::operator ( )"  << endl;
00357           ad_exit(1);
00358         }
00359       #endif
00360       return elem(i)(j,k,l,m);
00361     }
00362 
00367 const dvector& d7_array::operator()(int i, int j, int k, int l, int m, int n)
00368   const
00369     {
00370       #ifdef SAFE_ARRAYS
00371         if (i<indexmin()||i>indexmax())
00372         { cerr << "Error hslice index out of bounds in\n"
00373             "double& d5_array::operator ( )"  << endl;
00374           ad_exit(1);
00375         }
00376       #endif
00377       return elem(i)(j,k,l,m,n);
00378     }
00379 
00384 const double& d7_array::operator()(int i, int j, int k, int l, int m, int n,
00385   int _p) const
00386     {
00387       #ifdef SAFE_ARRAYS
00388         if (i<indexmin()||i>indexmax())
00389         { cerr << "Error hslice index out of bounds in\n"
00390             "double& d5_array::operator ( )"  << endl;
00391           ad_exit(1);
00392         }
00393       #endif
00394       return elem(i)(j,k,l,m,n,_p);
00395     }
00396 #endif
00397 
00402 d7_array::d7_array(int l7,int u7,int hsl,int hsu,int sl,int sh,int nrl,
00403    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00404 {
00405   allocate(l7,u7,hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00406 }
00407 
00412 d7_array::d7_array(const ad_integer& l7,const ad_integer& u7,
00413   const index_type& hsl,const index_type& hsu,
00414   const index_type& sl,const index_type& sh,const index_type& nrl,
00415   const index_type& nrh,const index_type& ncl,const index_type& nch,
00416   const index_type& l5,const index_type& u5,
00417   const index_type& l6,const index_type& u6)
00418 {
00419   allocate(l7,u7,hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00420 }
00421 
00426 void d7_array::allocate(int l7,int u7,int hsl,int hsu,int sl,int sh,int nrl,
00427    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00428  {
00429    if ( (shape=new vector_shape(l7,u7)) == 0)
00430    {
00431      cerr << " Error allocating memory in d6_array contructor\n";
00432      ad_exit(21);
00433    }
00434    int ss=size();
00435    if ( (t = new d6_array[ss]) == 0)
00436    {
00437      cerr << " Error allocating memory in d6_array contructor\n";
00438      ad_exit(21);
00439    }
00440    t -= indexmin();
00441    for (int i=l7; i<=u7; i++)
00442    {
00443      t[i].allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00444    }
00445  }
00446 
00451 void d7_array::allocate(int l7,int u7)
00452 {
00453   if ( (shape=new vector_shape(l7,u7)) == 0)
00454   {
00455     cerr << " Error allocating memory in d6_array contructor\n";
00456     ad_exit(21);
00457   }
00458   int ss=size();
00459   if ( (t = new d6_array[ss]) == 0)
00460   {
00461     cerr << " Error allocating memory in d6_array contructor\n";
00462     ad_exit(21);
00463   }
00464   t -= indexmin();
00465   for (int i=l7; i<=u7; i++)
00466   {
00467     t[i].allocate();
00468   }
00469 }
00470 
00475  void d7_array::allocate(const ad_integer& l7,const ad_integer& u7,
00476    const index_type& hsl,const index_type& hsu,
00477    const index_type& sl,const index_type& sh,const index_type& nrl,
00478    const index_type& nrh,const index_type& ncl,const index_type& nch,
00479    const index_type& l5,const index_type& u5,
00480    const index_type& l6,const index_type& u6)
00481  {
00482    if ( (shape=new vector_shape (l7,u7)) == 0)
00483    {
00484      cerr << " Error allocating memory in d6_array contructor\n";
00485    }
00486 
00487    int ss=size();
00488    if ( (t = new d6_array[ss]) == 0)
00489    {
00490      cerr << " Error allocating memory in d6_array contructor\n";
00491      ad_exit(21);
00492    }
00493    t -= indexmin();
00494    int i1=l7;
00495    int iu=u7;
00496    for (int i=i1; i<=iu; i++)
00497    {
00498      (*this)(i).allocate(ad_integer(hsl(i)),ad_integer(hsu(i)),
00499        sl(i),sh(i),nrl(i),nrh(i),ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
00500    }
00501  }