ADMB Documentation  11.1.1903
 All Classes Files Functions Variables Typedefs Friends Defines
f1b2vc2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f1b2vc2.cpp 1107 2013-07-11 21:56:15Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fun.h>
00012 
00017   dvector value(const df1b2vector& _t1)
00018   {
00019      ADUNCONST(df1b2vector,t1)
00020      dvector tmp(t1.indexmin(),t1.indexmax());
00021 
00022      for (int i=t1.indexmin(); i<=t1.indexmax(); i++)
00023      {
00024        tmp.elem(i)=value(t1(i));
00025      }
00026      return(tmp);
00027   }
00028 
00033   dmatrix value(const df1b2matrix& _m)
00034   {
00035     ADUNCONST(df1b2matrix,m)
00036     int nrl=m.indexmin();
00037     int nrh=m.indexmax();
00038     ivector ncl(nrl,nrh);
00039     ivector nch(nrl,nrh);
00040     int i;
00041     for (i=nrl;i<=nrh;i++)
00042     {
00043       ncl(i)=m(i).indexmin();
00044       nch(i)=m(i).indexmax();
00045     }
00046     dmatrix tmp(nrl,nrh,ncl,nch);
00047     for (i=nrl;i<=nrh;i++)
00048     {
00049       tmp(i)=value(m(i));
00050     }
00051     return tmp;
00052   }
00053 
00058 df1b2matrix&  df1b2matrix::operator = (const df1b2matrix& _M)
00059 {
00060   ADUNCONST(df1b2matrix,M)
00061   int mmin=M.indexmin();
00062   int mmax=M.indexmax();
00063   for (int i=mmin;i<=mmax;i++)
00064   {
00065     (*this)(i)=M(i);
00066   }
00067   return *this;
00068 }
00069 
00074 df1b2matrix&  df1b2matrix::operator = (const dmatrix& _M)
00075 {
00076   ADUNCONST(dmatrix,M)
00077   int mmin=M.indexmin();
00078   int mmax=M.indexmax();
00079   for (int i=mmin;i<=mmax;i++)
00080   {
00081     (*this)(i)=M(i);
00082   }
00083   return *this;
00084 }
00085 
00090 df1b2matrix&  df1b2matrix::operator = (double M)
00091 {
00092   int mmin=indexmin();
00093   int mmax=indexmax();
00094   for (int i=mmin;i<=mmax;i++)
00095   {
00096     int jmin=(*this)(i).indexmin();
00097     int jmax=(*this)(i).indexmax();
00098     for (int j=jmin;j<=jmax;j++)
00099     {
00100       (*this)(i,j)=M;
00101     }
00102   }
00103   return *this;
00104 }
00105 
00110 df1b2matrix&  df1b2matrix::operator = (const df1b2variable& _M)
00111 {
00112   ADUNCONST(df1b2variable,M)
00113   int mmin=indexmin();
00114   int mmax=indexmax();
00115   for (int i=mmin;i<=mmax;i++)
00116   {
00117     int jmin=(*this)(i).indexmin();
00118     int jmax=(*this)(i).indexmax();
00119     for (int j=jmin;i<=jmax;i++)
00120     {
00121       (*this)(i,j)=M;
00122     }
00123   }
00124   return *this;
00125 }
00126 
00131 df1b2matrix square(const df1b2matrix& _M)
00132 {
00133   ADUNCONST(df1b2matrix,M)
00134   int rmin=M.indexmin();
00135   int rmax=M.indexmax();
00136   df1b2matrix tmp(rmin,rmax);
00137   for (int i=rmin;i<=rmax;i++)
00138   {
00139     int cmin=M(i).indexmin();
00140     int cmax=M(i).indexmax();
00141     // need special allocate so that = does not cause an assign.
00142     tmp(i).noallocate(cmin,cmax);
00143     for (int j=cmin;j<=cmax;j++)
00144     {
00145       tmp(i,j)=square(M(i,j));
00146     }
00147   }
00148   return tmp;
00149 }
00150 
00155 void df1b2matrix::initialize(void)
00156 {
00157   int rmin=indexmin();
00158   int rmax=indexmax();
00159   for (int i=rmin;i<=rmax;i++)
00160   {
00161     int cmin=(*this)(i).indexmin();
00162     int cmax=(*this)(i).indexmax();
00163     // need special allocate so that = does not cause an assign.
00164     for (int j=cmin;j<=cmax;j++)
00165     {
00166       (*this)(i,j)=0.0;
00167     }
00168   }
00169 }
00170 
00175 df1b2matrix mfexp(const df1b2matrix& _M)
00176 {
00177   ADUNCONST(df1b2matrix,M)
00178   int rmin=M.indexmin();
00179   int rmax=M.indexmax();
00180   df1b2matrix tmp(rmin,rmax);
00181   for (int i=rmin;i<=rmax;i++)
00182   {
00183     int cmin=M(i).indexmin();
00184     int cmax=M(i).indexmax();
00185     // need special allocate so that = does not cause an assign.
00186     tmp(i).noallocate(cmin,cmax);
00187     for (int j=cmin;j<=cmax;j++)
00188     {
00189       tmp(i,j)=mfexp(M(i,j));
00190     }
00191   }
00192   return tmp;
00193 }
00194 
00199 df1b2matrix log(const df1b2matrix& _M)
00200 {
00201   ADUNCONST(df1b2matrix,M)
00202   int rmin=M.indexmin();
00203   int rmax=M.indexmax();
00204   df1b2matrix tmp(rmin,rmax);
00205   for (int i=rmin;i<=rmax;i++)
00206   {
00207     int cmin=M(i).indexmin();
00208     int cmax=M(i).indexmax();
00209     // need special allocate so that = does not cause an assign.
00210     tmp(i).noallocate(cmin,cmax);
00211     for (int j=cmin;j<=cmax;j++)
00212     {
00213       tmp(i,j)=log(M(i,j));
00214     }
00215   }
00216   return tmp;
00217 }
00218 
00223 df1b2matrix sin(const df1b2matrix& _M)
00224 {
00225   ADUNCONST(df1b2matrix,M)
00226   int rmin=M.indexmin();
00227   int rmax=M.indexmax();
00228   df1b2matrix tmp(rmin,rmax);
00229   for (int i=rmin;i<=rmax;i++)
00230   {
00231     int cmin=M(i).indexmin();
00232     int cmax=M(i).indexmax();
00233     // need special allocate so that = does not cause an assign.
00234     tmp(i).noallocate(cmin,cmax);
00235     for (int j=cmin;j<=cmax;j++)
00236     {
00237       tmp(i,j)=sin(M(i,j));
00238     }
00239   }
00240   return tmp;
00241 }
00242 
00247 df1b2matrix cos(const df1b2matrix& _M)
00248 {
00249   ADUNCONST(df1b2matrix,M)
00250   int rmin=M.indexmin();
00251   int rmax=M.indexmax();
00252   df1b2matrix tmp(rmin,rmax);
00253   for (int i=rmin;i<=rmax;i++)
00254   {
00255     int cmin=M(i).indexmin();
00256     int cmax=M(i).indexmax();
00257     // need special allocate so that = does not cause an assign.
00258     tmp(i).noallocate(cmin,cmax);
00259     for (int j=cmin;j<=cmax;j++)
00260     {
00261       tmp(i,j)=cos(M(i,j));
00262     }
00263   }
00264   return tmp;
00265 }
00266 /*
00267 df1b2matrix tan(const df1b2matrix& M)
00268 {
00269   int rmin=M.indexmin();
00270   int rmax=M.indexmax();
00271   df1b2matrix tmp(rmin,rmax);
00272   for (int i=rmin;i<=rmax;i++)
00273   {
00274     int cmin=M(i).indexmin();
00275     int cmax=M(i).indexmax();
00276     // need special allocate so that = does not cause an assign.
00277     tmp(i).noallocate(cmin,cmax);
00278     for (int j=cmin;j<=cmax;j++)
00279     {
00280       tmp(i,j)=tan(M(i,j));
00281     }
00282   }
00283   return tmp;
00284 }
00285 */