ADMB Documentation  11.1.1951
 All Classes Files Functions Variables Typedefs Friends Defines
d4arr.hpp
Go to the documentation of this file.
00001 /*
00002  * $Id: d4arr.hpp 1729 2014-03-04 01:26:24Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "New BSD" license
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #ifndef D4ARR_HPP
00046 #define D4ARR_HPP
00047 
00052   class four_array_shape
00053   {
00054     unsigned int ncopies;
00055     int hslice_min;
00056     int hslice_max;
00057     int slice_min;
00058     int slice_max;
00059     int row_min;
00060     int row_max;
00061     int col_min;
00062     int col_max;
00063     four_array_shape(int hsl,int hsu, int sl,int sh,int rl,
00064       int ru,int cl,int cu);
00065     //mat_shape(){};
00066 
00067     friend class d4_array;
00068     friend class dvar4_array;
00069   }; // End of class four_array_shape
00070 
00075 class d4_array
00076 {
00077   four_array_shape * shape;
00078   d3_array * t;
00079 public:
00080   void allocate(int hsl,int hsu,int sl,int sh,int nrl,
00081     int nrh,int ncl,int nch);
00082   void allocate(int hsl, int hsu, int sl, const ivector& sh, int nrl,
00083                 const imatrix& nrh, int ncl, const imatrix& nch);
00084   void allocate(int hsl, int hsu, int sl, const ivector& sh, int nrl,
00085                 const imatrix& nrh, int ncl, const i3_array& nch);
00086   void allocate(int hsl, int hsu, int sl, int sh, int nrl,
00087                 int nrh, const ivector& ncl, const ivector& nch);
00088   void allocate(int hsl, int hsu, int sl, int sh, const ivector& nrl,
00089                 const ivector& nrh, const ivector& ncl, const ivector& nch);
00090   void allocate(int hsl, int hsu, int sl, const ivector& sh,
00091                 int nrl, const imatrix& nrh, int ncl, int nch);
00092   void deallocate(void);
00093   void allocate(void);
00094   void allocate(const d4_array&);
00095   void allocate(const dvar4_array&);
00096   int operator!(void) const { return (shape == NULL); }
00097   d4_array(int hsl,int hsu, int sl,int sh,ivector nrl,ivector nrh,
00098     ivector ncl,ivector nch);
00099   d4_array(int hsl, int hsu, int sl, const ivector& sh, int nrl,
00100            const imatrix& nrh, int ncl, const i3_array& nch);
00101   d4_array& operator=(const d4_array&);
00102   d4_array(d4_array& m2);
00103   d4_array(int,int,int,int,int,int,int,int);
00104   //d4_array(int,int,int,ivector,int,imatrix,int,int);
00105   d4_array(int hsl, int hsu, int sl, const ivector& sh,
00106            int nrl, const imatrix& nrh, int ncl, int nch);
00107   d4_array();
00108   ~d4_array();
00109    d3_array& elem(int i) { return t[i];}
00110    dmatrix& elem (int i ,int j) {return ((*this)(i))(j);}
00111    dvector& elem(int i,int j,int k) {return (((*this)(i,j))(k));}
00112    double& elem(int i,int j,int k,int l)
00113    {
00114      return ( ((*this)(i,j,k))(l));
00115    }
00116   #ifdef OPT_LIB
00117     d3_array& operator ( ) (int i) { return t[i];}
00118     d3_array& operator [] (int i) { return t[i];}
00119     dmatrix& operator ( ) (int i ,int j) {return ((*this)(i))(j);}
00120     dvector& operator ( ) (int i,int j,int k) {return (((*this)(i,j))(k));}
00121     double& operator ( ) (int i,int j,int k,int l)
00122     {
00123       return ( ((*this)(i,j,k))(l));
00124     }
00125      inline const d3_array& operator()(int i) const { return t[i]; }
00126      inline const d3_array& operator[](int i) const { return t[i]; }
00127      inline const dmatrix& operator()(int i, int j) const
00128        { return ((*this)(i))(j); }
00129      inline const dvector& operator()(int i, int j, int k) const
00130        { return (((*this)(i, j))(k)); }
00131      inline const double& operator()(int i, int j, int k, int l) const
00132      {
00133        return (((*this)(i, j, k))(l));
00134      }
00135   #else
00136       const d3_array& operator()(int i) const;
00137       const d3_array& operator[](int i) const;
00138       const dmatrix& operator()(int i, int j) const;
00139       const dvector& operator()(int i, int j, int k) const;
00140       const double& operator()(int i, int j, int k, int l) const;
00141     d3_array& operator ( ) (int);
00142     d3_array& operator [] (int);
00143     dmatrix& operator ( ) (int,int);
00144     dvector& operator ( ) (int,int,int);
00145     double& operator ( ) (int,int,int,int);
00146   #endif
00147   //access functions
00148   friend class four_array_shape;
00149   int hslicemin(void) { return(shape->hslice_min);}
00150   int hslicemax(void) { return(shape->hslice_max);}
00151   int slicemin(void) { return(shape->slice_min);}
00152   int slicemax(void) { return(shape->slice_max);}
00153   int colmin(void) { return(shape->col_min);}
00154   int colmax(void) { return(shape->col_max);}
00155   int rowmin(void) { return(shape->row_min);}
00156   int rowmax(void) { return(shape->row_max);}
00157 
00158    // returns the number of rows
00159   int hslicesize() {return (shape->hslice_max-shape->hslice_min+1);}
00160   // returns the number of rows
00161   int slicesize() {return (shape->slice_max-shape->slice_min+1);}
00162   // returns the number of rows
00163   int rowsize() {return (shape->row_max-shape->row_min+1);}
00164   // returns the number of columns
00165   int colsize() {return (shape->col_max-shape->col_min+1);}
00166   int hslicemin(void) const { return (shape->hslice_min); }
00167   int hslicemax(void) const { return (shape->hslice_max); }
00168   int slicemin(void) const { return (shape->slice_min); }
00169   int slicemax(void) const { return (shape->slice_max); }
00170   int colmin(void) const { return (shape->col_min); }
00171   int colmax(void) const { return (shape->col_max); }
00172   int rowmin(void) const { return (shape->row_min); }
00173   int rowmax(void) const { return (shape->row_max); }
00174   // returns the number of rows
00175   int hslicesize() const { return (shape->hslice_max-shape->hslice_min + 1); }
00176   // returns the number of rows
00177   int slicesize() const { return (shape->slice_max-shape->slice_min + 1); }
00178   // returns the number of rows
00179   int rowsize() const { return (shape->row_max-shape->row_min + 1); }
00180   // returns the number of columns
00181   int colsize() const { return (shape->col_max-shape->col_min + 1); }
00182   void initialize(void);
00183 };
00184 
00189 class dvar4_array
00190 {
00191   four_array_shape * shape;
00192   dvar3_array * t;
00193 public:
00194   void allocate(int hsl,int hsu,int sl,int sh,int nrl,
00195     int nrh,int ncl,int nch);
00196   void allocate(int hsl, int hsu, int sl, int sh, int nrl,
00197                 int nrh, const ivector& ncl, const ivector& nch);
00198   void allocate(int hsl, int hsu, int sl, int sh, const ivector& nrl,
00199                 const ivector& nrh, const ivector& ncl, const ivector& nch);
00200   void deallocate(void);
00201   void allocate(void);
00202   void allocate(const d4_array&);
00203   void allocate(const dvar4_array&);
00204   int operator!(void) const { return (shape == NULL); }
00205   dvar4_array(int hsl,int hsu, int sl,int sh,ivector nrl,ivector nrh,
00206     ivector ncl,ivector nch);
00207   dvar4_array(d4_array& m1);
00208   dvar4_array(dvar4_array& m2);
00209   dvar4_array(int,int,int,int,int,int,int,int);
00210   dvar4_array(int hsl, int hsu, int sl, const ivector& sh,
00211               int nrl, const imatrix& nrh, int ncl, int nch);
00212   void allocate(int hsl, int hsu, int sl, const ivector& sh,
00213                 int nrl, const imatrix& nrh, int ncl, int nch);
00214   //dvar4_array(int,int,int,ivector,int,imatrix,int,int);
00215   dvar4_array();
00216   ~dvar4_array();
00217    dvar3_array& elem(int i) { return t[i];}
00218    dvar_matrix& elem (int i ,int j) {return ((*this)(i))(j);}
00219    dvar_vector& elem(int i,int j,int k) {return (((*this)(i,j))(k));}
00220    prevariable elem(int i,int j,int k,int l)
00221    {
00222      return ( ((*this)(i,j,k))(l));
00223    }
00224 
00225   d4_array vale(d4_array&);
00226   dvar4_array& operator=(const d4_array&);
00227   dvar4_array& operator=(const dvar4_array&);
00228   #ifdef OPT_LIB
00229     dvar3_array& operator ( ) (int i) { return t[i];}
00230     dvar3_array& operator [] (int i) { return t[i];}
00231     dvar_matrix& operator ( ) (int i ,int j) {return ((*this)(i))(j);}
00232     dvar_vector& operator ( ) (int i,int j,int k) {return (((*this)(i,j))(k));}
00233     prevariable operator ( ) (int i,int j,int k,int l)
00234     {
00235       return ( ((*this)(i,j,k))(l));
00236     }
00237      inline const dvar3_array& operator()(int i) const { return t[i]; }
00238      inline const dvar3_array& operator[](int i) const { return t[i]; }
00239      inline const dvar_matrix& operator()(int i, int j) const
00240        { return ((*this)(i))(j); }
00241      inline const dvar_vector& operator()(int i, int j, int k) const
00242        {return (((*this)(i, j))(k)); }
00243      inline const prevariable operator()(int i, int j, int k, int l) const
00244      {
00245        return ( ((*this)(i,j,k))(l));
00246      }
00247   #else
00248       const dvar3_array& operator()(int i) const;
00249       const dvar3_array& operator[](int i) const;
00250       const dvar_matrix& operator()(int i, int j) const;
00251       const dvar_vector& operator()(int i, int j, int k) const;
00252       const prevariable operator()(int i, int j, int k, int l) const;
00253     dvar3_array& operator ( ) (int);
00254     dvar3_array& operator [] (int);
00255     dvar_matrix& operator ( ) (int,int);
00256     dvar_vector& operator ( ) (int,int,int);
00257     prevariable operator ( ) (int,int,int,int);
00258   #endif
00259   //access functions
00260   friend class four_array_shape;
00261   int hslicemin(void) { return(shape->hslice_min);}
00262   int hslicemax(void) { return(shape->hslice_max);}
00263   int slicemin(void) { return(shape->slice_min);}
00264   int slicemax(void) { return(shape->slice_max);}
00265   int colmin(void) { return(shape->col_min);}
00266   int colmax(void) { return(shape->col_max);}
00267   int rowmin(void) { return(shape->row_min);}
00268   int rowmax(void) { return(shape->row_max);}
00269   // returns the number of rows
00270   int hslicesize() {return (shape->hslice_max-shape->hslice_min+1);}
00271   // returns the number of rows
00272   int slicesize() {return (shape->slice_max-shape->slice_min+1);}
00273   // returns the number of rows
00274   int rowsize() {return (shape->row_max-shape->row_min+1);}
00275   // returns the number of columns
00276   int colsize() {return (shape->col_max-shape->col_min+1);}
00277   int hslicemin(void) const { return (shape->hslice_min); }
00278   int hslicemax(void) const { return (shape->hslice_max); }
00279   int slicemin(void) const { return (shape->slice_min); }
00280   int slicemax(void) const { return (shape->slice_max); }
00281   int colmin(void) const { return (shape->col_min); }
00282   int colmax(void) const { return (shape->col_max); }
00283   int rowmin(void) const { return (shape->row_min); }
00284   int rowmax(void) const { return (shape->row_max); }
00285   // returns the number of rows
00286   int hslicesize() const { return (shape->hslice_max-shape->hslice_min + 1); }
00287   // returns the number of rows
00288   int slicesize() const { return (shape->slice_max-shape->slice_min + 1); }
00289   // returns the number of rows
00290   int rowsize() const { return (shape->row_max-shape->row_min + 1); }
00291   // returns the number of columns
00292   int colsize() const { return (shape->col_max-shape->col_min + 1); }
00293   void initialize(void);
00294 };
00295 
00296 d4_array exp(const d4_array& x);
00297 dvar4_array exp(const dvar4_array& x);
00298 d4_array sqrt(const d4_array& x);
00299 dvar4_array sqrt(const dvar4_array& x);
00300 
00301 ostream& operator<<(const ostream& ostr, d4_array &z);
00302 istream& operator>>(const istream& istr, d4_array &z);
00303 ostream& operator<<(const ostream& ostr, dvar4_array &z);
00304 istream& operator>>(const istream& istr, dvar4_array &z);
00305 
00306 #endif  // #ifndef D4ARR_HPP