ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
d7arr.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 <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(SAFE_ALL)
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       if (i < indexmin() || i > indexmax())
00138       {
00139         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00140         "d6_array& d7_array::operator()(int i)", indexmin(), indexmax(), i);
00141       }
00142       //return t[i];
00143       return elem(i);
00144     }
00145 
00150     d6_array& d7_array::operator [] (int i)
00151     {
00152       if (i < indexmin() || i > indexmax())
00153       {
00154         ADMB_ARRAY_BOUNDS_ERROR("index out of bounds",
00155         "d6_array& d7_array::operator[](int i)", indexmin(), indexmax(), i);
00156       }
00157       return t[i];
00158     }
00159 
00164     d5_array& d7_array::operator ( ) (int i ,int j)
00165     {
00166       if (i < indexmin() || i > indexmax())
00167       {
00168         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00169         "d5_array& d7_array::operator()(int i, int j)",
00170         indexmin(), indexmax(), i);
00171       }
00172       return elem(i)(j);
00173     }
00174 
00179     d4_array& d7_array::operator ( ) (int i,int j,int k)
00180     {
00181       if (i < indexmin() || i > indexmax())
00182       {
00183         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00184         "d4_array& d7_array::operator()(int i, int j, int k)",
00185         indexmin(), indexmax(), i);
00186       }
00187       return elem(i)(j,k);
00188     }
00189 
00194     d3_array& d7_array::operator ( ) (int i,int j,int k,int l)
00195     {
00196       if (i < indexmin() || i > indexmax())
00197       {
00198         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00199         "d3_array& d7_array::operator()(int i, int j, int k, int l)",
00200         indexmin(), indexmax(), i);
00201       }
00202       return elem(i)(j,k,l);
00203     }
00204 
00209     dmatrix& d7_array::operator ( ) (int i,int j,int k,int l,int m)
00210     {
00211       if (i < indexmin() || i > indexmax())
00212       {
00213         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00214         "dmatrix& d7_array::operator()(int i, int j, int k, int l, int m)",
00215         indexmin(), indexmax(), i);
00216       }
00217       return elem(i)(j,k,l,m);
00218     }
00219 
00224     dvector& d7_array::operator ( ) (int i,int j,int k,int l,int m,int n)
00225     {
00226       if (i < indexmin() || i > indexmax())
00227       {
00228         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00229       "dvector& d7_array::operator()(int i, int j, int k, int l, int m, int n)",
00230          indexmin(), indexmax(), i);
00231       }
00232       return elem(i)(j,k,l,m,n);
00233     }
00234 
00239     double& d7_array::operator ( ) (int i,int j,int k,int l,int m,int n,int _p)
00240     {
00241       if (i < indexmin() || i > indexmax())
00242       {
00243         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00244 "double& d7_array::operator()(int i, int j,int k,int l, int m, int n, int _p)",
00245         indexmin(), indexmax(), i);
00246       }
00247       return elem(i)(j,k,l,m,n,_p);
00248     }
00249 
00254 const d6_array& d7_array::operator()(int i) const
00255     {
00256         if (i<indexmin()||i>indexmax())
00257         { cerr << "Error  index out of bounds in\n"
00258             "d6_array& d7_array::operator ( )" << endl;
00259           ad_exit(1);
00260         }
00261       //return t[i];
00262       return elem(i);
00263     }
00264 
00269 const d6_array& d7_array::operator[](int i) const
00270     {
00271         if (i<indexmin()||i>indexmax())
00272         { cerr << "Error  index out of bounds in\n"
00273             "d5_array& d7_array::operator []" << endl;
00274           ad_exit(1);
00275         }
00276       return t[i];
00277     }
00278 
00283 const d5_array& d7_array::operator()(int i,int j) const
00284     {
00285         if (i<indexmin()||i>indexmax())
00286         { cerr << "Error hslice index out of bounds in\n"
00287             "d3_array& d5_array::operator ( )" << endl;
00288           ad_exit(1);
00289         }
00290       return elem(i)(j);
00291     }
00292 
00297 const d4_array& d7_array::operator()(int i, int j, int k) const
00298     {
00299         if (i<indexmin()||i>indexmax())
00300         { cerr << "Error hslice index out of bounds in\n"
00301           "dmatrix& d5_array::operator ( )" << endl;
00302           ad_exit(1);
00303         }
00304       return elem(i)(j,k);
00305     }
00306 
00311 const d3_array& d7_array::operator()(int i, int j, int k, int l) const
00312     {
00313         if (i<indexmin()||i>indexmax())
00314         { cerr << "Error hslice index out of bounds in\n"
00315             "double& d5_array::operator ( )"  << endl;
00316           ad_exit(1);
00317         }
00318       return elem(i)(j,k,l);
00319     }
00320 
00325 const dmatrix& d7_array::operator()(int i, int j, int k, int l, int m) const
00326     {
00327         if (i<indexmin()||i>indexmax())
00328         { cerr << "Error hslice index out of bounds in\n"
00329             "double& d5_array::operator ( )"  << endl;
00330           ad_exit(1);
00331         }
00332       return elem(i)(j,k,l,m);
00333     }
00334 
00339 const dvector& d7_array::operator()(int i, int j, int k, int l, int m, int n)
00340   const
00341     {
00342         if (i<indexmin()||i>indexmax())
00343         { cerr << "Error hslice index out of bounds in\n"
00344             "double& d5_array::operator ( )"  << endl;
00345           ad_exit(1);
00346         }
00347       return elem(i)(j,k,l,m,n);
00348     }
00349 
00354 const double& d7_array::operator()(int i, int j, int k, int l, int m, int n,
00355   int _p) const
00356     {
00357         if (i<indexmin()||i>indexmax())
00358         { cerr << "Error hslice index out of bounds in\n"
00359             "double& d5_array::operator ( )"  << endl;
00360           ad_exit(1);
00361         }
00362       return elem(i)(j,k,l,m,n,_p);
00363     }
00364 #endif
00365 
00370 d7_array::d7_array(int l7,int u7,int hsl,int hsu,int sl,int sh,int nrl,
00371    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00372 {
00373   allocate(l7,u7,hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00374 }
00375 
00380 d7_array::d7_array(const ad_integer& l7,const ad_integer& u7,
00381   const index_type& hsl,const index_type& hsu,
00382   const index_type& sl,const index_type& sh,const index_type& nrl,
00383   const index_type& nrh,const index_type& ncl,const index_type& nch,
00384   const index_type& l5,const index_type& u5,
00385   const index_type& l6,const index_type& u6)
00386 {
00387   allocate(l7,u7,hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00388 }
00389 
00394 void d7_array::allocate(int l7,int u7,int hsl,int hsu,int sl,int sh,int nrl,
00395    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6)
00396  {
00397    if ( (shape=new vector_shape(l7,u7)) == 0)
00398    {
00399      cerr << " Error allocating memory in d6_array contructor\n";
00400      ad_exit(21);
00401    }
00402    int ss=size();
00403    if ( (t = new d6_array[ss]) == 0)
00404    {
00405      cerr << " Error allocating memory in d6_array contructor\n";
00406      ad_exit(21);
00407    }
00408    t -= indexmin();
00409    for (int i=l7; i<=u7; i++)
00410    {
00411      t[i].allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6);
00412    }
00413  }
00414 
00419 void d7_array::allocate(int l7,int u7)
00420 {
00421   if ( (shape=new vector_shape(l7,u7)) == 0)
00422   {
00423     cerr << " Error allocating memory in d6_array contructor\n";
00424     ad_exit(21);
00425   }
00426   int ss=size();
00427   if ( (t = new d6_array[ss]) == 0)
00428   {
00429     cerr << " Error allocating memory in d6_array contructor\n";
00430     ad_exit(21);
00431   }
00432   t -= indexmin();
00433   for (int i=l7; i<=u7; i++)
00434   {
00435     t[i].allocate();
00436   }
00437 }
00438 
00443  void d7_array::allocate(const ad_integer& l7,const ad_integer& u7,
00444    const index_type& hsl,const index_type& hsu,
00445    const index_type& sl,const index_type& sh,const index_type& nrl,
00446    const index_type& nrh,const index_type& ncl,const index_type& nch,
00447    const index_type& l5,const index_type& u5,
00448    const index_type& l6,const index_type& u6)
00449  {
00450    if ( (shape=new vector_shape (l7,u7)) == 0)
00451    {
00452      cerr << " Error allocating memory in d6_array contructor\n";
00453    }
00454 
00455    int ss=size();
00456    if ( (t = new d6_array[ss]) == 0)
00457    {
00458      cerr << " Error allocating memory in d6_array contructor\n";
00459      ad_exit(21);
00460    }
00461    t -= indexmin();
00462    int i1=l7;
00463    int iu=u7;
00464    for (int i=i1; i<=iu; i++)
00465    {
00466      (*this)(i).allocate(ad_integer(hsl(i)),ad_integer(hsu(i)),
00467        sl(i),sh(i),nrl(i),nrh(i),ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i));
00468    }
00469  }