ADMB Documentation  11.1.1914
 All Classes Files Functions Variables Typedefs Friends Defines
f7arr.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f7arr.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 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       #ifdef SAFE_ARRAYS
00220       if (i < indexmin() || i > indexmax())
00221       {
00222         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00223         "dvar6_array& dvar7_array::operator () (int i)",
00224         indexmin(), indexmax(), i);
00225       }
00226       #endif
00227       return t[i];
00228     }
00229 
00234     dvar6_array& dvar7_array::operator [] (int i)
00235     {
00236       #ifdef SAFE_ARRAYS
00237       if (i < indexmin() || i > indexmax())
00238       {
00239         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00240         "dvar6_array& dvar7_array::operator [] (int i)",
00241         indexmin(), indexmax(), i);
00242       }
00243       #endif
00244       return t[i];
00245     }
00246 
00251     dvar5_array& dvar7_array::operator ( ) (int i ,int j)
00252     {
00253       #ifdef SAFE_ARRAYS
00254       if (i < indexmin() || i > indexmax())
00255       {
00256         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00257         "dvar5_array& dvar7_array::operator ( ) (int i, int j)",
00258         indexmin(), indexmax(), i);
00259       }
00260       #endif
00261       return elem(i)(j);
00262     }
00263 
00268     dvar4_array& dvar7_array::operator ( ) (int i,int j,int k)
00269     {
00270       #ifdef SAFE_ARRAYS
00271       if (i < indexmin() || i > indexmax())
00272       {
00273         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00274         "dvar4_array& dvar7_array::operator ( ) (int i, int j, int k)",
00275         indexmin(), indexmax(), i);
00276       }
00277       #endif
00278       return elem(i)(j,k);
00279     }
00280 
00285     dvar3_array& dvar7_array::operator ( ) (int i,int j,int k,int l)
00286     {
00287       #ifdef SAFE_ARRAYS
00288       if (i < indexmin() || i > indexmax())
00289       {
00290         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00291         "dvar3_array& dvar7_array::operator ( ) (int i, int j, int k, int l)",
00292         indexmin(), indexmax(), i);
00293       }
00294       #endif
00295       return elem(i)(j,k,l);
00296     }
00297 
00302     dvar_matrix& dvar7_array::operator ( ) (int i,int j,int k,int l,int m)
00303     {
00304       #ifdef SAFE_ARRAYS
00305       if (i < indexmin() || i > indexmax())
00306       {
00307         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00308    "dvar_matrix& dvar7_array::operator ( ) (int i, int j, int k, int l, int m)",
00309         indexmin(), indexmax(), i);
00310       }
00311       #endif
00312       return elem(i)(j,k,l,m);
00313     }
00314 
00319 dvar_vector& dvar7_array::operator ( ) (int i,int j,int k,int l,int m, int n)
00320     {
00321       #ifdef SAFE_ARRAYS
00322       if (i < indexmin() || i > indexmax())
00323       {
00324         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00325 "dvar_vector& dvar7_array::operator()(int i,int j, int k, int l, int m, int n)",
00326         indexmin(), indexmax(), i);
00327       }
00328       #endif
00329       return elem(i)(j,k,l,m,n);
00330     }
00331 
00336 prevariable dvar7_array::operator()(int i,int j,int k,int l,int m, int n,int _p)
00337     {
00338       #ifdef SAFE_ARRAYS
00339       if (i < indexmin() || i > indexmax())
00340       {
00341         ADMB_ARRAY_BOUNDS_ERROR("hslice index out of bounds",
00342 "dvar7_array::operator()(int i, int j, int k, int l, int m, int n, int _p)",
00343         indexmin(), indexmax(), i);
00344       }
00345       #endif
00346       return elem(i)(j,k,l,m,n,_p);
00347     }
00348 
00353 const dvar6_array& dvar7_array::operator()(int i) const
00354     {
00355       #ifdef SAFE_ARRAYS
00356         if (i<indexmin()||i>indexmax())
00357         { cerr << "Error  index out of bounds in\n"
00358             "dvar6_array& dvar7_array::operator ( )" << endl;
00359           ad_exit(1);
00360         }
00361       #endif
00362       return t[i];
00363     }
00364 
00369 const dvar6_array& dvar7_array::operator[](int i) const
00370     {
00371       #ifdef SAFE_ARRAYS
00372         if (i<indexmin()||i>indexmax())
00373         { cerr << "Error  index out of bounds in\n"
00374             "dvar5_array& dvar6_array::operator []" << endl;
00375           ad_exit(1);
00376         }
00377       #endif
00378       return t[i];
00379     }
00380 
00385 const dvar5_array& dvar7_array::operator()(int i ,int j) const
00386     {
00387       #ifdef SAFE_ARRAYS
00388         if (i<indexmin()||i>indexmax())
00389         { cerr << "Error hslice index out of bounds in\n"
00390             "dvar3_array& dvar7_array::operator ( )" << endl;
00391           ad_exit(1);
00392         }
00393       #endif
00394       return elem(i)(j);
00395     }
00396 
00401 const dvar4_array& dvar7_array::operator()(int i,int j,int k) const
00402     {
00403       #ifdef SAFE_ARRAYS
00404         if (i<indexmin()||i>indexmax())
00405         { cerr << "Error hslice index out of bounds in\n"
00406           "dvar_matrix& dvar7_array::operator ( )" << endl;
00407           ad_exit(1);
00408         }
00409       #endif
00410       return elem(i)(j,k);
00411     }
00412 
00417 const dvar3_array& dvar7_array::operator()(int i, int j, int k, int l) const
00418     {
00419       #ifdef SAFE_ARRAYS
00420         if (i<indexmin()||i>indexmax())
00421         { cerr << "Error hslice index out of bounds in\n"
00422             "dvar-vector& dvar7_array::operator ( )"  << endl;
00423           ad_exit(1);
00424         }
00425       #endif
00426       return elem(i)(j,k,l);
00427     }
00428 
00433 const dvar_matrix& dvar7_array::operator()(int i, int j, int k, int l, int m)
00434   const
00435     {
00436       #ifdef SAFE_ARRAYS
00437         if (i<indexmin()||i>indexmax())
00438         { cerr << "Error hslice index out of bounds in\n"
00439             "prevariable& dvar7_array::operator ( )"  << endl;
00440           ad_exit(1);
00441         }
00442       #endif
00443       return elem(i)(j,k,l,m);
00444     }
00445 
00450 const dvar_vector& dvar7_array::operator()(int i, int j, int k, int l, int m,
00451   int n) const
00452     {
00453       #ifdef SAFE_ARRAYS
00454         if (i<indexmin()||i>indexmax())
00455         { cerr << "Error hslice index out of bounds in\n"
00456             "prevariable& dvar7_array::operator ( )"  << endl;
00457           ad_exit(1);
00458         }
00459       #endif
00460       return elem(i)(j,k,l,m,n);
00461     }
00462 
00467 const prevariable dvar7_array::operator()(int i, int j, int k, int l, int m,
00468    int n, int _p) const
00469     {
00470       #ifdef SAFE_ARRAYS
00471         if (i<indexmin()||i>indexmax())
00472         { cerr << "Error hslice index out of bounds in\n"
00473             "prevariable& dvar7_array::operator ( )"  << endl;
00474           ad_exit(1);
00475         }
00476       #endif
00477       return elem(i)(j,k,l,m,n,_p);
00478     }
00479 #endif
00480 
00485 dvar7_array::dvar7_array(int hsl,int hsu,int sl,int sh,int nrl,
00486    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6,int l7,int u7)
00487 {
00488   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
00489 }
00490 
00495 dvar7_array::dvar7_array(const ad_integer& hsl,const ad_integer& hsu,
00496   const index_type& sl,const index_type& sh,const index_type& nrl,
00497   const index_type& nrh,const index_type& ncl,const index_type& nch,
00498   const index_type& l5,const index_type& u5,
00499   const index_type& l6,const index_type& u6,
00500   const index_type& l7,const index_type& u7)
00501 {
00502   allocate(hsl,hsu,sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
00503 }
00504 
00509 void dvar7_array::allocate(int hsl,int hsu,int sl,int sh,int nrl,
00510    int nrh,int ncl,int nch,int l5,int u5,int l6,int u6,int l7,int u7)
00511  {
00512    if ( (shape=new vector_shape(hsl,hsu)) == 0)
00513    {
00514      cerr << " Error allocating memory in dvar6_array contructor\n";
00515      ad_exit(21);
00516    }
00517    int ss=size();
00518    if ( (t = new dvar6_array[ss]) == 0)
00519    {
00520      cerr << " Error allocating memory in dvar6_array contructor\n";
00521      ad_exit(21);
00522    }
00523    t -= indexmin();
00524    for (int i=hsl; i<=hsu; i++)
00525    {
00526      (*this)(i).allocate(sl,sh,nrl,nrh,ncl,nch,l5,u5,l6,u6,l7,u7);
00527    }
00528  }
00529 
00534  void dvar7_array::allocate(const ad_integer& hsl,const ad_integer& hsu,
00535   const index_type& sl,const index_type& sh,const index_type& nrl,
00536    const index_type& nrh,const index_type& ncl,const index_type& nch,
00537    const index_type& l5,const index_type& u5,
00538    const index_type& l6,const index_type& u6,
00539    const index_type& l7,const index_type& u7)
00540  {
00541    if ( (shape=new vector_shape (hsl,hsu)) == 0)
00542    {
00543      cerr << " Error allocating memory in dvar6_array contructor\n";
00544    }
00545 
00546    int ss=size();
00547    if ( (t = new dvar6_array[ss]) == 0)
00548    {
00549      cerr << " Error allocating memory in dvar6_array contructor\n";
00550      ad_exit(21);
00551    }
00552    t -= indexmin();
00553    int il=hsl;
00554    int iu=hsu;
00555    for (int i=il; i<=iu; i++)
00556    {
00557      t[i].allocate(ad_integer(sl(i)),ad_integer(sh(i)),nrl(i),nrh(i),
00558         ncl(i),nch(i),l5(i),u5(i),l6(i),u6(i),l7(i),u7(i));
00559    }
00560  }