ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
f1b2vc4.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fun.h>
00012 
00017 df1b2matrix operator + (const df1b2matrix& _M,const df1b2variable& _x)
00018 {
00019   ADUNCONST(df1b2matrix,M)
00020   ADUNCONST(df1b2variable,x)
00021   int rmin=M.indexmin();
00022   int rmax=M.indexmax();
00023   df1b2matrix tmp(rmin,rmax);
00024   for (int i=rmin;i<=rmax;i++)
00025   {
00026     int cmin=M(i).indexmin();
00027     int cmax=M(i).indexmax();
00028     tmp(i).allocate(cmin,cmax);
00029     for (int j=cmin;j<=cmax;j++)
00030       tmp(i,j)=M(i,j)+x;
00031   }
00032   return tmp;
00033 }
00034 
00039 df1b2matrix& df1b2matrix::operator /= (const double x)
00040 {
00041   int rmin=indexmin();
00042   int rmax=indexmax();
00043   for (int i=rmin;i<=rmax;i++)
00044   {
00045     (*this)(i)/=x;
00046   }
00047   return (*this);
00048 }
00049 
00054 df1b2matrix& df1b2matrix::operator *= (const double x)
00055 {
00056   int rmin=indexmin();
00057   int rmax=indexmax();
00058   for (int i=rmin;i<=rmax;i++)
00059   {
00060     (*this)(i)*=x;
00061   }
00062   return (*this);
00063 }
00064 
00069 df1b2matrix& df1b2matrix::operator /= (const df1b2variable& _x)
00070 {
00071   ADUNCONST(df1b2variable,x)
00072   int rmin=indexmin();
00073   int rmax=indexmax();
00074   for (int i=rmin;i<=rmax;i++)
00075   {
00076     (*this)(i)/=x;
00077   }
00078   return (*this);
00079 }
00080 
00085 df1b2matrix& df1b2matrix::operator *= (const df1b2variable& _x)
00086 {
00087   ADUNCONST(df1b2variable,x)
00088   int rmin=indexmin();
00089   int rmax=indexmax();
00090   for (int i=rmin;i<=rmax;i++)
00091   {
00092     (*this)(i)*=x;
00093   }
00094   return (*this);
00095 }
00096 
00101 df1b2matrix& df1b2matrix::operator += (const df1b2matrix& _M)
00102 {
00103   ADUNCONST(df1b2matrix,M)
00104   int rmin=M.indexmin();
00105   int rmax=M.indexmax();
00106   if (rmin != M.indexmin() || rmax != M.indexmax())
00107   {
00108     cerr << "Unequal shapes in"
00109       " df1b2matrix& df1b2matrix::operator += (const df1b2matrix& _M)"
00110       << endl;
00111     ad_exit(1);
00112   }
00113   for (int i=rmin;i<=rmax;i++)
00114   {
00115     int cmin=(*this)(i).indexmin();
00116     int cmax=(*this)(i).indexmax();
00117     for (int j=cmin;j<=cmax;j++)
00118       (*this)(i,j)+=M(i,j);
00119   }
00120   return (*this);
00121 }
00122 
00127 df1b2matrix& df1b2matrix::operator -= (const df1b2matrix& _M)
00128 {
00129   ADUNCONST(df1b2matrix,M)
00130   int rmin=M.indexmin();
00131   int rmax=M.indexmax();
00132   if (rmin != M.indexmin() || rmax != M.indexmax())
00133   {
00134     cerr << "Unequal shapes in"
00135       " df1b2matrix& df1b2matrix::operator -= (const df1b2matrix& _M)"
00136       << endl;
00137     ad_exit(1);
00138   }
00139   for (int i=rmin;i<=rmax;i++)
00140   {
00141     int cmin=(*this)(i).indexmin();
00142     int cmax=(*this)(i).indexmax();
00143     for (int j=cmin;j<=cmax;j++)
00144       (*this)(i,j)-=M(i,j);
00145   }
00146   return (*this);
00147 }
00148 
00153 df1b2matrix operator + (const df1b2matrix& _M,const double x)
00154 {
00155   ADUNCONST(df1b2matrix,M)
00156   int rmin=M.indexmin();
00157   int rmax=M.indexmax();
00158   df1b2matrix tmp(rmin,rmax);
00159   for (int i=rmin;i<=rmax;i++)
00160   {
00161     int cmin=M(i).indexmin();
00162     int cmax=M(i).indexmax();
00163     tmp(i).allocate(cmin,cmax);
00164     for (int j=cmin;j<=cmax;j++)
00165       tmp(i,j)=M(i,j)+x;
00166   }
00167   return tmp;
00168 }
00169 
00174 df1b2matrix operator + (const df1b2variable& _x,const df1b2matrix& _M)
00175 {
00176   ADUNCONST(df1b2matrix,M)
00177   ADUNCONST(df1b2variable,x)
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     tmp(i).allocate(cmin,cmax);
00186     for (int j=cmin;j<=cmax;j++)
00187       tmp(i,j)=M(i,j)+x;
00188   }
00189   return tmp;
00190 }
00191 
00196 df1b2matrix operator + (const double x,const df1b2matrix& _M)
00197 {
00198   ADUNCONST(df1b2matrix,M)
00199   int rmin=M.indexmin();
00200   int rmax=M.indexmax();
00201   df1b2matrix tmp(rmin,rmax);
00202   for (int i=rmin;i<=rmax;i++)
00203   {
00204     int cmin=M(i).indexmin();
00205     int cmax=M(i).indexmax();
00206     tmp(i).allocate(cmin,cmax);
00207     for (int j=cmin;j<=cmax;j++)
00208       tmp(i,j)=M(i,j)+x;
00209   }
00210   return tmp;
00211 }
00212 
00217 df1b2matrix operator * (const df1b2variable& _x,const df1b2matrix& _M)
00218 {
00219   ADUNCONST(df1b2matrix,M)
00220   ADUNCONST(df1b2variable,x)
00221   int rmin=M.indexmin();
00222   int rmax=M.indexmax();
00223   df1b2matrix tmp(rmin,rmax);
00224   for (int i=rmin;i<=rmax;i++)
00225   {
00226     int cmin=M(i).indexmin();
00227     int cmax=M(i).indexmax();
00228     tmp(i).allocate(cmin,cmax);
00229     for (int j=cmin;j<=cmax;j++)
00230       tmp(i,j)=M(i,j)*x;
00231   }
00232   return tmp;
00233 }
00234 
00239 df1b2matrix operator * (const df1b2variable& _x,const dmatrix& _M)
00240 {
00241   ADUNCONST(dmatrix,M)
00242   ADUNCONST(df1b2variable,x)
00243   int rmin=M.indexmin();
00244   int rmax=M.indexmax();
00245   df1b2matrix tmp(rmin,rmax);
00246   for (int i=rmin;i<=rmax;i++)
00247   {
00248     int cmin=M(i).indexmin();
00249     int cmax=M(i).indexmax();
00250     tmp(i).allocate(cmin,cmax);
00251     for (int j=cmin;j<=cmax;j++)
00252       tmp(i,j)=M(i,j)*x;
00253   }
00254   return tmp;
00255 }
00256 
00261 df1b2matrix operator * (const df1b2matrix& _M,const df1b2variable& _x)
00262 {
00263   ADUNCONST(df1b2matrix,M)
00264   ADUNCONST(df1b2variable,x)
00265   int rmin=M.indexmin();
00266   int rmax=M.indexmax();
00267   df1b2matrix tmp(rmin,rmax);
00268   for (int i=rmin;i<=rmax;i++)
00269   {
00270     int cmin=M(i).indexmin();
00271     int cmax=M(i).indexmax();
00272     tmp(i).allocate(cmin,cmax);
00273     for (int j=cmin;j<=cmax;j++)
00274       tmp(i,j)=M(i,j)*x;
00275   }
00276   return tmp;
00277 }
00278 
00283 df1b2matrix operator * (const dmatrix& _M,const df1b2variable& _x)
00284 {
00285   ADUNCONST(dmatrix,M)
00286   ADUNCONST(df1b2variable,x)
00287   int rmin=M.indexmin();
00288   int rmax=M.indexmax();
00289   df1b2matrix tmp(rmin,rmax);
00290   for (int i=rmin;i<=rmax;i++)
00291   {
00292     int cmin=M(i).indexmin();
00293     int cmax=M(i).indexmax();
00294     tmp(i).allocate(cmin,cmax);
00295     for (int j=cmin;j<=cmax;j++)
00296       tmp(i,j)=M(i,j)*x;
00297   }
00298   return tmp;
00299 }
00300 
00305 df1b2matrix operator * (const df1b2matrix& _M,const double x)
00306 {
00307   return x*_M;
00308 }
00309 
00314 df1b2matrix operator * (const double x,const df1b2matrix& _M)
00315 {
00316   ADUNCONST(df1b2matrix,M)
00317   int rmin=M.indexmin();
00318   int rmax=M.indexmax();
00319   df1b2matrix tmp(rmin,rmax);
00320   for (int i=rmin;i<=rmax;i++)
00321   {
00322     int cmin=M(i).indexmin();
00323     int cmax=M(i).indexmax();
00324     tmp(i).allocate(cmin,cmax);
00325     for (int j=cmin;j<=cmax;j++)
00326       tmp(i,j)=M(i,j)*x;
00327   }
00328   return tmp;
00329 }
00330 
00335 df1b2matrix operator - (const df1b2variable& _x,const df1b2matrix& _M)
00336 {
00337   ADUNCONST(df1b2matrix,M)
00338   ADUNCONST(df1b2variable,x)
00339   int rmin=M.indexmin();
00340   int rmax=M.indexmax();
00341   df1b2matrix tmp(rmin,rmax);
00342   for (int i=rmin;i<=rmax;i++)
00343   {
00344     int cmin=M(i).indexmin();
00345     int cmax=M(i).indexmax();
00346     tmp(i).allocate(cmin,cmax);
00347     for (int j=cmin;j<=cmax;j++)
00348       tmp(i,j)=x-M(i,j);
00349   }
00350   return tmp;
00351 }
00352 
00357 df1b2matrix operator - (const double x,const df1b2matrix& _M)
00358 {
00359   ADUNCONST(df1b2matrix,M)
00360   int rmin=M.indexmin();
00361   int rmax=M.indexmax();
00362   df1b2matrix tmp(rmin,rmax);
00363   for (int i=rmin;i<=rmax;i++)
00364   {
00365     int cmin=M(i).indexmin();
00366     int cmax=M(i).indexmax();
00367     tmp(i).allocate(cmin,cmax);
00368     for (int j=cmin;j<=cmax;j++)
00369       tmp(i,j)=x-M(i,j);
00370   }
00371   return tmp;
00372 }
00373 
00378 df1b2matrix operator +(const df1b2matrix& _MM,const df1b2matrix& _NN)
00379 {
00380   df1b2matrix& M = (df1b2matrix&)_MM;
00381   df1b2matrix& N = (df1b2matrix&)_NN;
00382   int rmin=M.indexmin();
00383   int rmax=M.indexmax();
00384   df1b2matrix tmp(rmin,rmax);
00385   for (int i=rmin;i<=rmax;i++)
00386   {
00387     int cmin=M(i).indexmin();
00388     int cmax=M(i).indexmax();
00389     tmp(i).allocate(cmin,cmax);
00390     for (int j=cmin;j<=cmax;j++)
00391     {
00392       tmp(i,j)=M(i,j)+N(i,j);
00393     }
00394   }
00395   return tmp;
00396 }
00397 
00402 df1b2matrix operator +(const df1b2matrix& _M,const dmatrix& N)
00403 {
00404   ADUNCONST(df1b2matrix,M)
00405   int rmin=M.indexmin();
00406   int rmax=M.indexmax();
00407   df1b2matrix tmp(rmin,rmax);
00408   for (int i=rmin;i<=rmax;i++)
00409   {
00410     int cmin=M(i).indexmin();
00411     int cmax=M(i).indexmax();
00412     tmp(i).allocate(cmin,cmax);
00413     for (int j=cmin;j<=cmax;j++)
00414     {
00415       tmp(i,j)=M(i,j)+N(i,j);
00416     }
00417   }
00418   return tmp;
00419 }
00420 
00425 df1b2matrix operator +(const dmatrix& M,const df1b2matrix& _NN)
00426 {
00427   df1b2matrix& N = (df1b2matrix&)_NN;
00428   int rmin=M.indexmin();
00429   int rmax=M.indexmax();
00430   df1b2matrix tmp(rmin,rmax);
00431   for (int i=rmin;i<=rmax;i++)
00432   {
00433     int cmin=M(i).indexmin();
00434     int cmax=M(i).indexmax();
00435     tmp(i).allocate(cmin,cmax);
00436     for (int j=cmin;j<=cmax;j++)
00437     {
00438       tmp(i,j)=M(i,j)+N(i,j);
00439     }
00440   }
00441   return tmp;
00442 }
00443 
00448 df1b2matrix operator -(const df1b2matrix& _MM,const df1b2matrix& _NN)
00449 {
00450   df1b2matrix& M = (df1b2matrix&)_MM;
00451   df1b2matrix& N = (df1b2matrix&)_NN;
00452   int rmin=M.indexmin();
00453   int rmax=M.indexmax();
00454   df1b2matrix tmp(rmin,rmax);
00455   for (int i=rmin;i<=rmax;i++)
00456   {
00457     int cmin=M(i).indexmin();
00458     int cmax=M(i).indexmax();
00459     tmp(i).allocate(cmin,cmax);
00460     for (int j=cmin;j<=cmax;j++)
00461     {
00462       tmp(i,j)=M(i,j)-N(i,j);
00463     }
00464   }
00465   return tmp;
00466 }
00467 
00472 df1b2matrix operator -(const df1b2matrix& _M,const dmatrix& N)
00473 {
00474   ADUNCONST(df1b2matrix,M)
00475   int rmin=M.indexmin();
00476   int rmax=M.indexmax();
00477   df1b2matrix tmp(rmin,rmax);
00478   for (int i=rmin;i<=rmax;i++)
00479   {
00480     int cmin=M(i).indexmin();
00481     int cmax=M(i).indexmax();
00482     tmp(i).allocate(cmin,cmax);
00483     for (int j=cmin;j<=cmax;j++)
00484     {
00485       tmp(i,j)=M(i,j)-N(i,j);
00486     }
00487   }
00488   return tmp;
00489 }
00490 
00495 df1b2matrix operator -(const dmatrix& M,const df1b2matrix& _NN)
00496 {
00497   df1b2matrix& N = (df1b2matrix&)_NN;
00498   int rmin=M.indexmin();
00499   int rmax=M.indexmax();
00500   df1b2matrix tmp(rmin,rmax);
00501   for (int i=rmin;i<=rmax;i++)
00502   {
00503     int cmin=M(i).indexmin();
00504     int cmax=M(i).indexmax();
00505     tmp(i).allocate(cmin,cmax);
00506     for (int j=cmin;j<=cmax;j++)
00507     {
00508       tmp(i,j)=M(i,j)-N(i,j);
00509     }
00510   }
00511   return tmp;
00512 }