ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
depvars.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 // file fvar.cpp
00012 // constructors, destructors and misc functions involving class prevariable
00013 #include "fvar.hpp"
00014 
00015 #ifdef _MSC_VER
00016   #define lseek _lseek
00017   #define read _read
00018   #define write _write
00019   #define open _open
00020   #define close _close
00021 #else
00022   #include <unistd.h>
00023 #endif
00024 
00029 prevariable& operator<<(const prevariable& _v1, const prevariable& v2)
00030   {
00031     ADUNCONST(prevariable,v1)
00032     v1=v2;
00033     gradient_structure::save_dependent_variable_position(v1);
00034     return (prevariable&)v1;
00035   }
00036 
00041 dvar_vector& operator<<(const dvar_vector& v1, const dvar_vector& v2)
00042   {
00043     RETURN_ARRAYS_INCREMENT();
00044 
00045     int mmin=v1.indexmin();
00046     int mmax=v1.indexmax();
00047     if (mmin != v2.indexmin() || mmax != v2.indexmax())
00048     {
00049       cerr << " Incompatible bounds in dvar_vector& operator"
00050         " << (const dvar_vector& v1, const dvar_vector& v2)" << endl;
00051       ad_exit(21);
00052     }
00053 
00054     for (int i=mmin;i<=mmax;i++)
00055     {
00056       v1(i) << v2(i);
00057     }
00058     RETURN_ARRAYS_DECREMENT();
00059     return (dvar_vector&) v1;
00060   }
00061 
00066 dvar_matrix& operator<<(const dvar_matrix& v1, const dvar_matrix& v2)
00067   {
00068     int mmin=v1.rowmin();
00069     int mmax=v1.rowmax();
00070     RETURN_ARRAYS_INCREMENT();
00071     if (mmin != v2.rowmin() || mmax != v2.rowmax())
00072     {
00073       cerr << " Incompatible bounds in dvar_matrix& operator"
00074         " << (const dvar_matrix& v1, const dvar_matrix& v2)" << endl;
00075       ad_exit(21);
00076     }
00077     for (int i=mmin;i<=mmax;i++)
00078     {
00079       v1(i) << v2(i);
00080     }
00081     RETURN_ARRAYS_DECREMENT();
00082     return (dvar_matrix&)v1;
00083   }
00084 
00089   dependent_variables_information::dependent_variables_information(int ndv) :
00090     grad_buffer_position(1,ndv),
00091     cmpdif_buffer_position(1,ndv),
00092     grad_file_position(1,ndv),
00093     cmpdif_file_position(1,ndv),
00094     grad_file_count(1,ndv),
00095     cmpdif_file_count(1,ndv)
00096   {
00097      max_num_dependent_variables=ndv;
00098      depvar_count=0;
00099      grad_buffer_position.initialize();
00100      cmpdif_buffer_position.initialize();
00101      grad_file_count.initialize();
00102      cmpdif_file_count.initialize();
00103      grad_file_position.initialize();
00104      cmpdif_file_position.initialize();
00105   }
00106 
00111 void gradient_structure::save_dependent_variable_position(const prevariable& v1)
00112     {
00113       int depvar_count=++DEPVARS_INFO->depvar_count;
00114       //max_num_dependent_variables=ndv;
00115       if (depvar_count>DEPVARS_INFO->max_num_dependent_variables)
00116       {
00117         cout << "maximum number of depdendent variables of "
00118            << DEPVARS_INFO->max_num_dependent_variables << " exceeded "
00119            << endl
00120            << "use gradient_structure::set_NUM_DEPENDENT_VARIABLES(int i);"
00121            << endl << "to increase the number of dependent variables"
00122            << endl;
00123         ad_exit(1);
00124       }
00125       DEPVARS_INFO->grad_buffer_position(depvar_count)=GRAD_STACK1->ptr;
00126       DEPVARS_INFO->cmpdif_buffer_position(depvar_count)=fp->offset;
00127       DEPVARS_INFO->grad_file_count(depvar_count)=
00128                                 GRAD_STACK1->_GRADFILE_PTR;
00129       DEPVARS_INFO->cmpdif_file_count(depvar_count)=fp->file_ptr;
00130       DEPVARS_INFO->grad_file_position(depvar_count)
00131         =lseek(GRAD_STACK1->_GRADFILE_PTR,0,SEEK_CUR);
00132       DEPVARS_INFO->cmpdif_file_position(depvar_count)
00133         =lseek(fp->file_ptr,0,SEEK_CUR);
00134     }