ADMB Documentation  11.1.2535
 All Classes Files Functions Variables Typedefs Friends Defines
f7arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f7arr.cpp 1921 2014-04-23 18:47:05Z 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 dvar7_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 void dvar7_array::allocate(int l7,int u7)
00033 {
00034   if ( (shape=new vector_shape(l7,u7)) == 0)
00035   {
00036     cerr << " Error allocating memory in d6_array contructor\n";
00037     ad_exit(21);
00038   }
00039   int ss=size();
00040   if ( (t = new dvar6_array[ss]) == 0)
00041   {
00042     cerr << " Error allocating memory in d6_array contructor\n";
00043     ad_exit(21);
00044   }
00045   t -= indexmin();
00046   for (int i=l7; i<=u7; i++)
00047   {
00048     t[i].allocate();
00049   }
00050 }
00051 
00056  dvar7_array::dvar7_array(dvar7_array& m2)
00057  {
00058    if (m2.shape)
00059    {
00060      shape=m2.shape;
00061      (shape->ncopies)++;
00062      t = m2.t;
00063    }
00064    else
00065    {
00066      shape=NULL;
00067      t=NULL;
00068    }
00069  }
00070 
00075  dvar7_array::dvar7_array(d7_array& m2)
00076  {
00077    allocate(m2);
00078    (*this)=m2;
00079  }
00080 
00085  void dvar7_array::deallocate()
00086  {
00087    if (shape)
00088    {
00089      if (shape->ncopies)
00090      {
00091        (shape->ncopies)--;
00092      }
00093      else
00094      {
00095        t += indexmin();
00096        delete [] t;
00097        t=NULL;
00098        delete shape;
00099        shape=NULL;
00100      }
00101    }
00102 #if defined(ADWARN_DEV)
00103    else
00104    {
00105      cerr << "Warning -- trying to deallocate an unallocated dvar5_array"<<endl;
00106    }
00107 #endif
00108  }
00109 
00114  dvar7_array::~dvar7_array()
00115  {
00116    deallocate();
00117  }
00118 
00123  dvar7_array& dvar7_array::operator=(const dvar7_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       " dvar5_array& dvar5_array:: operator =  (const dvar5_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 dvar7_array& dvar7_array::operator=(const d7_array& m)
00146  {
00147    int mmin=indexmin();
00148    int mmax=indexmax();
00149    if (mmin!=m.indexmin() || mmax!=m.indexmax())
00150    {
00151      cerr << "Incompatible bounds in"
00152       " dvar7_array& dvar7_array:: operator =  (const d7_array& m)"
00153       << endl;
00154      ad_exit(1);
00155     }
00156    for (int i=mmin; i<=mmax; i++)
00157    {
00158      (*this)(i)=m(i);
00159    }
00160    return *this;
00161  }
00162 
00167 void dvar7_array::allocate(const dvar7_array& m1)
00168  {
00169    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00170        == 0)
00171    {
00172      cerr << " Error allocating memory in dvar6_array contructor" << endl;
00173    }
00174    int ss=size();
00175    if ( (t = new dvar6_array[ss]) == 0)
00176    {
00177      cerr << " Error allocating memory in dvar6_array contructor" << endl;
00178      ad_exit(21);
00179    }
00180    t -= indexmin();
00181    for (int i=indexmin(); i<=indexmax(); i++)
00182    {
00183      t[i].allocate(m1[i]);
00184    }
00185  }
00186 
00191 void dvar7_array::allocate(const d7_array& m1)
00192  {
00193    if ( (shape=new vector_shape(m1.indexmin(),m1.indexmax()))
00194        == 0)
00195    {
00196      cerr << " Error allocating memory in dvar6_array contructor" << endl;
00197    }
00198    int ss=size();
00199    if ( (t = new dvar6_array[ss]) == 0)
00200    {
00201      cerr << " Error allocating memory in dvar6_array contructor" << endl;
00202      ad_exit(21);
00203    }
00204    t -= indexmin();
00205    for (int i=indexmin(); i<=indexmax(); i++)
00206    {
00207      t[i].allocate(m1[i]);
00208    }
00209  }
00210 
00211   #ifndef OPT_LIB
00212 
00217     dvar6_array& dvar7_array::operator ( ) (int i)
00218     {
00219       if (i < indexmin() || i > indexmax())
00220       {
00221         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00222         "dvar6_array& dvar7_array::operator () (int i)",
00223         indexmin(), indexmax(), i);
00224       }
00225       return t[i];
00226     }
00227 
00232     dvar6_array& dvar7_array::operator [] (int i)
00233     {
00234       if (i < indexmin() || i > indexmax())
00235       {
00236         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00237         "dvar6_array& dvar7_array::operator [] (int i)",
00238         indexmin(), indexmax(), i);
00239       }
00240       return t[i];
00241     }
00242 
00247     dvar5_array& dvar7_array::operator ( ) (int i ,int j)
00248     {
00249       if (i < indexmin() || i > indexmax())
00250       {
00251         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00252         "dvar5_array& dvar7_array::operator ( ) (int i, int j)",
00253         indexmin(), indexmax(), i);
00254       }
00255       return elem(i)(j);
00256     }
00257 
00262     dvar4_array& dvar7_array::operator ( ) (int i,int j,int k)
00263     {
00264       if (i < indexmin() || i > indexmax())
00265       {
00266         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00267         "dvar4_array& dvar7_array::operator ( ) (int i, int j, int k)",
00268         indexmin(), indexmax(), i);
00269       }
00270       return elem(i)(j,k);
00271     }
00272 
00277     dvar3_array& dvar7_array::operator ( ) (int i,int j,int k,int l)
00278     {
00279       if (i < indexmin() || i > indexmax())
00280       {
00281         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00282         "dvar3_array& dvar7_array::operator ( ) (int i, int j, int k, int l)",
00283         indexmin(), indexmax(), i);
00284       }
00285       return elem(i)(j,k,l);
00286     }
00287 
00292     dvar_matrix& dvar7_array::operator ( ) (int i,int j,int k,int l,int m)
00293     {
00294       if (i < indexmin() || i > indexmax())
00295       {
00296         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00297    "dvar_matrix& dvar7_array::operator ( ) (int i, int j, int k, int l, int m)",
00298         indexmin(), indexmax(), i);
00299       }
00300       return elem(i)(j,k,l,m);
00301     }
00302 
00307 dvar_vector& dvar7_array::operator ( ) (int i,int j,int k,int l,int m, int n)
00308     {
00309       if (i < indexmin() || i > indexmax())
00310       {
00311         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00312 "dvar_vector& dvar7_array::operator()(int i,int j, int k, int l, int m, int n)",
00313         indexmin(), indexmax(), i);
00314       }
00315       return elem(i)(j,k,l,m,n);
00316     }
00317 
00322 prevariable dvar7_array::operator()(int i,int j,int k,int l,int m, int n,int _p)
00323     {
00324       if (i < indexmin() || i > indexmax())
00325       {
00326         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00327 "dvar7_array::operator()(int i, int j, int k, int l, int m, int n, int _p)",
00328         indexmin(), indexmax(), i);
00329       }
00330       return elem(i)(j,k,l,m,n,_p);
00331     }
00332 
00337 const dvar6_array& dvar7_array::operator()(int i) const
00338     {
00339         if (i<indexmin()||i>indexmax())
00340         { cerr << "Error  index out of bounds in\n"
00341             "dvar6_array& dvar7_array::operator ( )" << endl;
00342           ad_exit(1);
00343         }
00344       return t[i];
00345     }
00346 
00351 const dvar6_array& dvar7_array::operator[](int i) const
00352     {
00353         if (i<indexmin()||i>indexmax())
00354         { cerr << "Error  index out of bounds in\n"
00355             "dvar5_array& dvar6_array::operator []" << endl;
00356           ad_exit(1);
00357         }
00358       return t[i];
00359     }
00360 
00365 const dvar5_array& dvar7_array::operator()(int i ,int j) const
00366     {
00367         if (i<indexmin()||i>indexmax())
00368         { cerr << "Error hslice index out of bounds in\n"
00369             "dvar3_array& dvar7_array::operator ( )" << endl;
00370           ad_exit(1);
00371         }
00372       return elem(i)(j);
00373     }
00374 
00379 const dvar4_array& dvar7_array::operator()(int i,int j,int k) const
00380     {
00381         if (i<indexmin()||i>indexmax())
00382         { cerr << "Error hslice index out of bounds in\n"
00383           "dvar_matrix& dvar7_array::operator ( )" << endl;
00384           ad_exit(1);
00385         }
00386       return elem(i)(j,k);
00387     }
00388 
00393 const dvar3_array& dvar7_array::operator()(int i, int j, int k, int l) const
00394     {
00395         if (i<indexmin()||i>indexmax())
00396         { cerr << "Error hslice index out of bounds in\n"
00397             "dvar-vector& dvar7_array::operator ( )"  << endl;
00398           ad_exit(1);
00399         }
00400       return elem(i)(j,k,l);
00401     }
00402 
00407 const dvar_matrix& dvar7_array::operator()(int i, int j, int k, int l, int m)
00408   const
00409     {
00410         if (i<indexmin()||i>indexmax())
00411         { cerr << "Error hslice index out of bounds in\n"
00412             "prevariable& dvar7_array::operator ( )"  << endl;
00413           ad_exit(1);
00414         }
00415       return elem(i)(j,k,l,m);
00416     }
00417 
00422 const dvar_vector& dvar7_array::operator()(int i, int j, int k, int l, int m,
00423   int n) const
00424     {
00425         if (i<indexmin()||i>indexmax())
00426         { cerr << "Error hslice index out of bounds in\n"
00427             "prevariable& dvar7_array::operator ( )"  << endl;
00428           ad_exit(1);
00429         }
00430       return elem(i)(j,k,l,m,n);
00431     }
00432 
00437 const prevariable dvar7_array::operator()(int i, int j, int k, int l, int m,
00438    int n, int _p) const
00439     {
00440         if (i<indexmin()||i>indexmax())
00441         { cerr << "Error hslice index out of bounds in\n"
00442             "prevariable& dvar7_array::operator ( )"  << endl;
00443           ad_exit(1);
00444         }
00445       return elem(i)(j,k,l,m,n,_p);
00446     }
00447 #endif
00448 
00453 dvar7_array::dvar7_array(int hsl,int hsu,int sl,int sh,int nrl,
00454    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6,int l7,int u7)
00455 {
00456   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
00457 }
00458 
00463 dvar7_array::dvar7_array(const ad_integer& hsl,const ad_integer& hsu,
00464   const index_type& sl,const index_type& sh,const index_type& nrl,
00465   const index_type& nrh,const index_type& ncl,const index_type& nch,
00466   const index_type& l5,const index_type& u5,
00467   const index_type& l6,const index_type& u6,
00468   const index_type& l7,const index_type& u7)
00469 {
00470   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
00471 }
00472 
00477 void dvar7_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00478    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6,int l7,int u7)
00479  {
00480    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00481    {
00482      cerr << " Error allocating memory in dvar6_array contructor\n";
00483      ad_exit(21);
00484    }
00485    int ss=size();
00486    if ( (t = new dvar6_array[ss]) == 0)
00487    {
00488      cerr << " Error allocating memory in dvar6_array contructor\n";
00489      ad_exit(21);
00490    }
00491    t -= indexmin();
00492    for (int i=hsl; i<=hsu; i++)
00493    {
00494      (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
00495    }
00496  }
00497 
00502  void dvar7_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00503   const index_type& sl,const index_type& sh,const index_type& nrl,
00504    const index_type& nrh,const index_type& ncl,const index_type& nch,
00505    const index_type& l5,const index_type& u5,
00506    const index_type& l6,const index_type& u6,
00507    const index_type& l7,const index_type& u7)
00508  {
00509    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00510    {
00511      cerr << " Error allocating memory in dvar6_array contructor\n";
00512    }
00513 
00514    int ss=size();
00515    if ( (t = new dvar6_array[ss]) == 0)
00516    {
00517      cerr << " Error allocating memory in dvar6_array contructor\n";
00518      ad_exit(21);
00519    }
00520    t -= indexmin();
00521    int il=hsl;
00522    int iu=hsu;
00523    for (int i=il; i<=iu; i++)
00524    {
00525      t[i].allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00526         ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i),l7(i),u7(i));
00527    }
00528  }