ADMB Documentation  11.1.2274
 All Classes Files Functions Variables Typedefs Friends Defines
f1b2vc3.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f1b2vc3.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fun.h>
00012 
00017 df1b2matrix outer_prod(const df1b2vector& _MM,const df1b2vector& _NN)
00018 {
00019   df1b2vector& M = (df1b2vector&)_MM;
00020   df1b2vector& N = (df1b2vector&)_NN;
00021   int rmin=M.indexmin();
00022   int rmax=M.indexmax();
00023   int cmin=N.indexmin();
00024   int cmax=N.indexmax();
00025   df1b2matrix tmp(rmin,rmax);
00026   for (int i=rmin;i<=rmax;i++)
00027   {
00028     tmp(i).noallocate(cmin,cmax);
00029     for (int j=cmin;j<=cmax;j++)
00030     {
00031       tmp(i,j)=M(i)*N(j);
00032     }
00033   }
00034   return tmp;
00035 }
00036 
00041 df1b2vector mfexp(const df1b2vector& _x)
00042 {
00043   ADUNCONST(df1b2vector,x)
00044   df1b2vector tmp;
00045   int mmin=x.indexmin();
00046   int mmax=x.indexmax();
00047   tmp.noallocate(mmin,mmax);
00048   for (int i=mmin;i<=mmax;i++)
00049   {
00050     tmp(i)=mfexp(x(i));
00051   }
00052   return tmp;
00053 }
00054 
00059 df1b2vector operator * (const df1b2variable& _v,const dvector& _x)
00060 {
00061   ADUNCONST(df1b2variable,v)
00062   ADUNCONST(dvector,x)
00063   df1b2vector tmp;
00064   int mmin=x.indexmin();
00065   int mmax=x.indexmax();
00066   tmp.noallocate(mmin,mmax);
00067   for (int i=mmin;i<=mmax;i++)
00068   {
00069     tmp(i)=v*x(i);
00070   }
00071   return tmp;
00072 }
00073 
00078 df1b2vector operator * (const df1b2vector& _x,const df1b2variable& _v)
00079 {
00080   ADUNCONST(df1b2variable,v)
00081   ADUNCONST(df1b2vector,x)
00082   df1b2vector tmp;
00083   int mmin=x.indexmin();
00084   int mmax=x.indexmax();
00085   tmp.noallocate(mmin,mmax);
00086   for (int i=mmin;i<=mmax;i++)
00087   {
00088     tmp(i)=v*x(i);
00089   }
00090   return tmp;
00091 }
00092 
00097 df1b2vector operator * (const df1b2variable& _v,const df1b2vector& _x)
00098 {
00099   ADUNCONST(df1b2variable,v)
00100   ADUNCONST(df1b2vector,x)
00101   df1b2vector tmp;
00102   int mmin=x.indexmin();
00103   int mmax=x.indexmax();
00104   tmp.noallocate(mmin,mmax);
00105   for (int i=mmin;i<=mmax;i++)
00106   {
00107     tmp(i)=v*x(i);
00108   }
00109   return tmp;
00110 }
00111 
00116 df1b2vector operator + (const df1b2vector& _x,const df1b2variable& _v)
00117 {
00118   ADUNCONST(df1b2variable,v)
00119   ADUNCONST(df1b2vector,x)
00120   df1b2vector tmp;
00121   int mmin=x.indexmin();
00122   int mmax=x.indexmax();
00123   tmp.noallocate(mmin,mmax);
00124   for (int i=mmin;i<=mmax;i++)
00125   {
00126     tmp(i)=v+x(i);
00127   }
00128   return tmp;
00129 }
00130 
00135 df1b2vector operator + (const df1b2variable& _v,const df1b2vector& _x)
00136 {
00137   ADUNCONST(df1b2variable,v)
00138   ADUNCONST(df1b2vector,x)
00139   df1b2vector tmp;
00140   int mmin=x.indexmin();
00141   int mmax=x.indexmax();
00142   tmp.noallocate(mmin,mmax);
00143   for (int i=mmin;i<=mmax;i++)
00144   {
00145     tmp(i)=v+x(i);
00146   }
00147   return tmp;
00148 }
00149 
00154 df1b2vector operator + (double v,const df1b2vector& _x)
00155 {
00156   ADUNCONST(df1b2vector,x)
00157   df1b2vector tmp;
00158   int mmin=x.indexmin();
00159   int mmax=x.indexmax();
00160   tmp.noallocate(mmin,mmax);
00161   for (int i=mmin;i<=mmax;i++)
00162   {
00163     tmp(i)=v+x(i);
00164   }
00165   return tmp;
00166 }
00167 
00172 df1b2vector operator + (const df1b2vector& _x,const double v)
00173 {
00174   ADUNCONST(df1b2vector,x)
00175   df1b2vector tmp;
00176   int mmin=x.indexmin();
00177   int mmax=x.indexmax();
00178   tmp.noallocate(mmin,mmax);
00179   for (int i=mmin;i<=mmax;i++)
00180   {
00181     tmp(i)=v+x(i);
00182   }
00183   return tmp;
00184 }
00185 
00190 df1b2vector operator - (const df1b2vector& _x,const double& v)
00191 {
00192   ADUNCONST(df1b2vector,x)
00193   df1b2vector tmp;
00194   int mmin=x.indexmin();
00195   int mmax=x.indexmax();
00196   tmp.noallocate(mmin,mmax);
00197   for (int i=mmin;i<=mmax;i++)
00198   {
00199     tmp(i)=v-x(i);
00200   }
00201   return tmp;
00202 }
00203 
00204 /*
00205 df1b2variable operator * (const df1b2vector& _v,const df1b2vector& _x)
00206 {
00207   ADUNCONST(df1b2vector,v)
00208   ADUNCONST(df1b2vector,x)
00209   df1b2variable tmp=0.0;
00210   int mmin=x.indexmin();
00211   int mmax=x.indexmax();
00212   for (int i=mmin;i<=mmax;i++)
00213   {
00214     tmp+=v(i)*x(i);
00215   }
00216   return tmp;
00217 }
00218 */
00219 
00224 df1b2variable operator * (const dvector& _v,const df1b2vector& _x)
00225 {
00226   ADUNCONST(dvector,v)
00227   ADUNCONST(df1b2vector,x)
00228   df1b2variable tmp=0.0;
00229   int mmin=x.indexmin();
00230   int mmax=x.indexmax();
00231   for (int i=mmin;i<=mmax;i++)
00232   {
00233     tmp+=v(i)*x(i);
00234   }
00235   return tmp;
00236 }
00237 
00242 df1b2variable operator * (const df1b2vector& _v,const dvector& _x)
00243 {
00244   ADUNCONST(dvector,x)
00245   ADUNCONST(df1b2vector,v)
00246   df1b2variable tmp=0.0;
00247   int mmin=x.indexmin();
00248   int mmax=x.indexmax();
00249   for (int i=mmin;i<=mmax;i++)
00250   {
00251     tmp+=v(i)*x(i);
00252   }
00253   return tmp;
00254 }
00255 
00260 int size_count(const df1b2vector& _x)
00261 {
00262   ADUNCONST(df1b2vector,x)
00263   return x.indexmax()-x.indexmin()+1;
00264 }
00265 
00270 int size_count(const df1b2matrix& _x)
00271 {
00272   ADUNCONST(df1b2matrix,x)
00273   int tmp=0;
00274   int mmin=x.indexmin();
00275   int mmax=x.indexmax();
00276   for (int i=mmin;i<=mmax;i++)
00277   {
00278     tmp+=size_count(x(i));
00279   }
00280   return tmp;
00281 }
00282 
00287 void df1b2vector::initialize(void)
00288 {
00289   int mmin=indexmin();
00290   int mmax=indexmax();
00291   for (int i=mmin;i<=mmax;i++)
00292   {
00293     //x(i).initialize();
00294     (*this)(i)=0.0;
00295   }
00296 }
00297 
00302 df1b2vector operator * (double v,const df1b2vector& _x)
00303 {
00304   ADUNCONST(df1b2vector,x)
00305   df1b2vector tmp;
00306   int mmin=x.indexmin();
00307   int mmax=x.indexmax();
00308   tmp.noallocate(mmin,mmax);
00309   for (int i=mmin;i<=mmax;i++)
00310   {
00311     tmp(i)=v*x(i);
00312   }
00313   return tmp;
00314 }
00315 
00320 df1b2vector operator * (const df1b2vector& _v,double x)
00321 {
00322   ADUNCONST(df1b2vector,v)
00323   df1b2vector tmp;
00324   int mmin=v.indexmin();
00325   int mmax=v.indexmax();
00326   tmp.noallocate(mmin,mmax);
00327   for (int i=mmin;i<=mmax;i++)
00328   {
00329     tmp(i)=v(i)*x;
00330   }
00331   return tmp;
00332 }