• Main Page
  • Classes
  • Files

fvar.hpp

Go to the documentation of this file.
00001 
00051 #if defined(__GNUDOS__)
00052 #  pragma interface
00053 #endif
00054 //#define USE_DDOUBLE
00055 
00056 #ifndef FVAR_HPP
00057 #define FVAR_HPP
00058 #define USE_VECTOR_SHAPE_POOL
00059 //#define MYDEBUG
00060 #if defined(USE_DDOUBLE)
00061 #  include <qd/qd.h>
00062 //#  include </usr/local/include/qd/qd.h>
00063 # define  double dd_real
00064   dd_real operator ++ (dd_real& d) { return d+=1.0;}
00065   dd_real pow(const dd_real& d,int i);
00066   dd_real pow(const dd_real& d,const dd_real&);
00067 #endif
00068 #if defined(__TURBOC__) && defined(__linux__)
00069 #define __STL_PTHREADS
00070 #  include <k3stl.h>
00071 #  include <pthread_alloc>
00072 #endif
00073 #define  __NUMBERVECTOR__
00074 #define ADUNCONST(type,obj) type & obj = (type&) _##obj;
00075 
00076 #define my_off_t long int
00077 #define my_u_off_t unsigned long int
00078 
00079 #define  MFCL2_CONSTRUCTORS
00080 
00081 #if (defined(__GNUDOS__))
00082 #  if (  (__GNUC__>3) || (__GNUC__==3 && __GNUC_MINOR__>=0)  )
00083 #    define __GNU_NEWER__
00084 #    define GCC3
00085 #  endif
00086 #endif
00087 
00088 #if (defined(__MSVC32__))
00089 #  if (__MSVC32__>=7)
00090 #    define __MSC_NEWER__
00091 #  endif
00092 #endif
00093 
00094 #if defined(__MINGW32__)
00095 #  include <conio.h>
00096 #endif
00097 //#define USE_ADPVM 1
00098 //#define AD_DEMO
00099 #if defined(_ADEXEP)
00100 #  define USE_EXECPTIONS
00101 #endif
00102 //#define CHK_ID_STRING
00103 //#define SAFE_ALL
00104 #define DOS386
00105 //#define AD_FAST_ASSIGN
00106 // file fvar.hpp
00107 // try to just use BOR_CONST = const
00108 #define __USE_IOSTREAM__
00109 #if defined(__BORLANDC__)
00110 #  if (__BORLANDC__  >= 0x0550) 
00111 #    include <fcntl.h>
00112 #  endif
00113 #  if (__BORLANDC__  >= 0x0520) 
00114 #    define BOR_CONST const
00115 // #    define __USING_STD_NAMES__
00116 #  else
00117 #  define BOR_CONST
00118 #endif
00119 #else
00120 #  define BOR_CONST
00121 #endif
00122 #define USE_HIGHER_ARRAYS
00123 #if defined(__BORLANDC__) || defined (__MSVC32__) || defined(__WAT32__)
00124 #  include <io.h>
00125 #endif
00126 
00127 // test
00128 //#if defined (__MSVC32__) 
00129 #  if defined (BOR_CONST) 
00130 #    undef BOR_CONST
00131 #  endif
00132 #  define BOR_CONST const
00133 //#endif
00134 
00135 #if defined(linux) || defined (__GNUDOS__)
00136 #define AD_LONG_INT long int
00137 //#define AD_LONG_INT long long int
00138 #else
00139 #define AD_LONG_INT long int
00140 #endif
00141 
00142 #if defined(linux) || defined (__GNUDOS__)
00143 #  include <unistd.h>
00144 #endif
00145 
00146 #if defined(linux) || defined(__ADSGI__) || defined(__linux__)
00147 #include <fcntl.h> // to get fstreambase
00148 #  if !defined(O_BINARY)
00149 #    define O_BINARY 0
00150 #  endif
00151   #define UNIXKLUDGE
00152 #endif
00153 
00154 #if !defined(linux) 
00155 #  include <dos.h>
00156 #  if !defined(__MSVC32__) && !defined(__BORLANDC__) && !defined (__GNUDOS__)
00157 #    include <pc.h>
00158 #  endif
00159 #endif
00160 #define AD_VERSION 7
00161 
00162 #if defined(__GNUDOS__)
00163 extern "C" {
00164       void clrscr(void);
00165 }
00166   #define CGNU_DOUBLE double 
00167 #else
00168 #  if defined(__BORLANDC__)
00169 #    if (__BORLANDC__  > 0x0520) 
00170 #      define CGNU_DOUBLE double 
00171 #    else
00172 #      define CGNU_DOUBLE  double 
00173 #    endif
00174 #  else
00175 #    define CGNU_DOUBLE  double 
00176 #  endif
00177 #endif
00178 
00179 #ifdef __GNUDOS__
00180   #define DOS386 
00181   #define __GNU__
00182   #ifdef OLDGNU
00183   #include <gccmanip.h>
00184   #endif
00185 //#define HUGE_VAL  1.7976931348623158E+308
00186 #endif
00187 
00188 // for compilers that have trouble with const
00189 #define USE_CONST
00190 #ifdef USE_CONST
00191   #define _CONST const
00192 #else
00193   #define _CONST 
00194 #endif
00195 #ifdef __GNUDOS__
00196  // #include <admanip.h>
00197 #endif
00198 
00199 #ifdef _SNGL_ 
00200   #define double float
00201 #endif
00202 
00203 #ifndef NO_DERIVS
00204   #define  NO_DERIVS
00205 #endif
00206 
00207 #ifdef SAFE_ALL
00208 //#define INCLUDE_BLOCKSIZE       // add size info to df1b2variable
00209   #define CHK_ID_STRING
00210   #define DSAFE_ALLOCATE
00211 //  #define SAFE_INITIALIZE
00212   #define SAFE_ARRAYS
00213 #endif 
00214 
00215 #ifdef __NDP486__
00216 #include "short.def"
00217 #endif
00218 
00219 #ifdef USE_ASSEMBLER
00220   #include "adass.h"
00221 #endif
00222 
00223 extern "C" {
00224 typedef int (* fptr) (const char * format, ...) ;
00225 extern fptr ad_printf;
00226 typedef void (*exitptr)(int);
00227 extern exitptr ad_exit;
00228 
00229 void spdll_exit(int);
00230 }
00231 
00232   class smart_counter
00233   {
00234     int * ncopies;
00235   public:
00236     int * get_ncopies(void);
00237     smart_counter(void);
00238     smart_counter(const smart_counter & sc);
00239     ~smart_counter(void);
00240   };
00241 
00242   class double_and_int
00243   {
00244   public:
00245     double x;
00246     inline double& xvalue(void){return x;}
00247   };
00248 
00249 class banded_symmetric_dvar_matrix;
00250 class banded_symmetric_dmatrix;
00251 class banded_lower_triangular_dmatrix;
00252 class banded_lower_triangular_dvar_matrix;
00253 class random_number_generator;
00254 class ad_integer;
00255 class index_type;
00256 class dlink;
00257 class dvector;
00258 class dmatrix;
00259 class tdmatrix;
00260 class imatrix;
00261 class prevariable;
00262 class dvariable;
00263 class dvar_vector;
00264 class ivector;
00265 class lvector;
00266 class dvar_matrix;
00267 class uostream;
00268 class uistream;
00269 class arr_link;
00270 class arr_list;
00271 class d3_array;
00272 class d4_array;
00273 class d5_array;
00274 class d6_array;
00275 class d7_array;
00276 class dvar3_array;
00277 class dvar4_array;
00278 class dvar5_array;
00279 class dvar6_array;
00280 class dvar7_array;
00281 class dlist;
00282 class indvar_offset_list;
00283 class dvar_matrix_position;
00284 class DF_FILE;
00285 class dmatrix_position;
00286 class d3_array_position;
00287 class dvector_position;
00288 class vector_shape;
00289 class ivector_position;
00290 class kkludge_object;
00291 class dvar_vector_position;
00292 dvector restore_dvar_vector_derivatives(void);
00293 class gradient_structure;
00294 class dependent_variables_information;
00295 #if defined(__GNUC__) 
00296 #  if (__GNUC__  >= 3) 
00297 #    include <fstream>
00298 #  else
00299 #    include <fstream.h>
00300 #  endif
00301 #elif defined(__MSVC32__) 
00302 #  if (__MSVC32__  >= 7)
00303 #    include <fstream>
00304 #  else
00305 #    include <fstream.h>
00306 #  endif
00307 #else
00308 #  include <fstream.h>
00309 #endif
00310 #include <stdio.h>
00311 //#define __SUN__ 1
00312 # if defined (__WAT32__)
00313 #  if defined (max)
00314 #    undef max
00315 #  endif
00316 #  if defined (min)
00317 #    undef min
00318 #  endif
00319 #endif
00320 #if defined (__TURBOC__) || defined (__WAT32__) 
00321 #include <mem.h>  // to get memcpy and NULL
00322 #include <fstream.h> // to get fstreambase
00323 #include <iostream.h>
00324 #include <dos.h>
00325 #undef __ZTC__
00326 #define __USE_IOSTREAM__
00327 #undef __SUN__
00328 #endif
00329 
00330 #if ( defined(__GNUC__) && __GNUC__<3)
00331 #if defined(linux) || defined(__CYGWIN__)
00332 #   include <strstream.h>
00333 #  else
00334 #   include <strstrea.h>
00335 #  endif
00336 #endif
00337 
00338 #if defined(__BORLANDC__)
00339 #  if (__BORLANDC__  < 0x0550) 
00340 #    include <fcntl.h> // to get fstreambase
00341 #    include <strstrea.h>
00342 #  else
00343 #    include <strstream>
00344 #  endif
00345 #endif
00346 
00347 #if defined(__MSVC32__ ) 
00348 #  if (__MSVC32__  >= 7)
00349 #    include <iostream>
00350 #  else
00351 #    include <iostream.h>
00352 #    include <strstrea.h>
00353 #  endif
00354 #include <stddef.h>
00355 #include <fcntl.h> // to get fstreambase
00356 #include <dos.h>
00357 #undef __ZTC__
00358 #define __USE_IOSTREAM__
00359 #undef __SUN__
00360 #endif
00361 
00362 #ifdef __ZTC__
00363 #include <fstream.hpp> // to get fstreambase
00364 #include <iostream.hpp>
00365 #define __USE_IOSTREAM__
00366 #include <dos.h>
00367 #undef __SUN__
00368 #endif
00369 
00370 #ifdef __NDPX__
00371 #include <fstream.h>
00372 #include <iostream.h>
00373 #define __USE_IOSTREAM__
00374 #undef __SUN__
00375 #endif
00376 
00377 #ifdef __SUN__
00378 #undef __NDPX__
00379 #include <fstream.h>
00380 #include <iostream.h>
00381 #define __USE_IOSTREAM__
00382 
00383 #ifndef _FPOS_T_DEFINED
00384 #ifdef __GNUDOS__
00385 #  if defined(linux) || defined(__ADSGI__)|| defined(__CYGWIN32__)
00386       typedef long int fpos_t;
00387 #  else
00388       typedef unsigned long int fpos_t;
00389 #  endif
00390 # undef __SUN__
00391 #elif defined (__WAT32__)
00392   typedef long fpos_t;
00393 #else
00394   typedef int fpos_t;
00395 #endif
00396   #define _FPOS_T_DEFINED
00397 #endif
00398 
00399 #if defined(__GNUC__)
00400 extern "C" int getch(void);
00401 #else
00402 int getch(void);
00403 #endif
00404 
00405 #endif
00406 #include <math.h>
00407 
00408 #if defined(__BORLANDC__)
00409 #  if (__BORLANDC__  > 0x0520) 
00410      using std::ofstream;
00411      using std::ifstream;
00412 #  endif
00413 #endif
00414 
00415 #if ( (defined(__GNUC__) && __GNUC__>=3)   \
00416     || (defined(__MSVC32__) && __MSVC32__>=7)  \
00417     || (defined(__BORLANDC__) && __BORLANDC__>=0x0570  && defined(__linux__)) )
00418 #  include <iostream>
00419 #  include <iomanip>
00420 #  include <sstream>
00421 #  include <istream>
00422 #  include <strstream>
00423      using std::ofstream;
00424      using std::ostream;
00425      using std::ifstream;
00426      using std::istream;
00427      using std::istrstream;
00428      using std::streampos;
00429      using std::streambuf;
00430      using std::setw;
00431      using std::setprecision;
00432      using std::istringstream;
00433      using std::ios;
00434      using std::cerr;
00435      using std::cin;
00436      using std::cout;
00437      using std::endl;
00438 #else
00439 #  include <iomanip.h>     
00440 #endif     
00441 
00442 #define BEGIN_MINIMIZATION(nvar, objective_function, ind_vars, gradient, cntrl) \
00443 gradient_structure gs; \
00444 while (cntrl.ireturn >= 0) \
00445 { \
00446   cntrl.fmin(objective_function,ind_vars,gradient ); \
00447   if (cntrl.ireturn > 0) \
00448   {
00449 
00450 #define END_MINIMIZATION(nvar,gradient) \
00451     gradcalc(nvar, gradient); \
00452   } \
00453 }
00454 
00455 void default_evaluation(void);
00456 void default_evaluation0(void);
00457 void default_evaluation1(void);
00458 void default_evaluation1m(void);
00459 void default_evaluation2(void);
00460 void default_evaluation3(void);
00461 void default_evaluation4(void);
00462 void default_evaluation4m(void);
00463 
00464 void myheapcheck( char *);
00465 
00466 void RETURN_ARRAYS_INCREMENT(void);
00467 void RETURN_ARRAYS_DECREMENT(void);
00468 
00469 void * farptr_norm(void *);
00470 long int farptr_tolong(void *) ;
00471 #if (!defined(__ZTC__) || defined(DOS386))
00472   long int _farptr_tolong(void *);
00473 #endif
00474 void denormalize_ptr(void * , unsigned int byte_offset);
00475 
00476 class i3_array;
00477 
00478 ostream& operator<<(BOR_CONST ostream& ostr,_CONST dmatrix& z);
00479 istream& operator>>(BOR_CONST istream& istr,BOR_CONST dmatrix& z);
00480 uostream& operator<<(BOR_CONST uostream& ostr,_CONST dmatrix& z);
00481 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST dmatrix& z);
00482 
00483 ostream& operator<<(BOR_CONST ostream& ostr,_CONST d3_array& z);
00484 istream& operator>>(BOR_CONST istream& istr,BOR_CONST d3_array& z);
00485 uostream& operator<<(BOR_CONST uostream& ostr,_CONST d3_array& z);
00486 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST d3_array& z);
00487 
00488 ostream& operator<<(BOR_CONST ostream& ostr,_CONST dvar3_array& z);
00489 istream& operator>>(BOR_CONST istream& istr,BOR_CONST dvar3_array& z);
00490 uostream& operator<<(BOR_CONST uostream& ostr,_CONST dvar3_array& z);
00491 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST dvar3_array& z);
00492 
00493 ostream& operator<<(BOR_CONST ostream& ostr,_CONST ivector& z);
00494 istream& operator>>(BOR_CONST istream& istr,BOR_CONST ivector& z);
00495 uostream& operator<<(BOR_CONST uostream& ostr,_CONST ivector& z);
00496 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST ivector& z);
00497 
00498 ostream& operator<<(BOR_CONST ostream& ostr,_CONST lvector& z);
00499 istream& operator>>(BOR_CONST istream& istr,BOR_CONST lvector& z);
00500 uostream& operator<<(BOR_CONST uostream& ostr,_CONST lvector& z);
00501 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST lvector& z);
00502 
00503 ostream& operator<<(BOR_CONST ostream& ostr,const dvector& z);
00504 istream& operator>>(BOR_CONST istream& istr,BOR_CONST dvector& z);
00505 uostream& operator<<(BOR_CONST uostream& ostr,_CONST dvector& z);
00506 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST dvector& z);
00507 
00508 ostream& operator<<(BOR_CONST ostream& ostr,_CONST dvar_vector& z);
00509 istream& operator>>(BOR_CONST istream& istr,BOR_CONST dvar_vector& z);
00510 uostream& operator<<(BOR_CONST uostream& ostr,_CONST dvar_vector& z);
00511 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST dvar_vector& z);
00512 
00513 ostream& operator<<(BOR_CONST ostream& ostr,_CONST dvar_matrix& z);
00514 istream& operator>>(BOR_CONST istream& istr,BOR_CONST dvar_matrix& z);
00515 uostream& operator<<(BOR_CONST uostream& ostr,_CONST dvar_matrix& z);
00516 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST dvar_matrix& z);
00517 
00518 
00519 ostream& operator<<(BOR_CONST ostream& ostr,_CONST prevariable& z);
00520 istream& operator>>(BOR_CONST istream& istr,BOR_CONST prevariable& z);
00521 uostream& operator<<(BOR_CONST uostream& ostr,_CONST prevariable& z);
00522 uistream& operator>>(BOR_CONST uistream& istr,BOR_CONST prevariable& z);
00523 
00524 ostream& setscientific(BOR_CONST ostream& s);
00525 
00526 //ostream& setshowpoint(BOR_CONST ostream& s);
00527 class preshowpoint
00528 {
00529   int x;
00530 };
00531 preshowpoint  setshowpoint(void);
00532 ostream& operator << (BOR_CONST ostream&,preshowpoint);
00533 
00534 #if (__MSVC32__>=7 || __BORLANDC__  >= 0x0560) 
00535 #   define setfixed() std::fixed
00536 #else
00537   ostream& setfixed(BOR_CONST ostream& s);
00538   class prefixed
00539   {
00540     int x;
00541   };
00542   prefixed  setfixed(void);
00543   ostream& operator << (BOR_CONST ostream&,prefixed);
00544 #endif
00545   
00546 #if (__MSVC32__>=7 || __BORLANDC__  >= 0x0560) 
00547 #   define setscientific() std::scientific
00548 #else
00549   class prescientific
00550   {
00551     int x;
00552   };
00553   prescientific  setscientific(void);
00554   ostream& operator << (BOR_CONST ostream&,prescientific);
00555 #endif
00556 
00557 istream& operator>>(BOR_CONST istream& istr,BOR_CONST imatrix& z);
00558 ostream& operator<<(BOR_CONST ostream& istr,_CONST imatrix& z);
00559 istream& operator>>(BOR_CONST istream& istr,BOR_CONST i3_array& z);
00560 ostream& operator<<(BOR_CONST ostream& istr,_CONST i3_array& z);
00561   class grad_stack;
00562 
00563   class kkludge_object
00564   {
00565     char u;
00566   };
00567 
00568       class humungous_pointer
00569       {
00570       public:
00571         #if defined(__BORLANDC__ ) && !defined(DOS386) && !defined(__WIN32__)
00572     char huge * ptr;
00573   #else
00574     char * ptr;
00575   #endif
00576           int adjustment;
00577         void free(void);
00578   ~humungous_pointer(){;}
00579         void adjust(int);
00580   humungous_pointer();
00581   humungous_pointer operator + (unsigned long int& offset);
00582   humungous_pointer& operator += (unsigned long int& offset);
00583   humungous_pointer& operator = (void * p);
00584   int operator == (void * p);
00585   int operator != (void * p); 
00586         operator char* (); 
00587         operator void* (); 
00588         operator double_and_int* ();
00589         operator double* ();
00590       };
00591 
00592 #ifndef _VECTOR_SHAPE
00593   #define _VECTOR_SHAPE
00594 #include <dfpool.h>
00595   class vector_shape_pool : public dfpool
00596   {
00597   public:
00598     vector_shape_pool(void);
00599     vector_shape_pool(int);
00600   };
00601 
00602   class vector_shape
00603   {
00604   public:
00605 #if defined(USE_VECTOR_SHAPE_POOL)
00606     static vector_shape_pool * xpool;
00607     void * operator new(size_t);
00608     void operator delete(void * ptr,size_t n)
00609     {  xpool->free(ptr); }
00610 #endif
00611     unsigned int ncopies;
00612     void shift(int min);
00613     int index_min;
00614     int index_max;
00615   private:
00616     friend class dvector;
00617     //friend class tdvector;
00618     friend class subdvector;
00619     friend class dvar_vector;
00620     friend class ivector;
00621     friend class lvector;
00622     friend class ptr_vector;
00623   public:
00624     int decr_ncopies(void) {return --ncopies;}
00625     int get_ncopies(void) {return ncopies;}
00626     int incr_ncopies(void) {return ++ncopies;}
00627     vector_shape(int lb, int lu) {index_min=lb;index_max=lu;ncopies=0;}
00628     int indexmin(){return index_min;}
00629     int indexmax(){return index_max;}
00630   };
00631 #endif
00632 
00633   class ptr_vector
00634   {
00635     void ** v;
00636     vector_shape * shape;
00637 
00638   public:
00639 
00640     int indexmin() _CONST {return shape->index_min;} // returns the minimum allowable index
00641     int indexmax() _CONST  {return shape->index_max;} // returns the maximum allowable index
00642     int size() _CONST {return shape->index_max - shape->index_min+1;} // returns the maximum allowable index
00643 
00644     void shift(int min);
00645     ptr_vector( int ncl,  int ncu);
00646     ptr_vector();
00647     void allocate(int,int);
00648     //operator void ** ();
00649    ~ptr_vector();
00650     void*& operator[] (int i);
00651     void*& operator() (int i);
00652     //void*& elem(int i);
00653     void*& elem(int i) { return(*(v+i)); }
00654     int operator ! (void) _CONST {return (shape == NULL);}
00655     int operator () (void) _CONST {return (shape != NULL);}
00656 
00657     ptr_vector(BOR_CONST ptr_vector& t);
00658     ptr_vector& operator = (BOR_CONST ptr_vector& t);
00659     void initialize();
00660  }; // end of class ptr_vector
00661 
00662   class preivector
00663   {
00664     ivector * p;
00665     int lb;
00666     int ub;
00667     inline preivector(ivector * _p,int _lb,int _ub) {p=_p;lb=_lb,ub=_ub;}
00668     friend class ivector;
00669   };
00670 
00671   class vector_shapex;
00672   class ivector
00673   {
00674   protected:
00675     int index_min;
00676     int index_max;
00677     int * v;
00678     vector_shapex * shape;
00679 
00680   public:
00681     int allocated(void) _CONST {return (shape != NULL);}
00682 
00683     ivector& operator -- (void) 
00684     { 
00685       index_min--;index_max--;v++; return *this;
00686     }
00687     void reallocate(double size);
00688 
00689     ivector& operator ++ (void)  
00690     { 
00691       index_min++;index_max++;v--; return *this;
00692     }
00693     friend class vector_index;
00694     int operator ! (void) _CONST {return (shape == NULL);}
00695 
00696         int& elem(int i) { return(v[i]); }
00697 #ifdef USE_CONST
00698         _CONST int& elem(int i) _CONST { return(v[i]); }
00699 #endif
00700     int indexmin()_CONST  {return index_min;} // returns the minimum allowable index
00701     int indexmax()_CONST  {return index_max;} // returns the maximum allowable index
00702     int size() _CONST {return index_max - index_min+1;} // returns the maximum allowable index
00703     int * get_v(void) _CONST {return v;}
00704     void shift(int min);
00705     //ivector(unsigned int sz); //makes an array [0..sz]
00706     //inline allocated(void) {return ::allocated(this);}
00707     ivector(_CONST lvector&);
00708     ivector(void);
00709 
00710     ivector(_CONST dvector&);
00711 
00712     void fill(const char * s);
00713     void fill_seqadd(int, int);
00714     void fill_multinomial(BOR_CONST int& seed,_CONST dvector& p);
00715     void fill_multinomial(BOR_CONST random_number_generator& rng,_CONST dvector& p);
00716     ivector( int ncl,  int ncu);
00717     ivector(const ad_integer& ncl,const index_type& ncu);
00718     void allocate(const ad_integer& ncl,const index_type& ncu);
00719              // makes an array [ncl..ncu]
00720 
00721     ivector( unsigned int sz, long int * x);
00722 
00723 //#ifdef HOME_VERSION
00724       void safe_allocate(int ncl,int ncu);
00725       void allocate(int ncl,int ncu);
00726       void allocate(_CONST ivector& iv);
00727       void allocate(_CONST dvector& dv);
00728       void allocate(const char *);
00729       void allocate(void);
00730       void deallocate(void);
00731       void safe_deallocate(void);
00732 //#endif
00733 
00734     //operator int* () {return v;}
00735 
00736    ~ivector();
00737 
00738     void save_ivector_position(void) _CONST;
00739 
00740     void save_ivector_value(void) _CONST;
00741 
00742     void write_on(BOR_CONST ostream& s) _CONST;
00743 
00744     void read_from(BOR_CONST istream& s);
00745 
00746     void write_on(BOR_CONST uostream& s) _CONST;
00747 
00748     void read_from(BOR_CONST uistream& s);
00749 
00750  #ifdef OPT_LIB
00751     inline int& operator[] (int i) {return(*(v+i));}
00752     inline int& operator() (int i) {return(*(v+i));}
00753  #else
00754     int& operator[] (int i);
00755     int& operator() (int i);
00756  #endif
00757 
00758 #ifdef USE_CONST
00759  #ifdef OPT_LIB
00760     inline _CONST int& operator[] (int i) _CONST {return(*(v+i));}
00761     inline _CONST int& operator() (int i) _CONST {return(*(v+i));}
00762  #else
00763     _CONST int& operator[] (int i) _CONST;
00764     _CONST int& operator() (int i) _CONST;
00765  #endif
00766 #endif
00767 
00768     ivector sub(int lb,int ub)
00769     {
00770       return preivector(this,lb,ub);
00771     }
00772     ivector operator () (int lb,int ub)
00773     {
00774       return preivector(this,lb,ub);
00775     }
00776     ivector(const preivector& pd);
00777 
00778     ivector operator ()(_CONST ivector& u);
00779 
00780     ivector(_CONST ivector& t);
00781     void shallow_copy(_CONST ivector& t);
00782 
00783     ivector& operator = (_CONST ivector& t);
00784     ivector& operator = (int t);
00785 
00786     ivector& operator = (_CONST lvector& t);
00787 
00788     friend class imatrix;
00789     friend class i3_array;
00790     void initialize(void);
00791     ivector& operator += (_CONST ivector& t);
00792     ivector& operator += (int t);
00793 
00794  }; // end of class ivector
00795 
00796   ivector operator + (_CONST ivector& v,_CONST ivector& w);
00797   ivector operator - (_CONST ivector& v,_CONST ivector& w);
00798   ivector operator + (_CONST ivector& v,int w);
00799   ivector operator - (_CONST ivector& v,int w);
00800   ivector operator + (int v,_CONST ivector& w);
00801   ivector operator - (int v,_CONST ivector& w);
00802 
00803 class lvector_position
00804 {
00805   int min;
00806   int max;
00807   int * v;
00808 public:
00809   lvector_position(void);
00810   lvector_position(_CONST lvector& v);
00811   lvector_position(BOR_CONST lvector_position& dvp);
00812 };
00813 
00814   class lvector
00815   {
00816      AD_LONG_INT * v;
00817     vector_shape * shape;
00818 
00819   public:
00820     int operator ! (void) _CONST {return (shape == NULL);}
00821 
00822         inline AD_LONG_INT& elem(int i) { return(v[i]); }
00823 #ifdef USE_CONST
00824         inline _CONST AD_LONG_INT& elem(int i) _CONST { return(v[i]); }
00825 #endif
00826     int indexmin() _CONST  {return shape->index_min;} // returns the minimum allowable index
00827     int indexmax() _CONST {return shape->index_max;} // returns the maximum allowable index
00828     int size() _CONST {return shape->index_max - shape->index_min+1;} // returns the maximum allowable index
00829     void shift(int min);
00830 
00831     void fill(const char * s);
00832     void fill_seqadd( BOR_CONST AD_LONG_INT&,  BOR_CONST AD_LONG_INT&);
00833     void fill_multinomial(BOR_CONST int& seed,_CONST dvector& p);
00834     void fill_multinomial(BOR_CONST random_number_generator& rng,_CONST dvector& p);
00835 
00836     //lvector(unsigned int sz); //makes an array [0..sz]
00837 
00838     lvector(_CONST lvector&);
00839 
00840     lvector(_CONST dvector&);
00841 
00842     lvector(_CONST ivector&);
00843 
00844     lvector(void);
00845 
00846     lvector( int ncl,  int ncu);
00847     void allocate( int ncl,  int ncu);
00848     void allocate(_CONST lvector&);
00849     void allocate(void);
00850                                            // makes an array [ncl..ncu]
00851 
00852     lvector( unsigned int sz,  AD_LONG_INT * x);
00853 
00854     operator  AD_LONG_INT* ();
00855 
00856    ~lvector();
00857 
00858     void write_on(BOR_CONST ostream& s) _CONST;
00859 
00860     void read_from(BOR_CONST istream& s);
00861 
00862     void write_on(BOR_CONST uostream& s) _CONST;
00863 
00864     void read_from(BOR_CONST uistream& s);
00865 
00866 #ifdef OPT_LIB
00867     inline  AD_LONG_INT& operator[] (int i) {return v[i];}
00868     inline  AD_LONG_INT& operator() (int i) {return v[i];}
00869 #else
00870      AD_LONG_INT& operator[] (int i);
00871      AD_LONG_INT& operator() (int i);
00872 #endif
00873 
00874 #ifdef USE_CONST
00875 #ifdef OPT_LIB
00876     inline _CONST  AD_LONG_INT& operator[] (int i) _CONST {return v[i];}
00877     inline _CONST  AD_LONG_INT& operator() (int i) _CONST {return v[i];}
00878 #else
00879     _CONST  AD_LONG_INT& operator[] (int i) _CONST ;
00880     _CONST  AD_LONG_INT& operator() (int i) _CONST ;
00881 #endif
00882 #endif
00883 
00884     lvector operator ()(_CONST lvector& u);
00885 
00886     lvector& operator = (_CONST lvector& t);
00887 
00888     void initialize(void);
00889     friend class lmatrix;
00890  }; // end of class lvector
00891 
00892   AD_LONG_INT sum(_CONST lvector&);
00893 
00894   
00895   class dependent_variables_information
00896   {
00897     int max_num_dependent_variables;
00898     int depvar_count;
00899     ptr_vector grad_buffer_position;
00900     lvector cmpdif_buffer_position;
00901     lvector grad_file_position;
00902     lvector cmpdif_file_position;
00903     lvector grad_file_count;
00904     lvector cmpdif_file_count;
00905     dependent_variables_information(int ndv);
00906     friend class gradient_structure;
00907   };
00908   dvar_vector_position restore_dvar_vector_position(void);
00909   dvector restore_dvar_vector_value(BOR_CONST dvar_vector_position& tmp);
00910   void arr_free(double_and_int *);
00911   double_and_int * arr_new(unsigned int sz); 
00912 
00913   class gradient_structure
00914   {
00915       static char cmpdif_file_name[61];
00916       static DF_FILE * fp;
00917 public:
00918       #if defined(NO_DERIVS)
00919         static int no_derivatives;
00920       #endif
00921 private:
00922       static long int USE_FOR_HESSIAN;
00923       static long int NVAR;
00924       static int NUM_RETURN_ARRAYS;
00925       static dvariable** RETURN_ARRAYS;
00926       static int RETURN_ARRAYS_PTR;
00927       static dvariable ** RETURN_PTR_CONTAINER;
00928       static long int TOTAL_BYTES;
00929       static long int PREVIOUS_TOTAL_BYTES;
00930       static unsigned long ARRAY_MEMBLOCK_SIZE; //js
00931       static humungous_pointer ARRAY_MEMBLOCK_BASE;
00932       static humungous_pointer ARRAY_MEMBLOCK_BASEA;
00933       static humungous_pointer ARRAY_MEMBLOCK_SAVE;
00934 public:    
00935       static double * get_ARRAY_MEMBLOCK_BASE() 
00936       { 
00937         return (double*) ARRAY_MEMBLOCK_BASE;
00938       }
00939 private:
00940       static double * variables_save;
00941       static long int CMPDIF_BUFFER_SIZE;
00942       static long int GRADSTACK_BUFFER_SIZE;
00943       static unsigned int MAX_NVAR_OFFSET;
00944       static int save_var_file_flag;
00945       static int save_var_flag;
00946 
00947       static int MAX_DLINKS;
00948       static indvar_offset_list * INDVAR_LIST;
00949       static int NUM_DEPENDENT_VARIABLES;
00950       static dependent_variables_information * DEPVARS_INFO;
00951 
00952       // this needs to be a static member function so other static
00953       // member functions can call it
00954       static void check_set_error(const char* variable_name);
00955 
00956       static int instances;
00957       int   x;
00958 
00959     public:
00960       class arrmemblerr{}; // exception class
00961    
00962       static int Hybrid_bounded_flag;
00963       static double * hessian_ptr;
00964       static int get_USE_FOR_HESSIAN(void) {return USE_FOR_HESSIAN;}
00965       static void set_USE_FOR_HESSIAN(int i) {USE_FOR_HESSIAN=i;}
00966       friend class dfsdmat;
00967       gradient_structure(long int size=100000L);  // constructor
00968       ~gradient_structure(void); // destructor
00969       static void save_variables(void);
00970       static void restore_variables(void);
00971       static void save_arrays(void);
00972       static void restore_arrays(void);
00973       static long int totalbytes(void);
00974       friend dvector restore_dvar_vector_value(BOR_CONST dvar_vector_position& tmp);
00975       friend void cleanup_temporary_files();
00976       //friend dvector restore_dvar_vector_value(BOR_CONST dvar_vector_position&);
00977       friend dvector restore_dvar_vector_derivatives(void);
00978       friend dmatrix restore_dvar_matrix_derivatives(void);
00979       friend dmatrix restore_dvar_matrix_value(void);
00980       //friend dmatrix restore_derivatives(void);
00981       friend void gradfree(dlink * v);
00982       friend double_and_int * arr_new(unsigned int sz); //js
00983       friend void arr_free(double_and_int *);
00984       friend void RETURN_ARRAYS_DECREMENT(void);
00985       friend void RETURN_ARRAYS_INCREMENT(void);
00986       friend void make_indvar_list(_CONST dvar_vector& t);
00987       //friend void gradcalc( int , double *);
00988       friend void gradcalc(int nvar,BOR_CONST dvector& g);
00989       friend void slave_gradcalc(void);
00990       friend void funnel_gradcalc(void);
00991       friend void allocate_dvariable_space(void);
00992       friend void wide_funnel_gradcalc(void);
00993       friend dvar_vector_position restore_dvar_vector_position(void);
00994       static grad_stack  * GRAD_STACK1;
00995       friend double_and_int * gradnew();
00996       static dlist * GRAD_LIST;
00997       static int RETURN_ARRAYS_SIZE;
00998       //static int RETURN_INDEX;
00999       static dvariable * RETURN_PTR;
01000       static dvariable * MIN_RETURN;
01001       static dvariable * MAX_RETURN;
01002       static arr_list * ARR_LIST1;
01003       static arr_list * ARR_FREE_LIST1;
01004       //static void funnel_jacobcalc(void);
01005       static void jacobcalc(int nvar,BOR_CONST dmatrix& jac);
01006       static void jacobcalc(int nvar,BOR_CONST ofstream& jac);
01007       static void jacobcalc(int nvar,BOR_CONST uostream& jac);
01008 
01009       friend void default_evaluation(void);
01010       //access functions
01011 
01012       friend class DF_FILE;
01013       static DF_FILE * get_fp(void){return fp;}
01014       static void set_NUM_RETURN_ARRAYS(int i);
01015      #if defined(NO_DERIVS)
01016       static void set_NO_DERIVATIVES(void);
01017       static void set_YES_DERIVATIVES(void);
01018      #endif
01019       static void set_YES_SAVE_VARIABLES_VALUES();
01020       static void set_NO_SAVE_VARIABLES_VALUES();
01021       //static int _GRADFILE_PTR; // should be int gradfile_handle;
01022       //static int _GRADFILE_PTR1; // should be int gradfile_handle;
01023       //static int _GRADFILE_PTR2; // should be int gradfile_handle;
01024       //static int _VARSSAV_PTR; // should be int gradfile_handle;
01025       static void set_NUM_DEPENDENT_VARIABLES(int i);
01026       static void set_RETURN_ARRAYS_SIZE(int i);
01027       static void set_ARRAY_MEMBLOCK_SIZE(unsigned long i);
01028       static void set_CMPDIF_BUFFER_SIZE(long int i);
01029       static void set_GRADSTACK_BUFFER_SIZE(long int i);
01030       static void set_MAX_NVAR_OFFSET(unsigned int i);
01031       static void set_MAX_DLINKS(int i);
01032       static long int NUM_GRADSTACK_BYTES_WRITTEN(void);
01033       friend class dlist;
01034       friend class grad_stack;
01035       static void save_dependent_variable_position
01036         (_CONST prevariable& v1);
01037       static long int max_last_offset;
01038       friend class function_minimizer;
01039       friend void funnel_derivatives(void);
01040   };
01041 
01042   void jacobcalc(int nvar,BOR_CONST dmatrix& g);
01043   void jacobcalc(int nvar,BOR_CONST ofstream& ofs);
01044   void jacobcalc(int nvar,BOR_CONST uostream& ofs);
01045 
01046 #if defined(__BORLANDC__ )
01047 #  pragma interface
01048 #endif
01049     class dvect_ptr_ptr
01050     {
01051       dvector ** m;
01052     };
01053     class dlink
01054     {
01055        double_and_int  di;
01056        dlink *       prev;
01057     public:  // comments
01058       dlink * previous();
01059       inline double_and_int * get_address()
01060       {
01061         return &di;
01062       } //access function
01063 
01064       //friend tempvar();
01065       //friend class prevariable;
01066       //friend class tempvar;
01067       friend class dlist;
01068       friend void gradcalc(int nvar,BOR_CONST dvector& g);
01069       friend void slave_gradcalc(void);
01070       friend void gradloop();
01071       friend double_and_int * gradnew();
01072       friend void allocate_dvariable_space(void);
01073     };
01074 
01075     class dlist
01076     {
01077       dlink * last;
01078       unsigned int last_offset;
01079       unsigned int nlinks;
01080       dlink ** dlink_addresses;
01081       friend double_and_int * gradnew();
01082       friend void df_check_derivative_values(void);
01083       friend void df_check_derivative_values_indexed(void);
01084       friend void df_check_derivative_values_indexed_break(void);
01085 
01086     public:
01087       dlist();  // constructor
01088       void check_list(void);  // check list integrity
01089      ~dlist();  // destructor
01090       dlink * create();     //create a new link 
01091       void free_remove(dlink * rem);
01092       dlink * append(dlink *);  // add a link
01093       dlink* last_remove();
01094       friend void funnel_gradcalc(void);
01095       friend void slave_gradcalc(void);
01096       friend void gradcalc(int nvar,BOR_CONST dvector& g);
01097       friend void gradloop();
01098       friend void gradient_structure::restore_variables();
01099       friend void gradient_structure::save_variables();
01100       friend void gradient_structure::jacobcalc(int nvar,BOR_CONST dmatrix& jac);
01101       friend void allocate_dvariable_space(void);
01102       //friend void gradient_structure::funnel_jacobcalc(void);
01103       friend void gradient_structure::jacobcalc(int nvar,BOR_CONST ofstream& jac);
01104       friend void gradient_structure::jacobcalc(int nvar,BOR_CONST uostream& jac);
01105       friend void funnel_derivatives(void);
01106     };
01107 
01108     class indvar_offset_list;
01109     class grad_stack_entry
01110     {
01111     public:
01112       void (* func) (void);
01113       double * dep_addr;
01114       double * ind_addr1;
01115       double  mult1;
01116       double * ind_addr2;
01117       double  mult2;
01118     public:
01119       friend void gradcalc(int nvar,BOR_CONST dvector& g);
01120       friend void slave_gradcalc(void);
01121       friend void gradloop();
01122       friend void default_evaluation(void);
01123       friend class grad_stack;
01124       friend void gradient_structure::jacobcalc(int nvar,BOR_CONST dmatrix& jac);
01125       //friend void gradient_structure::funnel_jacobcalc(void);
01126     };
01127     void default_evaluation3ind(void);
01128 
01129     class grad_stack
01130     {
01131       grad_stack_entry * true_ptr_first;
01132       grad_stack_entry * ptr_first;
01133       grad_stack_entry * ptr_last;
01134       long int length;
01135       long int true_length;
01136     public:
01137       grad_stack_entry * ptr;
01138     private:
01139       //lvector * table;
01140       // js
01141       int _GRADFILE_PTR; // should be int gradfile_handle;
01142       int _GRADFILE_PTR1; // should be int gradfile_handle;
01143       int _GRADFILE_PTR2; // should be int gradfile_handle;
01144       int _VARSSAV_PTR; // should be int gradfile_handle;
01145       char gradfile_name[61];
01146       char gradfile_name1[61];
01147       char gradfile_name2[61];
01148       char var_store_file_name[61];
01149       void create_gradfile();
01150       long end_pos;
01151       long end_pos1;
01152       long end_pos2;
01153       dmatrix * table;
01154     public:
01155       friend void gradcalc(int nvar,BOR_CONST dvector& g);
01156       friend void slave_gradcalc(void);
01157       friend void funnel_gradcalc(void);
01158       friend void default_evaluation(void);
01159       friend void default_evaluation3ind(void);
01160       friend void reset_gradient_stack(void);
01161       friend void default_evaluation4ind(void);
01162       friend void grad_chk(void);
01163       friend void gradloop();
01164       friend void cleanup_temporary_files();
01165       ostream& operator  <<(grad_stack);
01166      void print();
01167       grad_stack();
01168      ~grad_stack();
01169       void write_grad_stack_buffer(void);
01170 
01171        void set_gradient_stack(void (* func) (void),
01172    double * dep_addr,double * ind_addr1=NULL, double mult1=0,
01173    double * ind_addr2=NULL, double mult2=0);
01174 
01175        void set_gradient_stack(void (* func) (void),
01176    double * dep_addr,double * ind_addr1,double * ind_addr2);
01177 
01178 
01179       void set_gradient_stack0(void (* func)(void),
01180         double * dep_addr);
01181 
01182        void set_gradient_stack1(void (* func) (void),
01183    double * dep_addr,double * ind_addr1);
01184 
01185        void set_gradient_stack2(void (* func) (void),
01186    double * dep_addr,double * ind_addr1, double mult1);
01187 
01188        void set_gradient_stack4(void (* func) (void),
01189    double * dep_addr,double * ind_addr1, double * ind_addr2);
01190 
01191        void set_gradient_stack(void (* func)(void),
01192         double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
01193         double mult2,double * ind_addr3, double mult3,double * ind_addr4,
01194         double mult4);
01195     
01196        void set_gradient_stack(void (* func)(void),
01197         double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
01198         double mult2,double * ind_addr3, double mult3);
01199     
01200       int read_grad_stack_buffer(my_off_t& lpos);
01201       void set_gradient_stack(void (*ptr)(void));
01202       void set_gbuffer_pointers(void);
01203        //js
01204       void increment_current_gradfile_ptr(void);
01205       int decrement_current_gradfile_ptr(void);
01206       //void open_gradfile();
01207       //void close_gradfile();
01208       #ifndef __MSC__
01209   int& gradfile_handle();
01210       #else
01211   int gradfile_handle();
01212       #endif
01213       char* get_gradfile_name();
01214       friend class gradient_structure;
01215       //int get_ngradfiles();
01216     }; // end of grad_stack
01217 
01218 
01219 #ifdef OPT_LIB
01220     
01221     inline void grad_stack::set_gradient_stack(void (* func)(void),
01222       double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
01223       double mult2)
01224     {
01225       #ifdef NO_DERIVS
01226   if (!gradient_structure::no_derivatives)
01227   {
01228       #endif
01229 #     if defined(MYDEBUG)
01230           int wrote_buffer=0;
01231 #     endif
01232     if (ptr > ptr_last)
01233     {
01234        // current buffer is full -- write it to disk and reset pointer
01235        // and counter
01236        this->write_grad_stack_buffer();
01237 #     if defined(MYDEBUG)
01238              wrote_buffer=1;
01239 #     endif
01240     }
01241 #     if defined(MYDEBUG)
01242           if (wrote_buffer==1)
01243           {
01244             cout << "WROTE BUFFER" << endl;
01245           }
01246 #     endif
01247     ptr->func = func;
01248     ptr->dep_addr = dep_addr;
01249     ptr->ind_addr1 = ind_addr1;
01250     ptr->mult1=mult1;
01251     ptr->ind_addr2 = ind_addr2;
01252     ptr->mult2=mult2;
01253     ptr++;
01254       #ifdef NO_DERIVS
01255   }
01256       #endif
01257     }
01258 #else
01259   //  void grad_stack::set_gradient_stack(void (* func)(void),
01260    //   double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
01261     //  double mult2);
01262 #endif
01263 
01264     inline void grad_stack::set_gradient_stack(void (* func)(void),
01265       double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
01266       double mult2,double * ind_addr3, double mult3)
01267     {
01268       #ifdef NO_DERIVS
01269   if (!gradient_structure::no_derivatives)
01270   {
01271       #endif
01272     if (ptr > ptr_last)
01273     {
01274        // current buffer is full -- write it to disk and reset pointer
01275        // and counter
01276        this->write_grad_stack_buffer();
01277     }
01278     ptr->func = NULL;
01279     ptr->dep_addr = dep_addr;
01280     ptr->ind_addr1 = ind_addr1;
01281     ptr->mult1=mult1;
01282     ptr->ind_addr2 = ind_addr2;
01283     ptr->mult2=mult2;
01284     ptr++;
01285     if (ptr > ptr_last)
01286     {
01287        // current buffer is full -- write it to disk and reset pointer
01288        // and counter
01289        this->write_grad_stack_buffer();
01290     }
01291     ptr->func = func;
01292     ptr->ind_addr1 = ind_addr3;
01293     ptr->mult1=mult3;
01294     ptr++;
01295       #ifdef NO_DERIVS
01296   }
01297       #endif
01298     }
01299 
01300     inline void grad_stack::set_gradient_stack(void (* func)(void),
01301       double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
01302       double mult2,double * ind_addr3, double mult3,double * ind_addr4,
01303       double mult4)
01304     {
01305       #ifdef NO_DERIVS
01306   if (!gradient_structure::no_derivatives)
01307   {
01308       #endif
01309     if (ptr > ptr_last)
01310     {
01311        // current buffer is full -- write it to disk and reset pointer
01312        // and counter
01313        this->write_grad_stack_buffer();
01314     }
01315     ptr->func = NULL;
01316     ptr->dep_addr = dep_addr;
01317     ptr->ind_addr1 = ind_addr1;
01318     ptr->mult1=mult1;
01319     ptr->ind_addr2 = ind_addr2;
01320     ptr->mult2=mult2;
01321     ptr++;
01322     if (ptr > ptr_last)
01323     {
01324        // current buffer is full -- write it to disk and reset pointer
01325        // and counter
01326        this->write_grad_stack_buffer();
01327     }
01328     ptr->func = func;
01329     ptr->ind_addr1 = ind_addr3;
01330     ptr->mult1=mult3;
01331     ptr->ind_addr2 = ind_addr4;
01332     ptr->mult2=mult4;
01333     ptr++;
01334       #ifdef NO_DERIVS
01335   }
01336       #endif
01337     }
01338 
01339     inline void grad_stack::set_gradient_stack(void (* func)(void),
01340       double * dep_addr,double * ind_addr1,double * ind_addr2)
01341     {
01342       #ifdef NO_DERIVS
01343   if (!gradient_structure::no_derivatives)
01344   {
01345       #endif
01346     if (ptr > ptr_last)
01347     {
01348        // current buffer is full -- write it to disk and reset pointer
01349        // and counter
01350        this->write_grad_stack_buffer();
01351     }
01352     ptr->func = func;
01353     ptr->dep_addr = dep_addr;
01354     ptr->ind_addr1 = ind_addr1;
01355     ptr->ind_addr2 = ind_addr2;
01356     ptr++;
01357       #ifdef NO_DERIVS
01358   }
01359       #endif
01360     }
01361 
01362     inline void grad_stack::set_gradient_stack2(void (* func)(void),
01363       double * dep_addr,double * ind_addr1, double mult1)
01364     {
01365       #ifdef NO_DERIVS
01366         if (!gradient_structure::no_derivatives)
01367         {
01368       #endif
01369           if (ptr > ptr_last)
01370           {
01371              // current buffer is full -- write it to disk and reset pointer
01372              // and counter
01373              this->write_grad_stack_buffer();
01374           }
01375           ptr->func = func;
01376           ptr->dep_addr = dep_addr;
01377           ptr->ind_addr1 = ind_addr1;
01378           ptr->mult1=mult1;
01379           ptr++;
01380       #ifdef NO_DERIVS
01381         }
01382       #endif
01383     }
01384 
01385     inline void grad_stack::set_gradient_stack4(void (* func)(void),
01386       double * dep_addr,double * ind_addr1, double * ind_addr2)
01387     {
01388       #ifdef NO_DERIVS
01389   if (!gradient_structure::no_derivatives)
01390   {
01391       #endif
01392     if (ptr > ptr_last)
01393     {
01394        // current buffer is full -- write it to disk and reset pointer
01395        // and counter
01396        this->write_grad_stack_buffer();
01397     }
01398     ptr->func = func;
01399     ptr->dep_addr = dep_addr;
01400     ptr->ind_addr1 = ind_addr1;
01401     ptr->ind_addr2 = ind_addr2;
01402     ptr++;
01403       #ifdef NO_DERIVS
01404   }
01405       #endif
01406     }
01407 
01408 
01409 
01410    /*
01411     inline void grad_stack::set_gradient_stack(void (* func)(void),
01412       double * dep_addr,double * ind_addr1, double mult1)
01413     {
01414       #ifdef NO_DERIVS
01415   if (!gradient_structure::no_derivatives)
01416   {
01417       #endif
01418     if (ptr > ptr_last)
01419     {
01420        // current buffer is full -- write it to disk and reset pointer
01421        // and counter
01422        this->write_grad_stack_buffer();
01423     }
01424     ptr->func = func;
01425     ptr->dep_addr = dep_addr;
01426     ptr->ind_addr1 = ind_addr1;
01427     ptr->mult1=mult1;
01428           ptr++;
01429       #ifdef NO_DERIVS
01430         }
01431       #endif
01432     }
01433     */
01434    /*
01435     void grad_stack::set_gradient_stack1(void (* func)(void),
01436       double * dep_addr,double * ind_addr1)
01437     {
01438       #ifdef NO_DERIVS
01439         if (!gradient_structure::no_derivatives)
01440         {
01441       #endif
01442           if (ptr > ptr_last)
01443           {
01444              // current buffer is full -- write it to disk and reset pointer
01445              // and counter
01446              this->write_grad_stack_buffer();
01447           }
01448           ptr->func = func;
01449           ptr->dep_addr = dep_addr;
01450           ptr->ind_addr1 = ind_addr1;
01451           ptr++;
01452       #ifdef NO_DERIVS
01453         }
01454       #endif
01455     }
01456   */
01457 
01458    /*
01459     inline void grad_stack::set_gradient_stack(void (* func)(void),
01460       double * dep_addr,double * ind_addr1)
01461     {
01462       #ifdef NO_DERIVS
01463         if (!gradient_structure::no_derivatives)
01464         {
01465       #endif
01466           if (ptr > ptr_last)
01467           {
01468              // current buffer is full -- write it to disk and reset pointer
01469              // and counter
01470              this->write_grad_stack_buffer();
01471           }
01472           ptr->func = func;
01473           ptr->dep_addr = dep_addr;
01474           ptr->ind_addr1 = ind_addr1;
01475           ptr++;
01476       #ifdef NO_DERIVS
01477         }
01478       #endif
01479     }
01480    */
01481 
01482    /*
01483     inline void grad_stack::set_gradient_stack0(void (* func)(void),
01484       double * dep_addr)
01485     {
01486       #ifdef NO_DERIVS
01487         if (!gradient_structure::no_derivatives)
01488         {
01489       #endif
01490           if (ptr > ptr_last)
01491           {
01492              // current buffer is full -- write it to disk and reset pointer
01493              // and counter
01494              this->write_grad_stack_buffer();
01495           }
01496           ptr->func = func;
01497           ptr->dep_addr = dep_addr;
01498           ptr++;
01499       #ifdef NO_DERIVS
01500         }
01501       #endif
01502     }
01503    */
01504 
01505    /*
01506     inline void grad_stack::set_gradient_stack(void (* func)(void),
01507       double * dep_addr)
01508     {
01509       #ifdef NO_DERIVS
01510         if (!gradient_structure::no_derivatives)
01511         {
01512       #endif
01513           if (ptr > ptr_last)
01514           {
01515              // current buffer is full -- write it to disk and reset pointer
01516              // and counter
01517              this->write_grad_stack_buffer();
01518           }
01519           ptr->func = func;
01520           ptr->dep_addr = dep_addr;
01521           ptr++;
01522       #ifdef NO_DERIVS
01523         }
01524       #endif
01525     }
01526 */
01527     inline void grad_stack::set_gradient_stack(void (*func)(void))
01528     {
01529       #ifdef NO_DERIVS
01530         if (!gradient_structure::no_derivatives)
01531         {
01532       #endif
01533           if (ptr > ptr_last)
01534           {
01535             // current buffer is full -- write it to disk and reset pointer
01536             // and counter
01537             this->write_grad_stack_buffer();
01538           }
01539 
01540           ptr->dep_addr = NULL;
01541           ptr->func = func;
01542           ptr->ind_addr2 = NULL ;// want to put a long int                                            //into the memory space of a double
01543           ptr->mult2=0;
01544           ptr++;
01545       #ifdef NO_DERIVS
01546         }
01547       #endif
01548     }
01549 
01550     class indvar_offset_list
01551     {
01552       int nvar; // The number of independent variables
01553       double **  address;
01554   
01555     public:
01556       friend class gradient_structure;
01557       inline double * get_address(BOR_CONST int& i) { return(address[i]);}
01558       void put_address(unsigned int& i, double * iaddress) 
01559       { 
01560         address[i] = iaddress;
01561         //  cerr << "In put_address i = " << i << "\n";
01562       }
01563     };
01564 
01565     void gradfree(dlink *);
01566 
01567   class prevariable_position;
01568 
01569   class prevariable
01570   {
01571   protected:
01572 #ifndef __SUN__
01573     prevariable(void) { }
01574 #endif
01575 #ifndef __NDPX__
01576     prevariable(double_and_int * u) {v=u;}
01577 #endif
01578 
01579   public:
01580     double_and_int * v;
01581     friend class dvar_vector_iterator;
01582     friend class dvar_vector;
01583     friend class dvar_matrix;
01584     friend class dvar3_array;
01585     //shclass sc;
01586     friend class indvar_offset_list;
01587     friend class gradient_structure;
01588     friend double_and_int * gradnew();
01589     friend void make_indvar_list(int ,dvariable *);
01590 
01591     friend class banded_symmetric_dvar_matrix;
01592     friend class banded_lower_triangular_dvar_matrix;
01593     friend double& value(_CONST prevariable& v1);
01594 
01595     friend double * address(_CONST prevariable& v1);
01596 
01597     //void gradfree(dlink * v)
01598 
01599     friend prevariable& operator *(_CONST prevariable& v1,_CONST prevariable& v2);
01600 
01601     friend prevariable& operator *( double v1,_CONST prevariable& v2);
01602 
01603     friend prevariable& operator *(_CONST prevariable& v1, double v2);
01604 
01605     friend prevariable& operator / (_CONST prevariable& t1,_CONST prevariable& t2);
01606 
01607     friend prevariable& operator / ( double t1,_CONST prevariable& t2);
01608 
01609     friend prevariable& operator / (_CONST prevariable& t1, double t2);
01610 
01611     friend prevariable& sin(_CONST prevariable& t1);
01612 
01613     friend prevariable& fabs(_CONST prevariable& t1);
01614     friend prevariable& sigmoid(_CONST prevariable& t1);
01615 
01616     friend prevariable& sfabs(_CONST prevariable& t1); //"smoothed absolute value function
01617 
01618     friend prevariable& sqrt(_CONST prevariable& t1);
01619     friend prevariable& sqr(_CONST prevariable& t1);
01620 
01621     friend prevariable& exp(_CONST prevariable& t1);
01622 
01623     friend prevariable& atan(_CONST prevariable& t1);
01624 
01625     friend prevariable& tan(_CONST prevariable& t1);
01626     friend prevariable& tanh(_CONST prevariable& t1);
01627 
01628     friend prevariable& atan2(_CONST prevariable& t1,_CONST prevariable& t2);
01629     friend prevariable& atan2(_CONST prevariable& t1, double t2);
01630     friend prevariable& atan2( double t1,_CONST prevariable& t2);
01631 
01632     friend prevariable& acos(_CONST prevariable& t1);
01633 
01634     friend prevariable& asin(_CONST prevariable& t1);
01635 
01636     friend prevariable& cos(_CONST prevariable& t1);
01637     friend prevariable& sinh(_CONST prevariable& t1);
01638     friend prevariable& cosh(_CONST prevariable& t1);
01639 
01640     friend prevariable& log(_CONST prevariable& t1);
01641     friend prevariable& log10(_CONST prevariable& t1);
01642 
01643     friend prevariable& ldexp(_CONST prevariable&, BOR_CONST int&);
01644 
01645 
01646   public:
01647 
01648    void save_prevariable_position(void) _CONST;
01649    prevariable_position restore_prevariable_position(void);
01650    void save_prevariable_value(void) _CONST;
01651    double restore_prevariable_value(void);
01652    double restore_prevariable_derivative(void);
01653 
01654 
01655    inline double * xadr() { return( &(v->x) ); }
01656    inline double& xval() { return( (v->x) ); }
01657 
01658    inline double_and_int * & get_v()
01659    {
01660      return v;
01661    }
01662    #ifdef USE_CONST
01663      inline double_and_int *  get_v() _CONST 
01664      {
01665        return v;
01666      }
01667    #endif
01668 
01669    prevariable& operator=(_CONST prevariable&);
01670    prevariable& operator=( double );
01671 #if (__BORLANDC__  >= 0x0540) 
01672    prevariable& operator=(_CONST prevariable&)_CONST ;
01673    prevariable& operator=( double )_CONST ;
01674 #endif
01675 
01676    int operator ==(_CONST prevariable& v1) _CONST;
01677    int operator <=(_CONST prevariable& v1) _CONST;
01678    int operator >=(_CONST prevariable& v1) _CONST;
01679    int operator >(_CONST prevariable& v1) _CONST;
01680    int operator <(_CONST prevariable& v1) _CONST;
01681    int operator !=(_CONST prevariable& v1) _CONST;
01682 
01683    int operator ==( double v1) _CONST;
01684    int operator <=( double v1) _CONST;
01685    int operator >=( double v1) _CONST;
01686    int operator >( double v1) _CONST;
01687    int operator <( double v1) _CONST;
01688    int operator !=( double v1) _CONST;
01689 #if defined(USE_DDOUBLE)
01690    int operator ==( int v1) _CONST;
01691    int operator <=( int v1) _CONST;
01692    int operator >=( int v1) _CONST;
01693    int operator >( int v1) _CONST;
01694    int operator <( int v1) _CONST;
01695    int operator !=( int v1) _CONST;
01696 #endif
01697 
01698   public:
01699 #ifdef __SUN__
01700     prevariable(void) { }
01701 #endif
01702 #ifdef __NDPX__
01703     prevariable(double_and_int * u) {v=u;}
01704 #endif
01705 
01706     void initialize(void);
01707 
01708     friend char* fform(const char*,_CONST prevariable&);
01709 
01710     void operator +=(_CONST prevariable& t1);
01711     void operator +=( double t1);
01712 
01713     void operator -=(_CONST prevariable& t1);
01714     void operator -=( double t1);
01715 
01716     void operator /=(_CONST prevariable& v1);
01717     void operator /=( double v1);
01718 
01719     void operator *=(_CONST prevariable& v1);
01720     void operator *=( double v1);
01721 
01722     friend prevariable& operator +(_CONST prevariable& v1,_CONST prevariable& v2);
01723 
01724     friend prevariable& operator +( double v1,_CONST prevariable& v2);
01725 
01726     friend prevariable& operator +(_CONST prevariable& v1, double v2);
01727 
01728     friend prevariable& operator -(_CONST prevariable& v1);
01729 
01730     friend prevariable& operator -(_CONST prevariable& v1,_CONST prevariable& v2);
01731 
01732     friend prevariable& operator -( double v1,_CONST prevariable& v2);
01733 
01734     friend prevariable& operator -(_CONST prevariable& v1, double v2);
01735 
01736     friend prevariable& pow(_CONST prevariable& t1,_CONST prevariable& t2);
01737 
01738     friend prevariable& pow(_CONST prevariable& t1, double t2);
01739 
01740     friend prevariable& pow( double t1,_CONST prevariable& t2);
01741 
01742   }; // end of class prevariable
01743 
01744   inline double& value(_CONST prevariable& v1) { return(v1.v->x); }
01745   inline double * address(_CONST prevariable& v1) { return(&(v1.v->x)); }
01746 
01747 
01748   prevariable& operator << (BOR_CONST prevariable& v1,_CONST prevariable& v2);
01749   dvar_vector& operator << (BOR_CONST dvar_vector& v1,_CONST dvar_vector& v2);
01750   dvar_matrix& operator << (BOR_CONST dvar_matrix& v1,_CONST dvar_matrix& v2);
01751 
01752   class df1_one_variable;
01753 
01754   class dvariable : public prevariable
01755   {
01756   public:
01757      dvariable();
01758      ~dvariable();
01759      dvariable( double t);
01760      dvariable(BOR_CONST int& t);
01761      dvariable(kkludge_object);
01762      dvariable(_CONST prevariable&);
01763      dvariable& operator=(_CONST prevariable&);
01764      dvariable& operator = (const df1_one_variable& v);
01765      dvariable& operator=( double);
01766 #if defined(USE_DDOUBLE)
01767 #  undef double
01768      dvariable& operator=( double);
01769 #  define double dd_real
01770 #endif
01771      dvariable(_CONST dvariable&);
01772 //#  if (__BORLANDC__  > 0x0520) 
01773 //     dvariable& operator+=(_CONST prevariable&);
01774 //#  endif
01775 
01776   }; // end of class dvariable
01777 
01778 #if defined(max)
01779 #undef max
01780 #endif
01781 #if defined(min)
01782 #undef min
01783 #endif
01784 
01785   class funnel_dvariable : public dvariable
01786   {
01787   public:
01788      dvariable& operator=(_CONST prevariable&);
01789   };
01790 
01791  // spreadsheet like element wise operations
01792 
01793   dvar_vector operator * (_CONST dvar_vector& t1, double x);
01794   dvar_vector operator / ( double x,_CONST dvar_vector& t1);
01795   dvar_vector operator / (_CONST dvar_vector& t1, double x);
01796   dvar_vector operator + ( double x,_CONST dvar_vector& t1);
01797   dvar_vector operator + (_CONST dvar_vector& t1, double x);
01798   dvar_vector operator - ( double x,_CONST dvar_vector& t1);
01799   dvar_vector operator - (_CONST dvar_vector& t1, double x);
01800   dvar_vector operator - (_CONST dvar_vector& t1);
01801   dvar_vector operator * (_CONST dvar_vector& t1,_CONST prevariable& x);
01802   dvar_vector operator / (_CONST prevariable& x,_CONST dvar_vector& t1);
01803   dvar_vector operator / (_CONST dvar_vector& t1,_CONST prevariable& x);
01804   dvar_vector operator + (_CONST prevariable& x,_CONST dvar_vector& t1);
01805   dvar_vector operator + (_CONST dvar_vector& t1,_CONST prevariable& x);
01806   dvar_vector operator - (_CONST prevariable& x,_CONST dvar_vector& t1);
01807   dvar_vector operator - (_CONST dvar_vector& t1,_CONST prevariable& x);
01808   dvar_vector operator - (_CONST dvector& t1,_CONST prevariable& x);
01809   dvar_vector operator * (_CONST dvector& t1,_CONST prevariable& x);
01810   dvar_vector operator * (_CONST prevariable& x,_CONST dvector& t1);
01811 
01812   dvector operator * (_CONST dvector& t1, double x);
01813   dvector operator / ( double x,_CONST dvector& t1);
01814   dvector operator / (_CONST dvector& t1, double x);
01815   dvector operator + ( double x,_CONST dvector& t1);
01816   dvector operator + (_CONST dvector& t1, double x);
01817   dvector operator - ( double x,_CONST dvector& t1);
01818   dvector operator - (_CONST  dvector& t1, double x);
01819   dvector operator - (_CONST dvector& t1);
01820 
01821   double max(_CONST dmatrix&);
01822   int max(const imatrix&);
01823   double max(_CONST dvector&);
01824   dvariable max(_CONST dvar_vector&);
01825   dvariable min(_CONST dvar_vector&);
01826 
01827   dmatrix symmetrize(_CONST dmatrix& m1);
01828   dvector eigenvalues(_CONST dmatrix& m1);
01829   dmatrix eigenvectors(_CONST dmatrix& m1);
01830   dmatrix eigenvectors(_CONST dmatrix& m1,BOR_CONST dvector& eigenvalues);
01831 
01832   dvar_matrix symmetrize(_CONST dvar_matrix& m1);
01833   dvar_vector eigenvalues(_CONST dvar_matrix& m1);
01834   dvar_matrix eigenvectors(_CONST dvar_matrix& m1);
01835 
01836   dmatrix outer_prod(_CONST dvector& t1 ,_CONST dvector& t2 );
01837   dvar_matrix outer_prod(_CONST dvar_vector& t1 ,_CONST dvar_vector& t2 );
01838   dvar_matrix outer_prod(_CONST dvector& t1 ,_CONST dvar_vector& t2 );
01839   dvar_matrix outer_prod(_CONST dvar_vector& t1 ,_CONST dvector& t2 );
01840   //double trace(_CONST dmatrix&);
01841   //dvariable trace(_CONST dvar_matrix&);
01842   dmatrix operator * ( double x,_CONST dmatrix& m);
01843   dmatrix operator * (_CONST dmatrix& m, double d);
01844   dmatrix operator / (_CONST dmatrix& m, double d);
01845   dmatrix operator / ( double d,_CONST dmatrix& m);
01846   dmatrix operator + ( double x,_CONST dmatrix& m);
01847   dvar_matrix operator + ( const dvariable& x,const dmatrix& m);
01848   dvar_matrix operator - ( const dvariable& x,const dmatrix& m);
01849   dmatrix operator + (_CONST dmatrix& m, double d);
01850   dmatrix operator - ( double x,_CONST dmatrix& m);
01851   dmatrix operator - (_CONST dmatrix& m, double d);
01852   dvar_matrix operator / (_CONST dvar_matrix& m,_CONST prevariable& x);
01853   dvar_matrix operator / (_CONST dmatrix& m,_CONST prevariable& x);
01854   dvar_matrix operator / (_CONST dvar_matrix& m, double x);
01855   dvar_matrix operator / ( double x,_CONST dvar_matrix& m);
01856   dvar_matrix operator / (_CONST prevariable& x,_CONST dvar_matrix& m);
01857 
01858   dvar_matrix operator * (_CONST prevariable& x,_CONST dmatrix& m);
01859   dvar_matrix operator * (_CONST dvar_matrix& m,_CONST prevariable& x);
01860   dvar_matrix operator * (_CONST prevariable& x,_CONST dvar_matrix& m);
01861   dvar_matrix operator * ( double x,_CONST dvar_matrix& m);
01862 
01863   dvector operator & (_CONST dvector& t1,_CONST dvector& t2);
01864   dvar_vector operator & (_CONST dvar_vector& t1,_CONST dvar_vector& t2);
01865 
01866 
01867   ivector column(_CONST imatrix& m,int i);
01868   dvector extract_column(_CONST dmatrix& m,int i);
01869   dvector column(_CONST dmatrix& m,int i);
01870   dvector extract_row(_CONST dmatrix& m, int j);
01871   dvector row(_CONST dmatrix& m, int j);
01872   dvar_vector extract_column(_CONST dvar_matrix& m, int i);
01873   dvar_vector column(_CONST dvar_matrix& m, int i);
01874   dvector column_value(const dvar_matrix& m, int i);
01875   dvar_vector extract_row(_CONST dvar_matrix& m, int j);
01876   dvar_vector row(_CONST dvar_matrix& m, int j);
01877 
01878 // dvector mathematical functions
01879 
01880      dvector sin(_CONST dvector& t1);
01881      dvector sqrt(_CONST dvector& t1);
01882      dvector sqr(_CONST dvector& t1);
01883      dvector exp(_CONST dvector& t1);
01884      dvector mfexp(_CONST dvector& t1);
01885      dvector mfexp(_CONST dvector& t1, double d);
01886      dvector atan(_CONST dvector& t1);
01887      dvector tan(_CONST dvector& t1);
01888      dvector tanh(_CONST dvector& t1);
01889      dvector atan2(_CONST dvector& t1,_CONST dvector& t2);
01890      dvector atan2(_CONST dvector& t1, double t2);
01891      dvector atan2( double t1,_CONST dvector& t2);
01892      dvector acos(_CONST dvector& t1);
01893      dvector asin(_CONST dvector& t1);
01894      dvector cos(_CONST dvector& t1);
01895      dvector sinh(_CONST dvector& t1);
01896      dvector cosh(_CONST dvector& t1);
01897      dvector log(_CONST dvector& t1);
01898      dvector log10(_CONST dvector& t1);
01899      dvector pow(_CONST dvector& t1, double);
01900      dvector pow(_CONST dvector& t1,int);
01901      dvector pow( double,_CONST dvector& t1);
01902      ivector pow(const ivector& v1, int x); 
01903      ivector pow(int x,const ivector& v1); 
01904 
01905 // end of dvector mathematical functions
01906 
01907 // dvar_vector mathematical functions
01908 
01909      dvar_vector sin(_CONST dvar_vector& t1);
01910      dvar_vector sqrt(_CONST dvar_vector& t1);
01911      dvar_vector sqr(_CONST dvar_vector& t1);
01912      dvar_vector exp(_CONST dvar_vector& t1);
01913      dvar_vector mfexp(_CONST dvar_vector& t1);
01914      dvar_vector mfexp(_CONST dvar_vector& t1, double d);
01915      dvar_vector atan(_CONST dvar_vector& t1);
01916      dvar_vector tan(_CONST dvar_vector& t1);
01917      dvar_vector tanh(_CONST dvar_vector& t1);
01918      dvar_vector atan2(_CONST dvar_vector& t1,_CONST dvar_vector& t2);
01919      dvar_vector atan2(_CONST dvar_vector& t1, double t2);
01920      dvar_vector atan2( double t1,_CONST dvar_vector& t2);
01921      dvar_vector acos(_CONST dvar_vector& t1);
01922      dvar_vector asin(_CONST dvar_vector& t1);
01923      dvar_vector cos(_CONST dvar_vector& t1);
01924      dvar_vector sinh(_CONST dvar_vector& t1);
01925      dvar_vector cosh(_CONST dvar_vector& t1);
01926      dvar_vector log(_CONST dvar_vector& t1);
01927      dvar_vector log10(_CONST dvar_vector& t1);
01928      dvar_vector pow(_CONST dvar_vector&,_CONST dvar_vector& t1);
01929      dvar_vector pow(_CONST dvar_vector&,_CONST dvector& t1);
01930      dvar_vector pow(_CONST dvector&,_CONST dvar_vector& t1);
01931      dvar_vector pow(_CONST dvar_vector& t1, double);
01932      dvar_vector pow(_CONST dvar_vector& t1,int);
01933      dvar_vector pow(_CONST dvar_vector& t1,_CONST prevariable&);
01934      dvar_vector pow(_CONST dvector& t1,_CONST prevariable&);
01935      dvar_vector pow(_CONST prevariable&,_CONST dvar_vector& t1);
01936 
01937 // end of dvar_vector mathematical functions
01938 
01939 // dmatrix mathematical functions
01940     dmatrix exp(_CONST dmatrix& m);
01941     dmatrix mfexp(_CONST dmatrix& m);
01942     dmatrix mfexp(_CONST dmatrix& m, double d);
01943     dmatrix sqrt(_CONST dmatrix& m);
01944     dmatrix sqr(_CONST dmatrix& m);
01945     dmatrix pow(_CONST dmatrix& m, double e);
01946     dmatrix pow(_CONST dmatrix& m,int e);
01947     dmatrix log(_CONST dmatrix& m);
01948     dmatrix sin(_CONST dmatrix& m);
01949     dmatrix cos(_CONST dmatrix& m);
01950     dmatrix tan(_CONST dmatrix& m);
01951     dmatrix elem_div(_CONST dmatrix& m,_CONST dmatrix& m2);
01952     dmatrix elem_prod(_CONST dmatrix& m,_CONST dmatrix& m2);
01953 // end of dmatrix mathematical functions
01954 
01955 //  dvar_matrix mathematical functions
01956     dvar_matrix exp(_CONST dvar_matrix& m);
01957     dvar_matrix mfexp(_CONST dvar_matrix& m);
01958     dvar_matrix mfexp(_CONST dvar_matrix& m, double d);
01959     dvar_matrix sqrt(_CONST dvar_matrix& m);
01960     dvar_matrix sqr(_CONST dvar_matrix& m);
01961     dvar_matrix log(_CONST dvar_matrix& m);
01962     dvar_matrix sin(_CONST dvar_matrix& m);
01963     dvar_matrix cos(_CONST dvar_matrix& m);
01964     dvar_matrix tan(_CONST dvar_matrix& m);
01965     dvar_matrix pow(_CONST dvar_matrix& m, double e);
01966     dvar_matrix pow(_CONST dvar_matrix& m,_CONST prevariable& e);
01967     dvar_matrix pow(_CONST dmatrix& m,_CONST prevariable& e);
01968     dvar_matrix pow(_CONST dvar_matrix& m,int e);
01969     dvar_matrix elem_prod(_CONST dvar_matrix& m,_CONST dvar_matrix& m2);
01970     dvar_matrix elem_prod(_CONST dvar_matrix& m,_CONST dmatrix& m2);
01971     dvar_matrix elem_prod(_CONST dmatrix& m,_CONST dvar_matrix& m2);
01972     dvar_matrix elem_div(_CONST dvar_matrix& m,_CONST dvar_matrix& m2);
01973     dvar_matrix elem_div(_CONST dvar_matrix& m,_CONST dmatrix& m2);
01974     dvar_matrix elem_div(_CONST dmatrix& m,_CONST dvar_matrix& m2);
01975 //  end of dvar_matrix mathematical functions
01976 
01977   int min(_CONST ivector& t1);
01978   int max(_CONST ivector& t1);
01979   int Max(_CONST ivector& t1);
01980 
01981      double mfexp(double);
01982      double mfexp(double,double bound);
01983      dvariable mfexp(const prevariable&);
01984      dvariable mfexp(const prevariable&,double bound);
01985 
01986 #ifndef DVEC_ARR_HPP
01987 #define DVEC_ARR_HPP
01988 
01989   class vector_shapex 
01990   {
01991   public:
01992     void * trueptr;
01993     vector_shapex(int lb,int ub,void * p) : index_min(lb), 
01994       index_max(ub), ncopies(0), trueptr(p) {}
01995     void * get_truepointer(void){ return trueptr; }
01996     friend class dvector;
01997     friend class ivector;
01998     //friend class tdvector;
01999     friend class dvar_vector;
02000 #if defined(USE_VECTOR_SHAPE_POOL)
02001     static vector_shape_pool * xpool;
02002     void * operator new(size_t);
02003     void operator delete(void * ptr,size_t n)
02004     {  xpool->free(ptr); }
02005 #endif
02006     unsigned int ncopies;
02007     void shift(int min);
02008     int index_min;
02009     int index_max;
02010   private:
02011     friend class subdvector;
02012     friend class lvector;
02013     friend class ptr_vector;
02014   public:
02015     int decr_ncopies(void) {return --ncopies;}
02016     int get_ncopies(void) {return ncopies;}
02017     int incr_ncopies(void) {return ++ncopies;}
02018     int indexmin(){return index_min;}
02019     int indexmax(){return index_max;}
02020   };
02021   class predvector
02022   {
02023     dvector * p;
02024     int lb;
02025     int ub;
02026     inline predvector(dvector * _p,int _lb,int _ub) {p=_p;lb=_lb,ub=_ub;}
02027     friend class dvector;
02028   };
02029 
02030   class predvar_vector
02031   {
02032     dvar_vector * p;
02033     int lb;
02034     int ub;
02035     inline predvar_vector(dvar_vector * _p,int _lb,int _ub) {p=_p;lb=_lb,ub=_ub;}
02036     friend class dvar_vector;
02037   };
02043   class dvector 
02044   {
02045   protected:
02046     double * v;
02047     int index_min;
02048     int index_max;
02049     vector_shapex * shape;
02050 
02051   public:
02052     dvector operator -();
02053     int operator ! (void) _CONST {return (shape == NULL);}
02054     int allocated(void) _CONST {return (shape != NULL);}
02055     dvector& operator -- (void) 
02056     { 
02057       index_min--;index_max--;v++; return *this;
02058     }
02059     dvector& operator ++ (void)  
02060     { 
02061       index_min++;index_max++;v--; return *this;
02062     }
02063     void reallocate(double size);
02064   dvector sub(int lb,int ub)
02065   {
02066     return predvector(this,lb,ub);
02067   }
02068   dvector operator () (int lb,int ub)
02069   {
02070     return predvector(this,lb,ub);
02071   }
02072   dvector(const predvector& pd);
02073   //virtual void write_message(void) { cout << " This is a dvector" << endl; }
02074   
02075   void fill_randpoisson(double lambda, BOR_CONST random_number_generator& rng);
02076   void fill_randnegbinomial(double lambda,double tau,
02077    const random_number_generator& rng);
02078   void shallow_copy(const dvector&);
02079 
02080     friend class banded_symmetric_dvar_matrix;
02081     friend class banded_lower_triangular_dvar_matrix;
02082     friend class banded_symmetric_dmatrix;
02083     friend class banded_lower_triangular_dmatrix;
02084     
02085 //#ifdef HOME_VERSION
02086       void allocate(int ncl,int ncu);
02087       void allocate(_CONST dvector& dv);
02088       void allocatec(_CONST dvector& dv);
02089       void allocate(_CONST dvar_vector&);
02090       void allocate(const char *);
02091       void allocate(void);
02092       void deallocate(void);
02093       void safe_deallocate(void);
02094       void safe_allocate(int,int);
02095 //#endif
02096 
02097     _CONST double * address() _CONST { return (v); }
02098     double*& get_v(void) { return (v); }
02099     double& elem(int i) { return(v[i]); }
02100     double* initpointer(void) { return (v+indexmin()); }
02101     #ifdef USE_CONST
02102       _CONST double* initpointer(void) _CONST { return (v+indexmin()); }
02103       double* get_v(void) _CONST { return (v); }
02104       _CONST double& elem(int i) _CONST { return(v[i]); }
02105     #endif
02106 
02107     void fill(const char * s);
02108     void fill_randu_ni(long int& n);
02109     void fill_randn_ni(long int& n);
02110     void fill_randbi_ni(long int& n,double);
02111 
02112     void fill_randu(long int& n);
02113     void fill_randn(long int& n);
02114     void fill_randbi(long int& n,double);
02115 
02116 
02117     void fill_randbi(double p,BOR_CONST random_number_generator& rng);
02118     void fill_randu(BOR_CONST random_number_generator& rng);
02119     void fill_randn(BOR_CONST random_number_generator& rng);
02120     void fill_randcau(BOR_CONST random_number_generator& rng);
02121 
02122     void fill_seqadd( double, double);
02123     void fill_multinomial(BOR_CONST int& seed,_CONST dvector& p);
02124     void fill_multinomial(BOR_CONST random_number_generator& rng,_CONST dvector& p);
02125     void initialize(void);
02126 
02127     int& testmin()  {return shape->index_min;} // returns the minimum allowable index
02128 
02129     int& testmax() {return shape->index_max;} // returns the minimum allowable index
02130 
02131     int indexmin() _CONST {return index_min;} // returns the minimum allowable index
02132 
02133     int indexmax() _CONST {return index_max;} // returns the maximum allowable index
02134     int size() _CONST {return (index_max - index_min+1);} // returns the number of elements
02135     dvector& shift(int min);
02136 
02137   
02138     dvector(BOR_CONST dvar_vector_position& dvp,BOR_CONST kkludge_object&);
02139 
02140     dvector(const ad_integer&,const index_type&);
02141     void allocate(const ad_integer&,const index_type&);
02152     dvector(void);
02153 
02162     dvector(_CONST dvector&);
02163 
02164     /* Not used.
02165     //dvector(_CONST dvector&,int lb,int ub);
02166     */
02167 
02168     dvector(_CONST ivector&);
02169 
02170     dvector(_CONST lvector&);
02171 
02172     dvector(const char *);
02173 
02182     dvector( int ncl,  int ncu);
02183                                            // makes an array [ncl..ncu]
02184 
02185     dvector( unsigned int sz, double * x);
02186 
02187     dvector(char * filename, const int& column);
02188 
02189     //operator double* () { return v;}
02190 
02191    ~dvector();
02192 
02193     void save_dvector_position(void) _CONST;
02194     void save_dvector_derivatives(BOR_CONST dvar_vector_position& pos) _CONST;
02195     void save_dvector_derivatives_na(BOR_CONST dvar_vector_position& pos) _CONST;
02196     void save_dvector_derivatives(void) _CONST;
02197     void save_dvector_value(void) _CONST;
02198 
02199     //dvector operator()(int,int);
02200     dvector operator()(_CONST lvector&);
02201     dvector operator ()(_CONST ivector& u);
02202 
02203     dvector& operator += (_CONST dvector& v1);
02204     dvector& operator -= (_CONST dvector& v1);
02205     dvector& operator += ( double v1);
02206     dvector& operator /= ( double v1);
02207     dvector& operator *= ( double v1);
02208     dvector& operator -= ( double v1);
02209 
02210     void read_from(BOR_CONST uistream&);
02211 
02212     friend class sdmatrix;
02213     friend double norm(_CONST dvector&);
02214     friend double norm2(_CONST dvector&);
02215     friend class dvar_vector;
02216     friend class dmatrix;
02217     friend class d3_array;
02218     friend char* fform(const char*,_CONST dvector&);
02219 
02220     void write_on(BOR_CONST ostream&) _CONST;
02221     void write_on(BOR_CONST uostream&) _CONST;
02222     void read_from(BOR_CONST istream&);
02223     friend double operator * (_CONST dvector& ,_CONST dvector& );
02224 
02225     friend dvariable operator * (_CONST dvector& ,_CONST dvar_vector& );
02226 
02227     friend dvariable operator * (_CONST dvar_vector& ,_CONST dvector& );
02228 
02229     friend dvar_vector operator * (_CONST prevariable& ,_CONST dvector& );
02230 
02231     friend dvector operator * ( double ,_CONST dvector& );
02232 
02233     friend dvector operator + (_CONST dvector& ,_CONST dvector& );
02234 
02235     friend dvector elem_prod(_CONST dvector& ,_CONST dvector& );
02236 
02237     friend dvector first_difference(_CONST dvector&);
02238     friend dvector second_difference(_CONST dvector&);
02239 
02240     friend dvector elem_div(_CONST dvector& ,_CONST dvector& );
02241 
02242     friend dvar_vector elem_prod(_CONST dvector& ,_CONST dvar_vector& );
02243 
02244     friend dvar_vector elem_div(_CONST dvector&,_CONST dvar_vector&);
02245 
02246     friend dvar_vector elem_prod(_CONST dvar_vector&,_CONST dvector& );
02247 
02248     friend dvar_vector elem_div(_CONST dvar_vector& ,_CONST dvector& );
02249 
02250     friend dvar_vector operator + (_CONST dvar_vector& ,_CONST dvector& );
02251 
02252     friend dvar_vector operator + (_CONST dvector& ,_CONST dvar_vector& );
02253 
02254     friend dvector operator - (_CONST dvector& ,_CONST dvector& );
02255 
02256     friend dvar_vector operator - (_CONST dvar_vector& ,_CONST dvector& );
02257 
02258     friend dvar_vector operator - (_CONST dvector& ,_CONST dvar_vector& );
02259 
02260     friend dvector  operator * (_CONST dvector& x,_CONST dmatrix& m);
02261 
02262     friend dvector  operator * (_CONST dmatrix& x,_CONST dvector& m);
02263 
02264     friend dvar_vector  operator * (_CONST dvector& x,_CONST dvar_matrix& m);
02265 
02266     friend dvar_vector  operator * (_CONST dvar_matrix& x,_CONST dvector& m);
02267 
02268 
02269 #ifdef OPT_LIB
02270       inline double& operator[] (register int i) { return(*(v+i)); }
02271       inline double& operator() (register int i) { return(*(v+i)); }
02272 #else
02273       double& operator[] (int i);
02274       double& operator() (int i);
02275 #endif
02276 
02277 #ifdef USE_CONST
02278   #ifdef OPT_LIB
02279     inline _CONST double& operator[] (register int i) _CONST { return(*(v+i)); }
02280     inline _CONST double& operator() (register int i) _CONST { return(*(v+i)); }
02281   #else
02282       _CONST double& operator[] (int i) _CONST;
02283       _CONST double& operator() (int i) _CONST;
02284   #endif
02285 #endif
02286 
02287 
02288     dvector& operator = (_CONST dvector& t);
02289 
02290     dvector& operator = ( double x);
02291 
02292     friend dvector exp(_CONST dvector&);
02293 
02294     friend dvector log(_CONST dvector&);
02295 
02296     friend dvector fabs(_CONST dvector&);
02297 
02298     friend double max(_CONST dvector&);
02299 
02300     friend double min(_CONST dvector&);
02301 
02302  }; // end of class dvector
02303 
02304 class independent_variables : public dvector 
02305 {
02306   public:
02307 
02308     independent_variables(BOR_CONST independent_variables& v) : dvector(v) {}
02309 
02310     independent_variables( int ncl,  int ncu) :
02311       dvector(ncl,ncu) {}
02312                                            // makes an array [ncl..ncu]
02313 
02314     independent_variables( unsigned int sz, double * x) :
02315       dvector(sz, x) {}
02316 
02317     independent_variables& operator = (_CONST dvector& t);
02318 
02319 };
02320      
02321 
02322 #endif
02323 
02324 dvariable dfatan1( dvariable , double , double ,BOR_CONST prevariable&fpen);
02325 
02326 double boundp( double x, double fmin, double fmax,const double& fpen);
02327 double boundp( double x, double fmin, double fmax);
02328 
02329 dvariable boundp(const prevariable & x, double fmin, double fmax,const prevariable& fpen);
02330 dvariable boundp(const prevariable & x, double fmin, double fmax,const prevariable& fpen,double s);
02331 
02332 double nd2fboundp(double x,double minb,double maxb,const double& pen);
02333 double boundpin(double x, double fmin, double fmax);
02334 double boundpin(const prevariable& x, double fmin, double fmax);
02335 double boundpin(const prevariable& x, double fmin, double fmax,double s);
02336 
02337 double dmin(double, double );
02338 
02339 double dmax(double i, double j);
02340 
02341 
02342 
02343 
02344 #include <stdlib.h>
02345 #ifdef __TURBOC__
02346 #  if !defined(__linux__)
02347 #    include <alloc.h>
02348 #  endif
02349 #endif
02350 
02351 
02352    double sigmoid( double t1);
02353 
02354   class mat_shape 
02355   {
02356     unsigned int ncopies;
02357     unsigned int nrows;
02358     unsigned int ncols; 
02359     int row_min;
02360     int row_max;
02361     int col_min;
02362     int col_max;
02363     mat_shape(int rl,int ru,int cl=0,int cu=-1);
02364     mat_shape(){};
02365     void colshift(int min);
02366     void rowshift(int min);
02367 
02368     //friend class const_dmatrix;
02369     friend class dmatrix;
02370     friend class sdmatrix;
02371     friend class dvar_matrix;
02372     friend class imatrix;
02373     friend class lmatrix;
02374     friend class i3_array;
02375   };
02376 
02377   class mat_shapex 
02378   {
02379   public:
02380     void * trueptr;
02381     unsigned int ncopies;
02382     mat_shapex(_CONST void * m) { trueptr=(void*)m;ncopies=0;}
02383     mat_shapex(){trueptr=NULL;ncopies=0;};
02384 
02385     void * get_pointer (void) {return trueptr;}
02386     friend class dmatrix;
02387     friend class sdmatrix;
02388     friend class dvar_matrix;
02389     friend class imatrix;
02390     friend class i3_array;
02391     friend class lmatrix;
02392   };
02393 
02394     class arr_link;
02395     class arr_list
02396     {
02397       arr_link * last;
02398       arr_link * free_last;
02399       unsigned long int last_offset;
02400       unsigned long int max_last_offset;
02401     public:
02402       long int number_arr_links;
02403       friend class arr_link;
02404   
02405     public:
02406     
02407       arr_list(void)
02408       {
02409         last = 0;
02410         free_last = 0;
02411         last_offset = 0;
02412         max_last_offset = 0;
02413         number_arr_links = 0;
02414       }
02415       unsigned long int get_last_offset() { return last_offset;}
02416       unsigned long int get_number_arr_links(){ return(number_arr_links);}
02417       unsigned long int get_max_last_offset() { return (max_last_offset);}
02418       void reset_max_last_offset() {max_last_offset=0;}
02419       friend double_and_int * arr_new(unsigned int);
02420       friend void arr_free(double_and_int *);
02421       friend void arr_remove(arr_link **);
02422       friend void arr_free_list_remove(arr_link **);
02423       friend void arr_free_add(arr_link *);
02424       friend void arr_free_remove(arr_link *);
02425     };
02426 
02427     class arr_link
02428     {
02429 #if defined(USE_VECTOR_SHAPE_POOL)
02430     static vector_shape_pool * xpool;
02431     void * operator new(size_t);
02432     void operator delete(void * ptr,size_t n) 
02433     {  xpool->free(ptr); }
02434 #endif
02435        arr_link *          prev;
02436        arr_link *          next;
02437        arr_link *          free_prev;
02438        arr_link *          free_next;
02439        unsigned int        status;
02440        // unsigned int     free_list_status;
02441        unsigned int        size;
02442        unsigned long int   offset;
02443      public:
02444        arr_link();
02445     
02446        friend double_and_int * arr_new(unsigned int);
02447        friend void arr_free(double_and_int *);
02448        friend void arr_remove(arr_link **);
02449        friend void arr_free_remove(arr_link *);
02450        friend void arr_free_add(arr_link *);
02451     };
02452 
02453 #if defined(__NUMBERVECTOR__)
02454   class param_init_number_vector;
02455   class param_init_bounded_number_vector;
02456   class param_init_vector_vector;
02457   class param_init_bounded_vector_vector;
02458 #endif
02459 
02460  class dvar_vector
02461  {
02462  public:
02463    double_and_int * va;
02464    int index_min;
02465    int index_max;
02466    arr_link * link_ptr;
02467    vector_shapex * shape;
02468  public:
02469     dvar_vector operator -();
02470 
02471     dvar_vector& operator -- (void) 
02472     { 
02473       index_min--;index_max--;va++; return *this;
02474     }
02475     dvar_vector& operator ++ (void)  
02476     { 
02477       index_min++;index_max++;va--; return *this;
02478     }
02479   dvar_vector sub(int lb,int ub)
02480   {
02481     return predvar_vector(this,lb,ub);
02482   }
02483   dvar_vector operator () (int lb,int ub)
02484   {
02485     return predvar_vector(this,lb,ub);
02486   }
02487   void shallow_copy(const dvar_vector&);
02488  int operator ! (void) _CONST {return (shape == NULL);}
02489  friend class dvar_matrix;
02490  friend class dvar3_array;
02491     friend class banded_symmetric_dvar_matrix;
02492     friend class banded_lower_triangular_dvar_matrix;
02493     friend class banded_symmetric_dmatrix;
02494     friend class banded_lower_triangular_dmatrix;
02495 
02496  void fill_randpoisson(double lambda, BOR_CONST random_number_generator& rng);
02497  void fill_randnegbinomial(double lambda,double tau,
02498   const random_number_generator& rng);
02499  prevariable elem(int i) { return (va+i); }
02500 
02501  double& elem_value(int i) { return (va[i].x); }
02502 
02503  double_and_int * get_va(){return va;}
02504 
02505 #ifdef USE_CONST
02506   prevariable elem(int i) _CONST { return (va+i); }
02507 
02508   double& elem_value(int i) _CONST { return (va[i].x); }
02509 
02510   double_and_int * get_va() _CONST {return va;}
02511 #endif
02512 
02513 
02514     friend dvar_matrix  operator * (_CONST dvar_matrix& m1,_CONST dmatrix& m2 );
02515 
02516     void deallocate();
02517     dvar_vector(_CONST dvar_vector&);
02518     dvar_vector(const predvar_vector&);
02519     dvar_vector();
02520     dvar_vector(int ncl,int ncu); // makes an array [ncl..ncu]
02521     dvar_vector(int ncl,int ncu,kkludge_object);
02522 
02523     //dvar_vector(const ad_integer&,const ad_integer&);
02524     dvar_vector( unsigned int sz, double * x);
02525     dvar_vector(BOR_CONST independent_variables&);
02526     friend char* fform(const char*,_CONST dvar_vector& );
02527 #   if defined(__NUMBERVECTOR__)
02528     dvar_vector(const param_init_number_vector&);
02529     dvar_vector(const param_init_bounded_number_vector&);
02530 #   endif
02531     dvar_vector(_CONST dvector&);
02532     dvar_vector(const char *);
02533    ~dvar_vector();
02534     void allocate(int,int);
02535     void allocate(void);
02536     void allocate(_CONST dvector&);
02537     void allocatec(_CONST dvar_vector&);
02538     void allocate(_CONST dvar_vector&);
02539 
02540     void allocate(const ad_integer&,const ad_integer&);
02541     void initialize(_CONST dvector& ww);
02542     void initialize(void);
02543     void save_dvar_vector_position(void) _CONST;
02544     void save_dvar_vector_value(void) _CONST;
02545     void write_on(BOR_CONST ostream&) _CONST;
02546     void write_on(BOR_CONST uostream&) _CONST;
02547     void read_from(BOR_CONST istream&);
02548     void read_from(BOR_CONST uistream&);
02549     int indexmin() _CONST {return index_min;} // returns the minimum allowable index
02550     int indexmax() _CONST {return index_max;} // returns the maximum allowable index
02551     int size() _CONST {return (index_max - index_min+1);} // returns the number of elements
02552     dvar_vector& shift(int min);
02553 
02554 #ifdef OPT_LIB
02555  #if defined(__NDPX__) || defined(__SUN__)
02556   inline prevariable operator() (register int i) { return (va+i); }
02557   inline prevariable operator[] (register int i) { return (va+i); }
02558       #ifdef USE_CONST
02559   inline _CONST prevariable operator() (int i) _CONST { return (va+i); }
02560   inline _CONST prevariable operator[] (int i) _CONST { return (va+i); }
02561       #endif
02562  #else
02563   inline prevariable operator() (int i) { return (va+i); }
02564   inline prevariable operator[] (int i) { return (va+i); }
02565   #ifdef USE_CONST
02566   inline _CONST prevariable operator() (int i) _CONST { return (va+i); }
02567   inline _CONST prevariable operator[] (int i) _CONST { return (va+i); }
02568   #endif
02569  #endif
02570 #else
02571   prevariable operator[] (int i);
02572   prevariable operator() (int i);
02573   #ifdef USE_CONST
02574   _CONST prevariable operator[] (int i) _CONST;
02575   _CONST prevariable operator() (int i) _CONST;
02576   #endif
02577 #endif
02578 
02579     double* initpointer(void) { return ((double*)(va+indexmin())); }
02580   #ifdef USE_CONST
02581     _CONST double* initpointer(void) _CONST { return ((double *)(va+indexmin())); }
02582 #endif
02583     dvar_vector operator()(_CONST lvector&);
02584     //dvar_vector operator()(int,int);
02585     dvar_vector operator ()(_CONST ivector& u);
02586     dvar_vector& operator+= (_CONST prevariable& d);
02587     dvar_vector& operator+= (double d);
02588     dvar_vector& operator/= (_CONST prevariable& d);
02589     //dvar_vector& operator*= (_CONST dvariable& d);
02590     dvar_vector& operator*= (_CONST prevariable& d);
02591     dvar_vector& operator*= ( double d);
02592     dvar_vector& operator/= ( double d);
02593     dvar_vector& operator-= (_CONST prevariable& d);
02594     dvar_vector& operator-= (double d);
02595     dvar_vector& operator+= (_CONST dvector& v1);
02596     dvar_vector& operator-= (_CONST dvector& v1);
02597     dvar_vector& operator+= (_CONST dvar_vector& v1);
02598     dvar_vector& operator-= (_CONST dvar_vector& v1);
02599     dvar_vector& operator = (_CONST dvar_vector& t);
02600     dvar_vector& operator = (_CONST dvector& t);
02601     dvar_vector& operator = ( double t);
02602     dvar_vector& operator = (_CONST prevariable& t);
02603     void fill(const char *);
02604     void fill_randu(long int& n);
02605     void fill_randn(long int& n);
02606     void fill_randbi(long int& n,double);
02607 
02608     void fill_randu_ni(long int& n);
02609     void fill_randn_ni(long int& n);
02610     void fill_randbi_ni(long int& n,double);
02611 
02612     void fill_seqadd( double, double);
02613     void fill_multinomial(BOR_CONST int& seed,_CONST dvector& p);
02614     void fill_multinomial(BOR_CONST random_number_generator& rng,_CONST dvector& p);
02615     friend dvar_vector operator + (_CONST dvar_vector& ,_CONST dvar_vector&);
02616     friend dvar_vector operator + (_CONST dvar_vector& ,_CONST dvector&);
02617     friend dvar_vector operator + (_CONST dvector& ,_CONST dvar_vector&);
02618     friend dvar_vector operator - (_CONST dvar_vector& ,_CONST dvar_vector&);
02619 
02620     friend dvar_vector operator - (_CONST dvector& ,_CONST dvar_vector&);
02621 
02622     friend dvar_vector operator - (_CONST dvar_vector& ,_CONST dvector&);
02623 
02624     friend dvar_vector sigmoid(_CONST dvar_vector& t1);
02625 
02626     friend dvariable operator * (_CONST dvar_vector& ,_CONST dvar_vector&);
02627 
02628     friend dvar_vector elem_div(_CONST dvar_vector& ,_CONST dvar_vector&);
02629 
02630     friend dvariable operator * (_CONST dvector& ,_CONST dvar_vector&);
02631 
02632     friend dvariable operator * (_CONST dvar_vector& ,_CONST dvector&);
02633 
02634     friend dvar_vector operator * (_CONST prevariable& ,_CONST dvar_vector&);
02635 
02636     friend dvar_vector operator * (_CONST prevariable& ,_CONST dvector& );
02637 
02638     friend dvar_vector operator * ( double ,_CONST dvar_vector&);
02639 
02640     friend dvar_vector operator * (_CONST dvar_vector& ,_CONST dmatrix& );
02641 
02642     friend dvar_vector operator * (_CONST dmatrix& ,_CONST dvar_vector& );
02643 
02644     friend dvar_vector operator * (_CONST dvar_vector& ,_CONST dvar_matrix& );
02645 
02646     friend dvar_vector operator * (_CONST dvar_matrix& ,_CONST dvar_vector& );
02647 
02648     friend dvar_matrix operator * (_CONST dvar_matrix& ,_CONST dvar_matrix& );
02649 
02650     friend dvar_matrix operator * (_CONST dmatrix& , _CONST dvar_matrix& );
02651 
02652     friend dvar_vector elem_prod(_CONST dvar_vector&,_CONST dvar_vector& );
02653 
02654     friend dvar_vector first_difference(_CONST dvar_vector&);
02655     friend dvar_vector second_difference(_CONST dvar_vector&);
02656 
02657     //friend dvar_vector elem_div(_CONST dvar_vector& ,_CONST dvar_vector& ); // js, see above
02658 
02659     friend dvar_vector elem_prod(_CONST dvector& ,_CONST dvar_vector& );
02660 
02661     friend dvar_vector elem_div(_CONST dvector&,_CONST dvar_vector&);
02662 
02663     friend dvar_vector elem_prod(_CONST dvar_vector&,_CONST dvector& );
02664 
02665     friend dvar_vector elem_div(_CONST dvar_vector& ,_CONST dvector& );
02666 
02667     friend dvariable norm(_CONST dvar_vector&);
02668     friend dvariable norm2(_CONST dvar_vector&);
02669 
02670 
02671     friend void copy_status(BOR_CONST ostream& s,_CONST dvar_vector& v);
02672 
02673     friend dvar_vector exp(_CONST dvar_vector&);
02674 
02675     friend dvar_vector log(_CONST dvar_vector&);
02676 
02677     friend dvar_vector sin(_CONST dvar_vector&);
02678 
02679     friend dvar_vector fabs(_CONST dvar_vector&);
02680 
02681     friend dvector value(_CONST dvar_vector& v1);
02682 
02683     friend dvar_vector sfabs(_CONST dvar_vector&);
02684 
02685     friend void make_indvar_list(_CONST dvar_vector&);
02686     friend class array_size;
02687 
02688  }; // end of class dvar_vector
02689 
02690  /*
02691  class funnel_dvar_vector : public dvar_vector
02692  {
02693  public:
02694     funnel_dvar_vector(int l,int u);
02695     dvar_vector& operator=(_CONST dvar_vector&);
02696  };
02697  */
02698    class fvar_ptr
02699    {
02700      dvar_vector * p;
02701    };
02702 
02703 
02704  class dvar_matrix
02705  {
02706     int index_min;
02707     int index_max;
02708     dvar_vector * m;
02709     mat_shapex * shape;
02710 
02711  public:
02712     dvar_matrix& operator -- (void) 
02713     { 
02714       index_min--;index_max--;m++; return *this;
02715     }
02716     dvar_matrix& operator ++ (void)  
02717     { 
02718       index_min++;index_max++;m--; return *this;
02719     }
02720   
02721     int operator ! (void) _CONST {return (shape == NULL);}
02722   inline dvar_vector& elem(int i) { return (m[i]); }
02723   inline prevariable elem(int i, int j) { return (elem(i).elem(j) ) ; }
02724   #ifdef USE_CONST
02725     inline dvar_vector& elem(int i) const { return (m[i]); }
02726     inline prevariable elem(int i, int j) const {return (elem(i).elem(j) ) ; }
02727   #endif
02728 
02729     friend class banded_symmetric_dvar_matrix;
02730     friend class banded_lower_triangular_dvar_matrix;
02731     friend class banded_symmetric_dmatrix;
02732     friend class banded_lower_triangular_dmatrix;
02733 friend class dvar3_array;
02734 //#ifdef HOME_VERSION
02735   void shallow_copy(const dvar_matrix&);
02736   dvar_matrix();
02737   void allocate(int nrl,int nrh,int ncl,int nch);
02738   void allocate(int nrl,int nrh);
02739   void allocate(ad_integer nrl,ad_integer nrh);
02740   void allocate(_CONST dmatrix& m1);
02741   void allocate(_CONST dvar_matrix& m1);
02742   void allocate(int nrl,int nrh,_CONST ivector& ncl,_CONST ivector& nch);
02743   void allocate(int nrl,int nrh,int ncl,_CONST ivector& nch);
02744   void allocate(int nrl,int nrh,_CONST ivector& ncl,int nch);
02745   void allocate(void);
02746   void deallocate();
02747 //#endif
02748   dvar_matrix(_CONST banded_symmetric_dvar_matrix&v);
02749   dvar_matrix(_CONST banded_lower_triangular_dvar_matrix&v);
02750 # if defined(__NUMBERVECTOR__)
02751     dvar_matrix(const param_init_vector_vector& );
02752     dvar_matrix(const param_init_bounded_vector_vector&);
02753 # endif
02754   dvar_matrix sub(int,int);
02755 
02756     double fill_seqadd( double, double);
02757 
02758     int colmin(void) _CONST { return((*this)(indexmin()).indexmin());}
02759     int colmax(void) _CONST { return((*this)(indexmin()).indexmax());}
02760     int rowmin(void) _CONST { return(index_min);}
02761     int rowmax(void) _CONST { return(index_max);}
02762     int indexmin(void) _CONST { return(index_min);}
02763     int indexmax(void) _CONST { return(index_max);}
02764     int rowsize() _CONST {return (rowmax()-rowmin()+1);} // returns the number of rows
02765     int colsize() _CONST {return (colmax()-colmin()+1);} // returns the number of columns
02766     void colshift(int min);
02767     void rowshift(int min);
02768 
02769     friend char* fform(const char*,_CONST dvar_matrix&);
02770 
02771     friend class dvar_vector;
02772 
02773     dvar_matrix(const ad_integer& nrl,const ad_integer& nrh,
02774       const index_type& ncl,const index_type& nch);
02775 
02776     void allocate(const ad_integer& nrl,const ad_integer& nrh,
02777       const index_type& ncl,const index_type& nch);
02778 
02779     dvar_matrix( int,  int,  int,  int );
02780     dvar_matrix( int,  int);
02781     dvar_matrix( int,  int, kkludge_object kk);
02782              // makes a matrix [nrl..nrh][ncl..nch]
02783 
02784     dvar_matrix(int,int,_CONST ivector&,_CONST ivector&);
02785              // makes a ragged dvar_matrix [nrl..nrh][ncl..nch]
02786 
02787     dvar_matrix(int,int,int,_CONST ivector&);
02788              // makes a ragged dvar_matrix [nrl..nrh][ncl..nch]
02789 
02790     dvar_matrix(_CONST dvar_matrix&);
02791              // copy initializer
02792     void initialize(void);
02793 
02794     dvar_matrix(_CONST dmatrix&);
02795 
02796     //dvar_matrix(char *);
02797 
02798    ~dvar_matrix();
02799 
02800     void save_dvar_matrix_position(void) _CONST;
02801     void save_dvar_matrix_value(void) _CONST;
02802 
02803     void fill(const char *);
02804     //void colfill(BOR_CONST int&n,...);
02805     //void rowfill(BOR_CONST int&n,...);
02806 
02807     void colfill_randu(BOR_CONST int&j,long int&n);
02808     void rowfill_randu(BOR_CONST int& i,long int& n);
02809     void colfill_randn(BOR_CONST int&j,long int&n);
02810     void rowfill_randn(BOR_CONST int& i,long int& n);
02811     void fill_randn(long int&n);
02812     void fill_randu(long int&n);
02813 
02814     void colfill_seqadd_ni(BOR_CONST int&, double, double);
02815     void colfill_randu_ni(BOR_CONST int&j,long int&n);
02816     void rowfill_randu_ni(BOR_CONST int& i,long int& n);
02817     void colfill_randn_ni(BOR_CONST int&j,long int&n);
02818     void rowfill_randn_ni(BOR_CONST int& i,long int& n);
02819     void fill_randn_ni(long int&n);
02820     void fill_randu_ni(long int&n);
02821 
02822     void colfill_seqadd(BOR_CONST int&, double, double);
02823     void rowfill_seqadd(BOR_CONST int&, double, double);
02824     void colfill(int j,_CONST dvar_vector& v);
02825     void rowfill(int j,_CONST dvar_vector& v);
02826 
02827     void write_on(BOR_CONST ostream&) _CONST;
02828     void write_on(BOR_CONST uostream&) _CONST;
02829     void read_from(BOR_CONST istream&);
02830     void read_from(BOR_CONST uistream&);
02831 
02832 #ifdef OPT_LIB
02833       inline dvar_vector& operator[] (register int i) { return (m[i]); }
02834       inline dvar_vector& operator() (register int i) { return (m[i]); }
02835 #else
02836       dvar_vector& operator () (int i);
02837       dvar_vector& operator[] (int) ;
02838 #endif
02839 
02840 #ifdef USE_CONST
02841   #ifdef OPT_LIB
02842       inline _CONST dvar_vector& operator[] (register int i) _CONST { return (m[i]); }
02843       inline _CONST dvar_vector& operator() (register int i) _CONST { return (m[i]); }
02844   #else
02845       _CONST dvar_vector& operator () (int i) _CONST;
02846       _CONST dvar_vector& operator[] (int) _CONST ;
02847   #endif
02848 #endif
02849 
02850   #ifdef OPT_LIB
02851     #ifdef __NDPX__
02852   prevariable operator () (register int i, register int j)
02853     { return ( prevariable((m[i]).va+j) ); }
02854     #else
02855   inline prevariable operator () (register int i, register int j)
02856     { return ( (m[i]).va+j ); }
02857     #endif
02858   #else
02859       prevariable operator () (int i, int j);
02860   #endif
02861 
02862   inline double& elem_value (register int i, register int j) 
02863     { return * (double*) ((m[i]).va+j); }
02864 
02865 #ifdef USE_CONST
02866   inline _CONST double& elem_value (register int i, register int j) _CONST
02867     { return * (double*) ((m[i]).va+j); }
02868   #ifdef OPT_LIB
02869     #ifdef __NDPX__
02870   prevariable operator () (register int i, register int j) _CONST
02871     { return ( prevariable((m[i]).va+j) ); }
02872     #else
02873   inline prevariable operator () (register int i, register int j) _CONST
02874     { return ( (m[i]).va+j ); }
02875     #endif
02876   #else
02877       _CONST prevariable operator () (int i, int j) _CONST;
02878   #endif
02879 #endif
02880 
02881     dvar_matrix& operator+= (_CONST dvar_matrix& x);
02882     dvar_matrix& operator-= (_CONST dvar_matrix& x);
02883     dvar_matrix& operator+= (_CONST dmatrix& x);
02884     dvar_matrix& operator-= (_CONST dmatrix& x);
02885 
02886 
02887     dvar_matrix& operator = (_CONST dvar_matrix& );
02888 
02889     dvar_matrix& operator = (_CONST dmatrix& );
02890     dvar_matrix& operator = ( double t);
02891     dvar_matrix& operator = (_CONST prevariable& t);
02892 
02893     dvar_matrix& operator *= (_CONST prevariable& t);
02894     dvar_matrix& operator *= ( double t);
02895     dvar_matrix& operator /= (_CONST prevariable& t);
02896     dvar_matrix& operator /= ( double t);
02897 
02898     friend dvar_vector operator * (_CONST dvar_vector& ,_CONST dvar_matrix& );
02899 
02900     friend dvar_vector operator * (_CONST dvar_matrix& ,_CONST dvar_vector& );
02901 
02902     friend dvar_vector operator * (_CONST dvector& ,_CONST dvar_matrix& );
02903 
02904     friend dvar_vector operator * (_CONST dvar_matrix& ,_CONST dvector& );
02905 
02906     friend dvar_matrix operator * (_CONST dvar_matrix& , _CONST dvar_matrix& );
02907 
02908     friend dvar_matrix operator * (_CONST dvar_matrix& , _CONST dmatrix& );
02909 
02910     friend dvar_matrix operator * (_CONST dmatrix& , _CONST dvar_matrix& );
02911 
02912     friend dvar_matrix operator + (_CONST dvar_matrix& ,_CONST dvar_matrix& );
02913     friend dvar_matrix operator + (_CONST dvar_matrix& ,_CONST dmatrix& );
02914     friend dvar_matrix operator + (_CONST dmatrix& ,_CONST dvar_matrix& );
02915 
02916     friend dvar_matrix operator + ( double ,_CONST dvar_matrix& );
02917     friend dvar_matrix operator + (_CONST dvar_matrix& , double );
02918     friend dvar_matrix operator - ( double ,_CONST dvar_matrix& );
02919     friend dvar_matrix operator - (_CONST dvar_matrix& , double );
02920 
02921     friend dvar_matrix operator + (_CONST dvariable& ,_CONST dvar_matrix& );
02922     friend dvar_matrix operator + (_CONST dvar_matrix& ,_CONST dvariable& );
02923     friend dvar_matrix operator - (_CONST dvariable& ,_CONST dvar_matrix& );
02924     friend dvar_matrix operator - (_CONST dvar_matrix& ,_CONST dvariable& );
02925 
02926     friend dvar_matrix operator - (_CONST dvar_matrix& ,_CONST dvar_matrix& );
02927     friend dvar_matrix operator - (_CONST dvar_matrix& ,_CONST dmatrix& );
02928     friend dvar_matrix operator - (_CONST dmatrix& ,_CONST dvar_matrix& );
02929 
02930     friend dvar_matrix inv(_CONST dvar_matrix&);
02931 
02932     friend dvariable det(_CONST dvar_matrix&);
02933     friend dvariable ln_det(const dvar_matrix&,const int& sgn);
02934 
02935     //friend dvar_matrix testsub(dvar_matrix);
02936 
02937     friend  dvar_matrix trans(_CONST dvar_matrix&);
02938 
02939     friend dvariable norm(_CONST dvar_matrix&);
02940     friend dvariable norm2(_CONST dvar_matrix&);
02941 
02942     friend void copy_status(BOR_CONST ostream& s,_CONST dvar_matrix& m1);
02943 
02944  }; // end of class dvar_matrix
02945 
02946 dvariable ln_det(const dvar_matrix&);
02947 dvar_matrix operator * (const dvar_matrix& t1, double x);
02948 dmatrix value(_CONST dvar_matrix& m);
02949 d3_array value(_CONST dvar3_array& a);
02950 dvar_vector sort(_CONST dvar_vector&,int NSTACK=60);
02951 dvector sort(_CONST dvector&,int NSTACK=60);
02952 ivector sort(_CONST ivector&,int NSTACK=60);
02953 dvector sort(_CONST dvector&,BOR_CONST ivector& index,int NSTACK=60);
02954 ivector sort(_CONST ivector&,BOR_CONST ivector& index,int NSTACK=60);
02955 dmatrix sort(_CONST dmatrix&,int column,int NSTACK=60);
02956 imatrix sort(_CONST imatrix&,int column,int NSTACK=60);
02957 
02958  //void gradcalc( int , double *);
02959  void gradcalc(int nvar,BOR_CONST dvector& g);
02960  void slave_gradcalc(void);
02961 
02962  class dmatrix
02963  {
02964  protected:
02965    int index_min;
02966    int index_max;
02967     dvector * m;
02968     mat_shapex * shape;
02969     friend char* fform(const char*,_CONST dmatrix&);
02970     friend class dvar_matrix;
02971  public:
02972  
02973     dmatrix& operator -- (void) 
02974     { 
02975       index_min--;index_max--;m++; return *this;
02976     }
02977     dmatrix& operator ++ (void)  
02978     { 
02979       index_min++;index_max++;m--; return *this;
02980     }
02981     void shallow_copy(const dmatrix&);
02982     int operator ! (void) _CONST {return (shape == NULL);}
02983 
02984     dmatrix sub(int,int);
02985 //#ifdef HOME_VERSION
02986     dmatrix(void); 
02987     dmatrix(int,int,kkludge_object); 
02988     dmatrix(int,int); 
02989     void allocate(void);
02990     void allocate(_CONST dmatrix& dm);
02991     void allocate(_CONST dvar_matrix&);
02992     void allocate(int nrl,int nrh,int ncl,int nch);
02993     void allocate(int nrl,int nrh);
02994     void allocate(ad_integer nrl,ad_integer nrh);
02995     void allocate(int nrl,int nrh,int ncl,const ivector& nch);
02996     //void allocate(int nrl,int nrh,
02997     // const index_type& ncl,const index_type& nch);
02998     void allocate(int nrl,int nrh,const ivector& ncl,int nch);
02999     void deallocate();
03000     void allocate(const ad_integer& nrl,const ad_integer& nrh,
03001       const index_type& ncl,const index_type& nch);
03002     void allocate(int nrl,int nrh,const ivector& ncl,const ivector& nch);
03003 //#endif
03004     friend class banded_symmetric_dmatrix;
03005     friend class banded_lower_triangular_dmatrix;
03006 
03007     dmatrix( int,  int,  int,  int );
03008              // makes a matrix [nrl..nrh][ncl..nch]
03009 
03010     dmatrix(const ad_integer& nrl,const ad_integer& nrh,
03011       const index_type& ncl,const index_type& nch);
03012 
03013     dmatrix(int,int,_CONST ivector& coll,_CONST ivector& colh);
03014              // makes a ragged dmatrix[nrl..nrh][ncl..nch]
03015 
03016     dmatrix(int,int,int coll,_CONST ivector& colh);
03017              // makes a ragged dmatrix[nrl..nrh][ncl..nch]
03018 
03019     dmatrix(BOR_CONST dvar_matrix_position&);
03020 
03021     dmatrix(BOR_CONST dmatrix_position&);
03022 
03023     dmatrix(_CONST dmatrix&);
03024     dmatrix(_CONST banded_symmetric_dmatrix&);
03025     dmatrix(_CONST banded_lower_triangular_dmatrix&);
03026     dmatrix(char *);
03027     void fill(const char *);
03028     double fill_seqadd( double, double);
03029     void initialize(void);
03030              // copy initializer
03031 
03032    ~dmatrix();
03033     void save_dmatrix_derivatives(BOR_CONST dvar_matrix_position& pos) _CONST;
03034     void save_dmatrix_derivatives_na(BOR_CONST dvar_matrix_position& pos) _CONST;
03035     void save_dmatrix_value(void) _CONST;
03036     void save_dmatrix_position(void) _CONST;
03037     //void save_dmatrix_derivatives(void);
03038 
03039     int indexmin(void) _CONST { return index_min;}
03040     int indexmax(void) _CONST { return index_max;}
03041     int rowmin(void) _CONST { return index_min;}
03042     int rowmax(void) _CONST { return index_max;}
03043     int colmin(void) _CONST { return((*this)(indexmin()).indexmin());}
03044     int colmax(void) _CONST { return((*this)(indexmin()).indexmax());}
03045     int rowsize() _CONST {return (rowmax()-rowmin()+1);} // returns the number of rows
03046     int colsize() _CONST {return (colmax()-colmin()+1);} // returns the number of columns
03047     void rowshift(int min);
03048     void colshift(int min);
03049 
03050     void write_on(BOR_CONST ostream&) _CONST;
03051     void write_on(BOR_CONST uostream&) _CONST;
03052     void read_from(BOR_CONST istream&);
03053     void read_from(BOR_CONST uistream&);
03054 
03055     //void colfill(BOR_CONST int&n,...);
03056     //void rowfill(BOR_CONST int&n,...);
03057 
03058     void colfill_randu(BOR_CONST int&j,long int&n);
03059     void rowfill_randu(BOR_CONST int& i,long int& n);
03060     void colfill_randn(BOR_CONST int&j,long int&n);
03061     void fill_randn(long int&n);
03062     void fill_randu(long int&n);
03063     void rowfill_randn(BOR_CONST int& i,long int& n);
03064 
03065 
03066 
03067     void colfill_randu(BOR_CONST int&j,BOR_CONST random_number_generator& rng);
03068     void rowfill_randu(BOR_CONST int& i,BOR_CONST random_number_generator& rng);
03069     void fill_randn(BOR_CONST random_number_generator& rng);
03070     void fill_randcau(BOR_CONST random_number_generator& rng);
03071     void fill_randu(BOR_CONST random_number_generator& rng);
03072     void colfill_randn(BOR_CONST int&j,BOR_CONST random_number_generator& rng);
03073     void rowfill_randn(BOR_CONST int& i,BOR_CONST random_number_generator& rng);
03074 
03075     void colfill_randu_ni(BOR_CONST int&j,long int&n);
03076     void rowfill_randu_ni(BOR_CONST int& i,long int& n);
03077     void colfill_randn_ni(BOR_CONST int&j,long int&n);
03078     void fill_randn_ni(long int&n);
03079     void fill_randu_ni(long int&n);
03080     void rowfill_randn_ni(BOR_CONST int& i,long int& n);
03081 
03082 
03083 
03084     void colfill_seqadd(BOR_CONST int&, double, double);
03085     void rowfill_seqadd(BOR_CONST int&, double, double);
03086     void colfill(int j,_CONST dvector& v);
03087     void rowfill(int j,_CONST dvector& v);
03088 
03089 #ifdef OPT_LIB
03090       inline dvector& operator() (register int i) { return m[i]; }
03091       inline double& operator() (register int i, register int j) {return(*(m[i].v+j));}
03092       inline dvector& operator[] (register int i) { return m[i]; }
03093 #else
03094       double& operator() (int i, int j);
03095       dvector& operator() (int i);
03096       dvector& operator[] (int) ;
03097 #endif
03098 
03099 #ifdef USE_CONST
03100   #ifdef OPT_LIB
03101       inline _CONST dvector& operator() (register int i) _CONST { return m[i]; }
03102       inline _CONST double& operator() (register int i, register int j) _CONST 
03103       {return(*(m[i].v+j));}
03104       inline _CONST dvector& operator[] (register int i) _CONST  { return m[i]; }
03105 #else
03106       _CONST double& operator() (int i, int j) _CONST;
03107       _CONST dvector& operator() (int i) _CONST;
03108       _CONST dvector& operator[] (int)  _CONST;
03109   #endif
03110 #endif
03111 
03112     inline dvector& elem(int i) { return( *(m+i) ); }
03113     inline double& elem(int i,int j) { return( *((*(m+i)).v+j) ); }
03114     #ifdef USE_CONST
03115       inline _CONST dvector& elem(int i) _CONST { return( *(m+i) ); }
03116       inline _CONST double& elem(int i,int j) _CONST 
03117         { return( *((*(m+i)).v+j) ); }
03118     #endif
03119     friend class d3_array;
03120     friend dvector operator * (_CONST dvector& ,_CONST dmatrix& );
03121 
03122     friend dvector operator * (_CONST dmatrix& ,_CONST dvector& );
03123 
03124     friend dvar_vector operator * (_CONST dvar_vector& ,_CONST dmatrix& );
03125 
03126     friend dvar_vector operator * (_CONST dmatrix& ,_CONST dvar_vector& );
03127 
03128     friend dmatrix operator * (_CONST dmatrix& , _CONST dmatrix& );
03129 
03130     friend dvar_matrix operator * (_CONST dvar_matrix& ,_CONST dmatrix& );
03131 
03132     friend dvar_matrix operator * (_CONST dmatrix& , _CONST  dvar_matrix& );
03133 
03134     friend dvar_matrix::dvar_matrix(_CONST dmatrix&);
03135 
03136     friend dmatrix operator - (_CONST dmatrix& ,_CONST dmatrix& );
03137     friend dmatrix operator + (_CONST dmatrix& ,_CONST dmatrix& );
03138 
03139     friend dvar_matrix operator + (_CONST dvar_matrix& ,_CONST dmatrix& );
03140 
03141     friend dvar_matrix operator + (_CONST dmatrix& ,_CONST dvar_matrix& );
03142 
03143     friend dmatrix  trans(_CONST dmatrix& m1);
03144 
03145     friend dmatrix inv(_CONST dmatrix&);
03146     friend dmatrix inv(_CONST dmatrix& m1,const double& _ln_det, const int& _sgn);
03147 
03148     friend double det(_CONST dmatrix&);
03149     friend double ln_det(_CONST dmatrix& m1,BOR_CONST int& sgn);
03150 
03151     friend double norm(_CONST dmatrix&);
03152     friend double norm2(_CONST dmatrix&);
03153 
03154     dmatrix& operator += (_CONST dmatrix& t);
03155     dmatrix& operator -= (_CONST dmatrix& t);
03156 
03157     dmatrix& operator = (const dmatrix& t);
03158     dmatrix& operator = ( double t);