ADMB Documentation  11.1.2490
 All Classes Files Functions Variables Typedefs Friends Defines
f1b2vc5.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: f1b2vc5.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 void check_shape(const df1b2vector & _x,const dvector & _y,const char * s)
00018 {
00019   ADUNCONST(df1b2vector,x)
00020   ADUNCONST(dvector,y)
00021   if (x.indexmin() != y.indexmin() || x.indexmax() != y.indexmax())
00022   {
00023     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00024     ad_exit(1);
00025   }
00026 }
00027 
00032 void check_shape(const df1b2vector & _x,const df1b2vector & _y,const char * s)
00033 {
00034   ADUNCONST(df1b2vector,x)
00035   ADUNCONST(df1b2vector,y)
00036   if (x.indexmin() != y.indexmin() || x.indexmax() != y.indexmax())
00037   {
00038     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00039     ad_exit(1);
00040   }
00041 }
00042 
00047 void check_shape(const dvector & _x,const df1b2vector & _y,const char * s)
00048 {
00049   ADUNCONST(dvector,x)
00050   ADUNCONST(df1b2vector,y)
00051   if (x.indexmin() != y.indexmin() || x.indexmax() != y.indexmax())
00052   {
00053     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00054     ad_exit(1);
00055   }
00056 }
00057 
00062 void check_shape(const df1b2vector & _x,const df1b2matrix & _y,const char * s)
00063 {
00064   ADUNCONST(df1b2vector,x)
00065   ADUNCONST(df1b2matrix,y)
00066   if (x.indexmin() != y(y.indexmin()).indexmin() ||
00067     x.indexmax() != y(y.indexmin()).indexmax())
00068   {
00069     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00070     ad_exit(1);
00071   }
00072 }
00073 
00078 df1b2vector& df1b2vector::operator = (const df1b2vector& _x)
00079 {
00080   if (allocated())
00081   {
00082     ADUNCONST(df1b2vector,x)
00083     check_shape(*this,x,"df1b2vector& df1b2vector::operator =");
00084     int mmin=x.indexmin();
00085     int mmax=x.indexmax();
00086     for (int i=mmin;i<=mmax;i++)
00087     {
00088       (*this)(i)=x(i);
00089     }
00090   }
00091   else
00092   {
00093     copy(_x);
00094   }
00095   return *this;
00096 }
00097 
00102 df1b2vector& df1b2vector::operator = (const dvector& _x)
00103 {
00104   ADUNCONST(dvector,x)
00105   check_shape(*this,x,"df1b2vector& df1b2vector::operator =");
00106   int mmin=x.indexmin();
00107   int mmax=x.indexmax();
00108   for (int i=mmin;i<=mmax;i++) (*this)(i)=x(i);
00109   return *this;
00110 }
00111 
00116 df1b2vector& df1b2vector::operator = (const df1b2variable& _x)
00117 {
00118   ADUNCONST(df1b2variable,x)
00119   int mmin=indexmin();
00120   int mmax=indexmax();
00121   for (int i=mmin;i<=mmax;i++) (*this)(i)=x;
00122   return *this;
00123 }
00124 
00129 df1b2vector& df1b2vector::operator = (double x)
00130 {
00131   int mmin=indexmin();
00132   int mmax=indexmax();
00133   for (int i=mmin;i<=mmax;i++) (*this)(i)=x;
00134   return *this;
00135 }
00136 
00141 df1b2vector operator * (const dmatrix& _M,const df1b2vector& _x)
00142 {
00143   ADUNCONST(dmatrix,M)
00144   ADUNCONST(df1b2vector,x)
00145   //check_shape(x,M,"operator *");
00146   int rmin=M.indexmin();
00147   int rmax=M.indexmax();
00148   //int mmin=x.indexmin();
00149   //int mmax=x.indexmax();
00150   df1b2vector tmp(rmin,rmax);
00151   tmp.initialize();
00152   for (int i=rmin;i<=rmax;i++)
00153   {
00154     tmp(i)=M(i)*x;
00155   }
00156   return tmp;
00157 }
00158 
00163 df1b2vector operator * (const df1b2matrix& _M,const df1b2vector& _x)
00164 {
00165   ADUNCONST(df1b2matrix,M)
00166   ADUNCONST(df1b2vector,x)
00167   //check_shape(x,M,"operator *");
00168   int rmin=M.indexmin();
00169   int rmax=M.indexmax();
00170   //int mmin=x.indexmin();
00171   //int mmax=x.indexmax();
00172   df1b2vector tmp(rmin,rmax);
00173   tmp.initialize();
00174   for (int i=rmin;i<=rmax;i++)
00175   {
00176     tmp(i)=M(i)*x;
00177   }
00178   return tmp;
00179 }
00180 
00185 df1b2vector operator * (const df1b2vector& _x,const df1b2matrix& _M)
00186 {
00187   ADUNCONST(df1b2matrix,M)
00188   ADUNCONST(df1b2vector,x)
00189   //check_shape(x,M,"operator *");
00190   int rmin=M.indexmin();
00191   int rmax=M.indexmax();
00192   int mmin=x.indexmin();
00193   int mmax=x.indexmax();
00194   df1b2vector tmp(rmin,rmax);
00195   tmp.initialize();
00196   for (int i=rmin;i<=rmax;i++)
00197   {
00198     for (int j=mmin;j<=mmax;j++)
00199       tmp(i)+=M(j,i)*x(j);
00200   }
00201   return tmp;
00202 }
00203 
00208 df1b2vector operator * (const df1b2vector& _x,const dmatrix& _M)
00209 {
00210   ADUNCONST(dmatrix,M)
00211   ADUNCONST(df1b2vector,x)
00212   //check_shape(x,M,"operator *");
00213   int rmin=M.indexmin();
00214   int rmax=M.indexmax();
00215   int mmin=x.indexmin();
00216   int mmax=x.indexmax();
00217   df1b2vector tmp(rmin,rmax);
00218   tmp.initialize();
00219   for (int i=rmin;i<=rmax;i++)
00220   {
00221     for (int j=mmin;j<=mmax;j++)
00222       tmp(i)+=M(j,i)*x(j);
00223   }
00224   return tmp;
00225 }
00226 
00231 df1b2vector operator * (const dvector& _x,const df1b2matrix& _M)
00232 {
00233   ADUNCONST(df1b2matrix,M)
00234   ADUNCONST(dvector,x)
00235   //check_shape(x,M,"operator *");
00236   int rmin=M.indexmin();
00237   int rmax=M.indexmax();
00238   int mmin=x.indexmin();
00239   int mmax=x.indexmax();
00240   df1b2vector tmp(rmin,rmax);
00241   tmp.initialize();
00242   for (int i=rmin;i<=rmax;i++)
00243   {
00244     for (int j=mmin;j<=mmax;j++)
00245       tmp(i)+=M(j,i)*x(j);
00246   }
00247   return tmp;
00248 }
00249 
00254 df1b2matrix operator * (const df1b2matrix& _MM,const df1b2matrix& _NN)
00255 {
00256   df1b2matrix& M = (df1b2matrix&)_MM;
00257   df1b2matrix& N = (df1b2matrix&)_NN;
00258   //check_shape(x,M,"operator *");
00259   int rmin=M.indexmin();
00260   int rmax=M.indexmax();
00261   int kmin=N.rowmin();
00262   int kmax=N.rowmax();
00263   int cmin=N(kmin).indexmin();
00264   int cmax=N(kmin).indexmax();
00265   if (M(rmin).indexmin()!=N.indexmin() || M(rmin).indexmax()!=N.indexmax())
00266   {
00267     cerr << "incompatible matrix sizes" << endl;
00268     ad_exit(1);
00269   }
00270   df1b2matrix tmp(rmin,rmax,cmin,cmax);
00271   tmp.initialize();
00272   for (int i=rmin;i<=rmax;i++)
00273   {
00274     for (int j=cmin;j<=cmax;j++)
00275     {
00276       for (int k=kmin;k<=kmax;k++)
00277       {
00278         tmp(i,j)+=M(i,k)*N(k,j);
00279       }
00280     }
00281   }
00282   return tmp;
00283 }
00284 
00289 df1b2vector operator * (const df1b2matrix& _M,const dvector& _x)
00290 {
00291   ADUNCONST(df1b2matrix,M)
00292   ADUNCONST(dvector,x)
00293   //check_shape(x,M,"operator *");
00294   int rmin=M.indexmin();
00295   int rmax=M.indexmax();
00296   int cmin=x.indexmin();
00297   int cmax=x.indexmax();
00298   df1b2vector tmp(rmin,rmax);
00299   for (int i=rmin;i<=rmax;i++)
00300     for (int j=cmin;j<=cmax;j++)
00301       tmp(i)+=M(i,j)*x(j);
00302   return tmp;
00303 }
00304 
00309 df1b2matrix elem_prod(const df1b2matrix& _MM,const df1b2matrix& _NN)
00310 {
00311   df1b2matrix& M = (df1b2matrix&)_MM;
00312   df1b2matrix& N = (df1b2matrix&)_NN;
00313   int rmin=M.indexmin();
00314   int rmax=M.indexmax();
00315   df1b2matrix tmp(rmin,rmax);
00316   for (int i=rmin;i<=rmax;i++)
00317   {
00318     int cmin=M(i).indexmin();
00319     int cmax=M(i).indexmax();
00320     tmp(i).noallocate(cmin,cmax);
00321     for (int j=cmin;j<=cmax;j++)
00322     {
00323       tmp(i,j)=M(i,j)*N(i,j);
00324     }
00325   }
00326   return tmp;
00327 }
00328 
00333 df1b2matrix elem_prod(const dmatrix& _MM,const df1b2matrix& _NN)
00334 {
00335   dmatrix& M = (dmatrix&)_MM;
00336   df1b2matrix& N = (df1b2matrix&)_NN;
00337   int rmin=M.indexmin();
00338   int rmax=M.indexmax();
00339   df1b2matrix tmp(rmin,rmax);
00340   for (int i=rmin;i<=rmax;i++)
00341   {
00342     int cmin=M(i).indexmin();
00343     int cmax=M(i).indexmax();
00344     tmp(i).noallocate(cmin,cmax);
00345     for (int j=cmin;j<=cmax;j++)
00346     {
00347       tmp(i,j)=M(i,j)*N(i,j);
00348     }
00349   }
00350   return tmp;
00351 }
00352 
00357 df1b2matrix elem_prod(const df1b2matrix& _MM,const dmatrix& _NN)
00358 {
00359   df1b2matrix& M = (df1b2matrix&)_MM;
00360   dmatrix& N = (dmatrix&)_NN;
00361   int rmin=M.indexmin();
00362   int rmax=M.indexmax();
00363   df1b2matrix tmp(rmin,rmax);
00364   for (int i=rmin;i<=rmax;i++)
00365   {
00366     int cmin=M(i).indexmin();
00367     int cmax=M(i).indexmax();
00368     tmp(i).noallocate(cmin,cmax);
00369     for (int j=cmin;j<=cmax;j++)
00370     {
00371       tmp(i,j)=M(i,j)*N(i,j);
00372     }
00373   }
00374   return tmp;
00375 }
00376 
00381 df1b2matrix elem_div(const df1b2matrix& _MM,const df1b2matrix& _NN)
00382 {
00383   df1b2matrix& M = (df1b2matrix&)_MM;
00384   df1b2matrix& N = (df1b2matrix&)_NN;
00385   int rmin=M.indexmin();
00386   int rmax=M.indexmax();
00387   df1b2matrix tmp(rmin,rmax);
00388   for (int i=rmin;i<=rmax;i++)
00389   {
00390     int cmin=M(i).indexmin();
00391     int cmax=M(i).indexmax();
00392     tmp(i).noallocate(cmin,cmax);
00393     for (int j=cmin;j<=cmax;j++)
00394     {
00395       tmp(i,j)=M(i,j)/N(i,j);
00396     }
00397   }
00398   return tmp;
00399 }
00400 
00405 df1b2matrix elem_div(const dmatrix& _MM,const df1b2matrix& _NN)
00406 {
00407   dmatrix& M = (dmatrix&)_MM;
00408   df1b2matrix& N = (df1b2matrix&)_NN;
00409   int rmin=M.indexmin();
00410   int rmax=M.indexmax();
00411   df1b2matrix tmp(rmin,rmax);
00412   for (int i=rmin;i<=rmax;i++)
00413   {
00414     int cmin=M(i).indexmin();
00415     int cmax=M(i).indexmax();
00416     tmp(i).noallocate(cmin,cmax);
00417     for (int j=cmin;j<=cmax;j++)
00418     {
00419       tmp(i,j)=M(i,j)/N(i,j);
00420     }
00421   }
00422   return tmp;
00423 }
00424 
00429 df1b2matrix elem_div(const df1b2matrix& _MM,const dmatrix& _NN)
00430 {
00431   df1b2matrix& M = (df1b2matrix&)_MM;
00432   dmatrix& N = (dmatrix&)_NN;
00433   int rmin=M.indexmin();
00434   int rmax=M.indexmax();
00435   df1b2matrix tmp(rmin,rmax);
00436   for (int i=rmin;i<=rmax;i++)
00437   {
00438     int cmin=M(i).indexmin();
00439     int cmax=M(i).indexmax();
00440     tmp(i).noallocate(cmin,cmax);
00441     for (int j=cmin;j<=cmax;j++)
00442     {
00443       tmp(i,j)=M(i,j)/N(i,j);
00444     }
00445   }
00446   return tmp;
00447 }
00448 
00453 df1b2vector elem_div(const dvector& _v,const df1b2vector& _w)
00454 {
00455   ADUNCONST(dvector,v)
00456   ADUNCONST(df1b2vector,w)
00457   int rmin=v.indexmin();
00458   int rmax=v.indexmax();
00459   df1b2vector tmp;
00460   tmp.noallocate(rmin,rmax);
00461   for (int i=rmin;i<=rmax;i++)
00462   {
00463     tmp(i)=v(i)/w(i);
00464   }
00465   return tmp;
00466 }
00467 
00472 df1b2vector elem_div(const df1b2vector& _v,const df1b2vector& _w)
00473 {
00474   ADUNCONST(df1b2vector,v)
00475   ADUNCONST(df1b2vector,w)
00476   int rmin=v.indexmin();
00477   int rmax=v.indexmax();
00478   df1b2vector tmp;
00479   tmp.noallocate(rmin,rmax);
00480   for (int i=rmin;i<=rmax;i++)
00481   {
00482     tmp(i)=v(i)/w(i);
00483   }
00484   return tmp;
00485 }
00486 
00491 df1b2vector elem_prod(const df1b2vector& _v,const df1b2vector& _w)
00492 {
00493   ADUNCONST(df1b2vector,v)
00494   ADUNCONST(df1b2vector,w)
00495   int rmin=v.indexmin();
00496   int rmax=v.indexmax();
00497   df1b2vector tmp;
00498   tmp.noallocate(rmin,rmax);
00499   for (int i=rmin;i<=rmax;i++)
00500   {
00501     tmp(i)=v(i)*w(i);
00502   }
00503   return tmp;
00504 }
00505 
00510 df1b2vector elem_prod(const df1b2vector& _v,const dvector& _w)
00511 {
00512   ADUNCONST(df1b2vector,v)
00513   ADUNCONST(dvector,w)
00514   int rmin=v.indexmin();
00515   int rmax=v.indexmax();
00516   df1b2vector tmp;
00517   tmp.noallocate(rmin,rmax);
00518   for (int i=rmin;i<=rmax;i++)
00519   {
00520     tmp(i)=v(i)*w(i);
00521   }
00522   return tmp;
00523 }
00524 
00529 df1b2vector elem_prod(const dvector& _v,const df1b2vector& _w)
00530 {
00531   ADUNCONST(dvector,v)
00532   ADUNCONST(df1b2vector,w)
00533   int rmin=v.indexmin();
00534   int rmax=v.indexmax();
00535   df1b2vector tmp;
00536   tmp.noallocate(rmin,rmax);
00537   for (int i=rmin;i<=rmax;i++)
00538   {
00539     tmp(i)=v(i)*w(i);
00540   }
00541   return tmp;
00542 }
00543 
00548 df1b2vector elem_div(const df1b2vector& _v,const dvector& _w)
00549 {
00550   ADUNCONST(df1b2vector,v)
00551   ADUNCONST(dvector,w)
00552   int rmin=v.indexmin();
00553   int rmax=v.indexmax();
00554   df1b2vector tmp;
00555   tmp.noallocate(rmin,rmax);
00556   for (int i=rmin;i<=rmax;i++)
00557   {
00558     tmp(i)=v(i)/w(i);
00559   }
00560   return tmp;
00561 }
00562 
00567 df1b2matrix::df1b2matrix(int nrl,int nrh,int ncl,int nch)
00568 {
00569   if (nrl>nrh)
00570   {
00571     allocate();
00572   }
00573   else
00574   {
00575     allocate(nrl,nrh,ncl,nch);
00576   }
00577 }
00578 
00583 df1b2matrix::df1b2matrix(int nrl,int nrh)
00584 {
00585   if (nrl>nrh)
00586   {
00587     allocate();
00588   }
00589   else
00590   {
00591     allocate(nrl,nrh);
00592   }
00593 }
00594 
00599 df1b2matrix::df1b2matrix(int nrl,int nrh,const index_type& ncl,
00600   const index_type& nch)
00601 {
00602   if (nrl>nrh)
00603   {
00604     allocate();
00605   }
00606   else
00607   {
00608     allocate(nrl,nrh,ncl,nch);
00609   }
00610 }
00611 
00616 df1b2matrix::df1b2matrix(void)
00617 {
00618   allocate();
00619 }
00620 
00625 void df1b2matrix::allocate(int nrl,int nrh,int ncl,int nch,const char * s)
00626 {
00627   allocate(nrl,nrh,ncl,nch);
00628 }
00629 
00634 void df1b2matrix::allocate(int nrl,int nrh,const index_type& ncl,
00635   const index_type& nch,const char * s)
00636 {
00637   allocate(nrl,nrh,ncl,nch);
00638 }
00639 
00644 void df1b2matrix::allocate(int nrl,int nrh,int ncl,int nch)
00645 {
00646   index_min=nrl;
00647   index_max=nrh;
00648   int rs=size();
00649   if ( (v = new df1b2vector[rs]) == 0)
00650   {
00651       cerr << " Error allocating memory in df1b2matrix contructor\n";
00652       ad_exit(21);
00653   }
00654   if ( (shape=new mat_shapex(v)) == 0)
00655   {
00656     cerr << " Error allocating memory in df1b2matrix contructor\n";
00657   }
00658   v -= indexmin();
00659   for (int i=nrl; i<=nrh; i++)
00660   {
00661     v[i].allocate(ncl,nch);
00662   }
00663 }
00664 
00669 void df1b2matrix::allocate(int nrl,int nrh,const index_type& ncl,
00670   const index_type& nch)
00671 {
00672   index_min=nrl;
00673   index_max=nrh;
00674   int rs=size();
00675   if ( (v = new df1b2vector[rs]) == 0)
00676   {
00677       cerr << " Error allocating memory in df1b2matrix contructor\n";
00678       ad_exit(21);
00679   }
00680   if ( (shape=new mat_shapex(v)) == 0)
00681   {
00682     cerr << " Error allocating memory in df1b2matrix contructor\n";
00683   }
00684   v -= indexmin();
00685   for (int i=nrl; i<=nrh; i++)
00686   {
00687     v[i].allocate(ncl(i),nch(i));
00688   }
00689 }
00690 
00695 df1b2matrix::df1b2matrix(const df1b2matrix & x)
00696 {
00697   index_min=x.index_min;
00698   index_max=x.index_max;
00699   v=x.v;
00700   shape=x.shape;
00701   if (shape) (shape->ncopies)++;
00702 }
00703 
00708 void df1b2matrix::allocate(int nrl,int nrh)
00709 {
00710   index_min=nrl;
00711   index_max=nrh;
00712   int rs=size();
00713   if ( (v = new df1b2vector[rs]) == 0)
00714   {
00715       cerr << " Error allocating memory in df1b2matrix contructor\n";
00716       ad_exit(21);
00717   }
00718   if ( (shape=new mat_shapex(v)) == 0)
00719   {
00720     cerr << " Error allocating memory in df1b2matrix contructor\n";
00721   }
00722   v -= indexmin();
00723   /*
00724   for (int i=nrl; i<=nrh; i++)
00725   {
00726     v[i].allocate(ncl,nch);
00727   }
00728   */
00729 }
00730 
00735 df1b2matrix::~df1b2matrix()
00736 {
00737   if (shape)
00738   {
00739     if (shape->ncopies)
00740     {
00741       (shape->ncopies)--;
00742     }
00743     else
00744     {
00745       deallocate();
00746     }
00747   }
00748 }
00749 
00754 void df1b2matrix::deallocate()
00755 {
00756   if (shape)
00757   {
00758     v=(df1b2vector*)(shape->get_pointer());
00759     delete [] v;
00760     v=0;
00761     delete shape;
00762     shape=0;
00763   }
00764 }
00765 
00770 void df1b2matrix::allocate(void)
00771 {
00772   index_min=1;
00773   index_max=0;
00774   v=0;
00775   shape=0;
00776 }
00777 
00781 void df1b2matrix::colfill(const int j, const df1b2vector& v)
00782 {
00783   //RETURN_ARRAYS_INCREMENT();   makes no sense for df1b2 stuff
00784   for (int i=rowmin(); i<=rowmax(); i++)
00785   {
00786     (*this)[i][j]=v[i];
00787   }
00788   //RETURN_ARRAYS_DECREMENT();
00789 }
00790 
00795 df1b2variable sum(const df1b2vector& _x)
00796 {
00797   ADUNCONST(df1b2vector,x)
00798   df1b2variable tmp;
00799   tmp=0.0;
00800   int mmin=x.indexmin();
00801   int mmax=x.indexmax();
00802   for (int i=mmin;i<=mmax;i++)
00803   {
00804     tmp+=x(i);
00805   }
00806   return tmp;
00807 }
00808 
00813 df1b2variable mean(const df1b2vector& _x)
00814 {
00815   ADUNCONST(df1b2vector,x)
00816   df1b2variable tmp;
00817   tmp=0.0;
00818   int mmin=x.indexmin();
00819   int mmax=x.indexmax();
00820   double fn=mmax-mmin+1;
00821   for (int i=mmin;i<=mmax;i++)
00822   {
00823     tmp+=x(i);
00824   }
00825   return tmp/fn;
00826 }
00827 
00832 df1b2variable norm2(const df1b2vector& _x)
00833 {
00834   ADUNCONST(df1b2vector,x)
00835   df1b2variable tmp;
00836   tmp=0.0;
00837   int mmin=x.indexmin();
00838   int mmax=x.indexmax();
00839   for (int i=mmin;i<=mmax;i++)
00840   {
00841     tmp+=square(x(i));
00842   }
00843   return tmp;
00844 }
00845 df1b2variable sumsq(const df1b2vector& _x) {return(norm2(_x));}
00846 
00851 df1b2variable norm(const df1b2vector& _x)
00852 {
00853   ADUNCONST(df1b2vector,x)
00854   df1b2variable tmp;
00855   tmp=0.0;
00856   int mmin=x.indexmin();
00857   int mmax=x.indexmax();
00858   for (int i=mmin;i<=mmax;i++)
00859   {
00860     tmp+=square(x(i));
00861   }
00862   return sqrt(tmp);
00863 }
00864 
00869 df1b2variable norm2(const df1b2matrix& _x)
00870 {
00871   ADUNCONST(df1b2matrix,x)
00872   df1b2variable tmp;
00873   tmp=0.0;
00874   int mmin=x.indexmin();
00875   int mmax=x.indexmax();
00876   for (int i=mmin;i<=mmax;i++)
00877   {
00878     tmp+=norm2(x(i));
00879   }
00880   return tmp;
00881 }
00882 df1b2variable sumsq(const df1b2matrix& _x) {return(norm2(_x));}
00883 
00888 df1b2variable norm(const df1b2matrix& _x)
00889 {
00890   ADUNCONST(df1b2matrix,x)
00891   df1b2variable tmp;
00892   tmp=0.0;
00893   int mmin=x.indexmin();
00894   int mmax=x.indexmax();
00895   for (int i=mmin;i<=mmax;i++)
00896   {
00897     tmp+=norm2(x(i));
00898   }
00899   return sqrt(tmp);
00900 }
00901 
00906 df1b2variable sum(const df1b2matrix& _x)
00907 {
00908   ADUNCONST(df1b2matrix,x)
00909   df1b2variable tmp;
00910   tmp=0.0;
00911   int mmin=x.indexmin();
00912   int mmax=x.indexmax();
00913   for (int i=mmin;i<=mmax;i++)
00914   {
00915     tmp+=sum(x(i));
00916   }
00917   return tmp;
00918 }
00919 
00924 df1b2variable mean(const df1b2matrix& _x)
00925 {
00926   ADUNCONST(df1b2matrix,x)
00927   df1b2variable tmp;
00928   tmp=0.0;
00929   int mmin=x.indexmin();
00930   int mmax=x.indexmax();
00931   int nitems=0;
00932   for (int i=mmin;i<=mmax;i++)
00933   {
00934     tmp+=sum(x(i));
00935     nitems+=x(i).indexmax()-x(i).indexmin()+1;
00936   }
00937   return tmp/nitems;
00938 }