ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
f1b2vc5.cpp
Go to the documentation of this file.
00001 
00006 #include <df1b2fun.h>
00007 #ifndef OPT_LIB
00008   #include <cassert>
00009 #endif
00010 
00015 void check_shape(const df1b2vector & _x,const dvector & _y,const char * s)
00016 {
00017   ADUNCONST(df1b2vector,x)
00018   ADUNCONST(dvector,y)
00019   if (x.indexmin() != y.indexmin() || x.indexmax() != y.indexmax())
00020   {
00021     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00022     ad_exit(1);
00023   }
00024 }
00025 
00030 void check_shape(const df1b2vector & _x,const df1b2vector & _y,const char * s)
00031 {
00032   ADUNCONST(df1b2vector,x)
00033   ADUNCONST(df1b2vector,y)
00034   if (x.indexmin() != y.indexmin() || x.indexmax() != y.indexmax())
00035   {
00036     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00037     ad_exit(1);
00038   }
00039 }
00040 
00045 void check_shape(const dvector & _x,const df1b2vector & _y,const char * s)
00046 {
00047   ADUNCONST(dvector,x)
00048   ADUNCONST(df1b2vector,y)
00049   if (x.indexmin() != y.indexmin() || x.indexmax() != y.indexmax())
00050   {
00051     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00052     ad_exit(1);
00053   }
00054 }
00055 
00060 void check_shape(const df1b2vector & _x,const df1b2matrix & _y,const char * s)
00061 {
00062   ADUNCONST(df1b2vector,x)
00063   ADUNCONST(df1b2matrix,y)
00064   if (x.indexmin() != y(y.indexmin()).indexmin() ||
00065     x.indexmax() != y(y.indexmin()).indexmax())
00066   {
00067     cerr << "Incompatible shapes in df1b2vector function" << s << endl;
00068     ad_exit(1);
00069   }
00070 }
00071 
00076 df1b2vector& df1b2vector::operator = (const df1b2vector& _x)
00077 {
00078   if (allocated())
00079   {
00080     ADUNCONST(df1b2vector,x)
00081     check_shape(*this,x,"df1b2vector& df1b2vector::operator =");
00082     int mmin=x.indexmin();
00083     int mmax=x.indexmax();
00084     for (int i=mmin;i<=mmax;i++)
00085     {
00086       (*this)(i)=x(i);
00087     }
00088   }
00089   else
00090   {
00091     copy(_x);
00092   }
00093   return *this;
00094 }
00095 
00100 df1b2vector& df1b2vector::operator = (const dvector& _x)
00101 {
00102   ADUNCONST(dvector,x)
00103   check_shape(*this,x,"df1b2vector& df1b2vector::operator =");
00104   int mmin=x.indexmin();
00105   int mmax=x.indexmax();
00106   for (int i=mmin;i<=mmax;i++) (*this)(i)=x(i);
00107   return *this;
00108 }
00109 
00114 df1b2vector& df1b2vector::operator = (const df1b2variable& _x)
00115 {
00116   ADUNCONST(df1b2variable,x)
00117   int mmin=indexmin();
00118   int mmax=indexmax();
00119   for (int i=mmin;i<=mmax;i++) (*this)(i)=x;
00120   return *this;
00121 }
00122 
00127 df1b2vector& df1b2vector::operator = (double x)
00128 {
00129   int mmin=indexmin();
00130   int mmax=indexmax();
00131   for (int i=mmin;i<=mmax;i++) (*this)(i)=x;
00132   return *this;
00133 }
00134 
00139 df1b2vector operator * (const dmatrix& _M,const df1b2vector& _x)
00140 {
00141   ADUNCONST(dmatrix,M)
00142   ADUNCONST(df1b2vector,x)
00143   //check_shape(x,M,"operator *");
00144   int rmin=M.indexmin();
00145   int rmax=M.indexmax();
00146   //int mmin=x.indexmin();
00147   //int mmax=x.indexmax();
00148   df1b2vector tmp(rmin,rmax);
00149   tmp.initialize();
00150   for (int i=rmin;i<=rmax;i++)
00151   {
00152     tmp(i)=M(i)*x;
00153   }
00154   return tmp;
00155 }
00156 
00161 df1b2vector operator * (const df1b2matrix& _M,const df1b2vector& _x)
00162 {
00163   ADUNCONST(df1b2matrix,M)
00164   ADUNCONST(df1b2vector,x)
00165   //check_shape(x,M,"operator *");
00166   int rmin=M.indexmin();
00167   int rmax=M.indexmax();
00168   //int mmin=x.indexmin();
00169   //int mmax=x.indexmax();
00170   df1b2vector tmp(rmin,rmax);
00171   tmp.initialize();
00172   for (int i=rmin;i<=rmax;i++)
00173   {
00174     tmp(i)=M(i)*x;
00175   }
00176   return tmp;
00177 }
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 cmin = M(rmin).indexmin();
00192   int cmax = M(rmin).indexmax();
00193   int mmin = x.indexmin();
00194   int mmax = x.indexmax();
00195   df1b2vector tmp(cmin, cmax);
00196 #ifndef OPT_LIB
00197   tmp.initialize();
00198 #endif
00199   for (int i = cmin; i <= cmax; ++i)
00200   {
00201     for (int j = mmin; j <= mmax; ++j)
00202     {
00203       tmp(i) += M(j, i) * x(j);
00204     }
00205   }
00206   return tmp;
00207 }
00215 df1b2vector operator*(const df1b2vector& _x, const dmatrix& _M)
00216 {
00217   ADUNCONST(dmatrix,M)
00218   ADUNCONST(df1b2vector,x)
00219   //check_shape(x,M,"operator *");
00220   int rmin = M.indexmin();
00221   int cmin = M(rmin).indexmin();
00222   int cmax = M(rmin).indexmax();
00223   int mmin = x.indexmin();
00224   int mmax = x.indexmax();
00225   df1b2vector tmp(cmin, cmax);
00226 #ifndef OPT_LIB
00227   tmp.initialize();
00228 #endif
00229   for (int i = cmin; i <= cmax; ++i)
00230   {
00231     for (int j = mmin; j <= mmax; ++j)
00232     {
00233       tmp(i) += M(j, i) * x(j);
00234     }
00235   }
00236   return tmp;
00237 }
00245 df1b2vector operator*(const dvector& _x, const df1b2matrix& _M)
00246 {
00247   ADUNCONST(df1b2matrix,M)
00248   ADUNCONST(dvector,x)
00249   //check_shape(x,M,"operator *");
00250   int rmin = M.indexmin();
00251   int cmin = M(rmin).indexmin();
00252   int cmax = M(rmin).indexmax();
00253   int mmin = x.indexmin();
00254   int mmax = x.indexmax();
00255   df1b2vector tmp(cmin, cmax);
00256 #ifndef OPT_LIB
00257   tmp.initialize();
00258 #endif
00259   for (int i = cmin; i <= cmax; ++i)
00260   {
00261     for (int j = mmin; j <= mmax; ++j)
00262     {
00263       tmp(i) += M(j, i) * x(j);
00264     }
00265   }
00266   return tmp;
00267 }
00268 
00273 df1b2matrix operator * (const df1b2matrix& _MM,const df1b2matrix& _NN)
00274 {
00275   df1b2matrix& M = (df1b2matrix&)_MM;
00276   df1b2matrix& N = (df1b2matrix&)_NN;
00277   //check_shape(x,M,"operator *");
00278   int rmin=M.indexmin();
00279   int rmax=M.indexmax();
00280   int kmin=N.rowmin();
00281   int kmax=N.rowmax();
00282   int cmin=N(kmin).indexmin();
00283   int cmax=N(kmin).indexmax();
00284   if (M(rmin).indexmin()!=N.indexmin() || M(rmin).indexmax()!=N.indexmax())
00285   {
00286     cerr << "incompatible matrix sizes" << endl;
00287     ad_exit(1);
00288   }
00289   df1b2matrix tmp(rmin,rmax,cmin,cmax);
00290   tmp.initialize();
00291   for (int i=rmin;i<=rmax;i++)
00292   {
00293     for (int j=cmin;j<=cmax;j++)
00294     {
00295       for (int k=kmin;k<=kmax;k++)
00296       {
00297         tmp(i,j)+=M(i,k)*N(k,j);
00298       }
00299     }
00300   }
00301   return tmp;
00302 }
00303 
00308 df1b2vector operator * (const df1b2matrix& _M,const dvector& _x)
00309 {
00310   ADUNCONST(df1b2matrix,M)
00311   ADUNCONST(dvector,x)
00312   //check_shape(x,M,"operator *");
00313   int rmin=M.indexmin();
00314   int rmax=M.indexmax();
00315   int cmin=x.indexmin();
00316   int cmax=x.indexmax();
00317   df1b2vector tmp(rmin,rmax);
00318   for (int i=rmin;i<=rmax;i++)
00319     for (int j=cmin;j<=cmax;j++)
00320       tmp(i)+=M(i,j)*x(j);
00321   return tmp;
00322 }
00323 
00328 df1b2matrix elem_prod(const df1b2matrix& _MM,const df1b2matrix& _NN)
00329 {
00330   df1b2matrix& M = (df1b2matrix&)_MM;
00331   df1b2matrix& N = (df1b2matrix&)_NN;
00332   int rmin=M.indexmin();
00333   int rmax=M.indexmax();
00334   df1b2matrix tmp(rmin,rmax);
00335   for (int i=rmin;i<=rmax;i++)
00336   {
00337     int cmin=M(i).indexmin();
00338     int cmax=M(i).indexmax();
00339     tmp(i).noallocate(cmin,cmax);
00340     for (int j=cmin;j<=cmax;j++)
00341     {
00342       tmp(i,j)=M(i,j)*N(i,j);
00343     }
00344   }
00345   return tmp;
00346 }
00347 
00352 df1b2matrix elem_prod(const dmatrix& _MM,const df1b2matrix& _NN)
00353 {
00354   dmatrix& M = (dmatrix&)_MM;
00355   df1b2matrix& N = (df1b2matrix&)_NN;
00356   int rmin=M.indexmin();
00357   int rmax=M.indexmax();
00358   df1b2matrix tmp(rmin,rmax);
00359   for (int i=rmin;i<=rmax;i++)
00360   {
00361     int cmin=M(i).indexmin();
00362     int cmax=M(i).indexmax();
00363     tmp(i).noallocate(cmin,cmax);
00364     for (int j=cmin;j<=cmax;j++)
00365     {
00366       tmp(i,j)=M(i,j)*N(i,j);
00367     }
00368   }
00369   return tmp;
00370 }
00371 
00376 df1b2matrix elem_prod(const df1b2matrix& _MM,const dmatrix& _NN)
00377 {
00378   df1b2matrix& M = (df1b2matrix&)_MM;
00379   dmatrix& N = (dmatrix&)_NN;
00380   int rmin=M.indexmin();
00381   int rmax=M.indexmax();
00382   df1b2matrix tmp(rmin,rmax);
00383   for (int i=rmin;i<=rmax;i++)
00384   {
00385     int cmin=M(i).indexmin();
00386     int cmax=M(i).indexmax();
00387     tmp(i).noallocate(cmin,cmax);
00388     for (int j=cmin;j<=cmax;j++)
00389     {
00390       tmp(i,j)=M(i,j)*N(i,j);
00391     }
00392   }
00393   return tmp;
00394 }
00395 
00400 df1b2matrix elem_div(const df1b2matrix& _MM,const df1b2matrix& _NN)
00401 {
00402   df1b2matrix& M = (df1b2matrix&)_MM;
00403   df1b2matrix& N = (df1b2matrix&)_NN;
00404   int rmin=M.indexmin();
00405   int rmax=M.indexmax();
00406   df1b2matrix tmp(rmin,rmax);
00407   for (int i=rmin;i<=rmax;i++)
00408   {
00409     int cmin=M(i).indexmin();
00410     int cmax=M(i).indexmax();
00411     tmp(i).noallocate(cmin,cmax);
00412     for (int j=cmin;j<=cmax;j++)
00413     {
00414       tmp(i,j)=M(i,j)/N(i,j);
00415     }
00416   }
00417   return tmp;
00418 }
00419 
00424 df1b2matrix elem_div(const dmatrix& _MM,const df1b2matrix& _NN)
00425 {
00426   dmatrix& M = (dmatrix&)_MM;
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).noallocate(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 elem_div(const df1b2matrix& _MM,const dmatrix& _NN)
00449 {
00450   df1b2matrix& M = (df1b2matrix&)_MM;
00451   dmatrix& N = (dmatrix&)_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).noallocate(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 df1b2vector elem_div(const dvector& _v,const df1b2vector& _w)
00473 {
00474   ADUNCONST(dvector,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_div(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 df1b2vector& _w)
00511 {
00512   ADUNCONST(df1b2vector,v)
00513   ADUNCONST(df1b2vector,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 df1b2vector& _v,const dvector& _w)
00530 {
00531   ADUNCONST(df1b2vector,v)
00532   ADUNCONST(dvector,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_prod(const dvector& _v,const df1b2vector& _w)
00549 {
00550   ADUNCONST(dvector,v)
00551   ADUNCONST(df1b2vector,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 df1b2vector elem_div(const df1b2vector& _v,const dvector& _w)
00568 {
00569   ADUNCONST(df1b2vector,v)
00570   ADUNCONST(dvector,w)
00571   int rmin=v.indexmin();
00572   int rmax=v.indexmax();
00573   df1b2vector tmp;
00574   tmp.noallocate(rmin,rmax);
00575   for (int i=rmin;i<=rmax;i++)
00576   {
00577     tmp(i)=v(i)/w(i);
00578   }
00579   return tmp;
00580 }
00581 
00586 df1b2matrix::df1b2matrix(int nrl,int nrh,int ncl,int nch)
00587 {
00588   if (nrl>nrh)
00589   {
00590     allocate();
00591   }
00592   else
00593   {
00594     allocate(nrl,nrh,ncl,nch);
00595   }
00596 }
00597 
00602 df1b2matrix::df1b2matrix(int nrl,int nrh)
00603 {
00604   if (nrl>nrh)
00605   {
00606     allocate();
00607   }
00608   else
00609   {
00610     allocate(nrl,nrh);
00611   }
00612 }
00613 
00618 df1b2matrix::df1b2matrix(int nrl,int nrh,const index_type& ncl,
00619   const index_type& nch)
00620 {
00621   if (nrl>nrh)
00622   {
00623     allocate();
00624   }
00625   else
00626   {
00627     allocate(nrl,nrh,ncl,nch);
00628   }
00629 }
00630 
00635 df1b2matrix::df1b2matrix(void)
00636 {
00637   allocate();
00638 }
00639 
00644 void df1b2matrix::allocate(int nrl,int nrh,int ncl,int nch,const char * s)
00645 {
00646   allocate(nrl,nrh,ncl,nch);
00647 }
00648 
00653 void df1b2matrix::allocate(int nrl,int nrh,const index_type& ncl,
00654   const index_type& nch,const char * s)
00655 {
00656   allocate(nrl,nrh,ncl,nch);
00657 }
00658 
00663 void df1b2matrix::allocate(int nrl,int nrh,int ncl,int nch)
00664 {
00665   index_min=nrl;
00666   index_max=nrh;
00667   int rs=size();
00668   if ( (v = new df1b2vector[rs]) == 0)
00669   {
00670       cerr << " Error allocating memory in df1b2matrix contructor\n";
00671       ad_exit(21);
00672   }
00673   if ( (shape=new mat_shapex(v)) == 0)
00674   {
00675     cerr << " Error allocating memory in df1b2matrix contructor\n";
00676   }
00677   v -= indexmin();
00678   for (int i=nrl; i<=nrh; i++)
00679   {
00680     v[i].allocate(ncl,nch);
00681   }
00682 }
00683 
00688 void df1b2matrix::allocate(int nrl,int nrh,const index_type& ncl,
00689   const index_type& nch)
00690 {
00691   index_min=nrl;
00692   index_max=nrh;
00693   int rs=size();
00694   if ( (v = new df1b2vector[rs]) == 0)
00695   {
00696       cerr << " Error allocating memory in df1b2matrix contructor\n";
00697       ad_exit(21);
00698   }
00699   if ( (shape=new mat_shapex(v)) == 0)
00700   {
00701     cerr << " Error allocating memory in df1b2matrix contructor\n";
00702   }
00703   v -= indexmin();
00704   for (int i=nrl; i<=nrh; i++)
00705   {
00706     v[i].allocate(ncl(i),nch(i));
00707   }
00708 }
00709 
00714 df1b2matrix::df1b2matrix(const df1b2matrix & x)
00715 {
00716   index_min=x.index_min;
00717   index_max=x.index_max;
00718   v=x.v;
00719   shape=x.shape;
00720   if (shape) (shape->ncopies)++;
00721 }
00722 
00727 void df1b2matrix::allocate(int nrl,int nrh)
00728 {
00729   index_min=nrl;
00730   index_max=nrh;
00731   int rs=size();
00732   if ( (v = new df1b2vector[rs]) == 0)
00733   {
00734       cerr << " Error allocating memory in df1b2matrix contructor\n";
00735       ad_exit(21);
00736   }
00737   if ( (shape=new mat_shapex(v)) == 0)
00738   {
00739     cerr << " Error allocating memory in df1b2matrix contructor\n";
00740   }
00741   v -= indexmin();
00742   /*
00743   for (int i=nrl; i<=nrh; i++)
00744   {
00745     v[i].allocate(ncl,nch);
00746   }
00747   */
00748 }
00749 
00754 df1b2matrix::~df1b2matrix()
00755 {
00756   if (shape)
00757   {
00758     if (shape->ncopies)
00759     {
00760       (shape->ncopies)--;
00761     }
00762     else
00763     {
00764       deallocate();
00765     }
00766   }
00767 }
00768 
00773 void df1b2matrix::deallocate()
00774 {
00775   if (shape)
00776   {
00777     v=(df1b2vector*)(shape->get_pointer());
00778     delete [] v;
00779     v=0;
00780     delete shape;
00781     shape=0;
00782   }
00783 }
00784 
00789 void df1b2matrix::allocate(void)
00790 {
00791   index_min=1;
00792   index_max=0;
00793   v=0;
00794   shape=0;
00795 }
00796 
00800 void df1b2matrix::colfill(const int j, const df1b2vector& v)
00801 {
00802   //RETURN_ARRAYS_INCREMENT();   makes no sense for df1b2 stuff
00803   for (int i=rowmin(); i<=rowmax(); i++)
00804   {
00805     (*this)[i][j]=v[i];
00806   }
00807   //RETURN_ARRAYS_DECREMENT();
00808 }
00809 
00814 df1b2variable sum(const df1b2vector& _x)
00815 {
00816   ADUNCONST(df1b2vector,x)
00817   df1b2variable tmp;
00818   tmp=0.0;
00819   int mmin=x.indexmin();
00820   int mmax=x.indexmax();
00821   for (int i=mmin;i<=mmax;i++)
00822   {
00823     tmp+=x(i);
00824   }
00825   return tmp;
00826 }
00827 
00832 df1b2variable mean(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   double fn=mmax-mmin+1;
00840   for (int i=mmin;i<=mmax;i++)
00841   {
00842     tmp+=x(i);
00843   }
00844   return tmp/fn;
00845 }
00846 
00851 df1b2variable norm2(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 tmp;
00863 }
00864 df1b2variable sumsq(const df1b2vector& _x) {return(norm2(_x));}
00865 
00870 df1b2variable norm(const df1b2vector& _x)
00871 {
00872   ADUNCONST(df1b2vector,x)
00873   df1b2variable tmp;
00874   tmp=0.0;
00875   int mmin=x.indexmin();
00876   int mmax=x.indexmax();
00877   for (int i=mmin;i<=mmax;i++)
00878   {
00879     tmp+=square(x(i));
00880   }
00881   return sqrt(tmp);
00882 }
00883 
00888 df1b2variable norm2(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 tmp;
00900 }
00901 df1b2variable sumsq(const df1b2matrix& _x) {return(norm2(_x));}
00902 
00907 df1b2variable norm(const df1b2matrix& _x)
00908 {
00909   ADUNCONST(df1b2matrix,x)
00910   df1b2variable tmp;
00911   tmp=0.0;
00912   int mmin=x.indexmin();
00913   int mmax=x.indexmax();
00914   for (int i=mmin;i<=mmax;i++)
00915   {
00916     tmp+=norm2(x(i));
00917   }
00918   return sqrt(tmp);
00919 }
00920 
00925 df1b2variable sum(const df1b2matrix& _x)
00926 {
00927   ADUNCONST(df1b2matrix,x)
00928   df1b2variable tmp;
00929   tmp=0.0;
00930   int mmin=x.indexmin();
00931   int mmax=x.indexmax();
00932   for (int i=mmin;i<=mmax;i++)
00933   {
00934     tmp+=sum(x(i));
00935   }
00936   return tmp;
00937 }
00938 
00943 df1b2variable mean(const df1b2matrix& _x)
00944 {
00945   ADUNCONST(df1b2matrix,x)
00946   df1b2variable tmp;
00947   tmp=0.0;
00948   int mmin=x.indexmin();
00949   int mmax=x.indexmax();
00950   int nitems=0;
00951   for (int i=mmin;i<=mmax;i++)
00952   {
00953     tmp+=sum(x(i));
00954     nitems+=x(i).indexmax()-x(i).indexmin()+1;
00955   }
00956 #ifndef OPT_LIB
00957   assert(nitems > 0);
00958 #endif
00959   return tmp/nitems;
00960 }