ADMB Documentation  11.1.1920
 All Classes Files Functions Variables Typedefs Friends Defines
f3arr1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f3arr1.cpp 1716 2014-03-03 20:34:53Z 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 
00014 #ifndef OPT_LIB
00015 
00020     prevariable dvar3_array::operator () (int k, int i, int j)
00021     {
00022       #ifdef SAFE_ARRAYS
00023       if (!allocated(*this))
00024       {
00025          cerr << "trying to access an unallocated object" << endl;
00026          ad_exit(21);
00027       }
00028       if (k < slicemin())
00029       {
00030          ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too low",
00031          "prevariable dvar3_array::operator () (int k, int i, int j)",
00032          slicemin(), slicemax(), k);
00033       }
00034       if (k > slicemax())
00035       {
00036          ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too high",
00037          "prevariable dvar3_array::operator () (int k, int i, int j)",
00038          slicemin(), slicemax(), k);
00039       }
00040       return ( (elem(k))(i,j) );
00041       #else
00042       return ( (t[k].m[i]).va+j );
00043       #endif
00044     }
00045 
00050     dvar_vector& dvar3_array::operator () (int k, int i)
00051     {
00052       #ifdef SAFE_ARRAYS
00053       if (k < slicemin())
00054       {
00055          ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too low",
00056          "dvar_vector& dvar3_array::operator () (int k, int i)",
00057          slicemin(), slicemax(), k);
00058       }
00059       if (k > slicemax())
00060       {
00061          ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too high",
00062          "dvar_vector& dvar3_array::operator () (int k, int i)",
00063          slicemin(), slicemax(), k);
00064       }
00065       #endif
00066       return ( (elem(k))(i) );
00067     }
00068 
00073  dvar_matrix& dvar3_array::operator[] (int i)
00074  {
00075    #ifdef SAFE_ARRAYS
00076    if (i < slicemin())
00077    {
00078      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too low",
00079      "dvar_matrix& dvar3_array::operator [] (int i)",
00080      slicemin(), slicemax(), i);
00081    }
00082    if (i > slicemax())
00083    {
00084      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too high",
00085      "dvar_matrix& dvar3_array::operator [] (int i)",
00086      slicemin(), slicemax(), i);
00087    }
00088    #endif
00089    return( t[i]);
00090  }
00091 
00096  dvar_matrix& dvar3_array::operator() (int i)
00097  {
00098    #ifdef SAFE_ARRAYS
00099    if (!allocated(*this))
00100    {
00101        cerr << "trying to access an unallocated object" << endl;
00102        ad_exit(21);
00103    }
00104    if (i < slicemin())
00105    {
00106      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too low",
00107      "dvar_matrix& dvar3_array::operator () (int i)",
00108      slicemin(), slicemax(), i);
00109    }
00110    if (i > slicemax())
00111    {
00112      ADMB_ARRAY_BOUNDS_ERROR("array bound exceeded -- slice index too high",
00113      "dvar_matrix& dvar3_array::operator () (int i)",
00114      slicemin(), slicemax(), i);
00115    }
00116    #endif
00117    return( t[i]);
00118  }
00119 #endif
00120 
00125 dvariable sum(const dvar3_array& m)
00126 {
00127   RETURN_ARRAYS_INCREMENT();
00128   dvariable tmp=0.;
00129   for (int i=m.indexmin();i<=m.indexmax();i++)
00130   {
00131     tmp+=sum(m.elem(i));
00132   }
00133   RETURN_ARRAYS_DECREMENT();
00134   return tmp;
00135 }