00001 /* 00002 * $Id: fvar2.cpp 542 2012-07-10 21:04:06Z johnoel $ 00003 * 00004 * Author: David Fournier 00005 * Copyright (c) 2008-2012 Regents of the University of California 00006 */ 00011 // file fvar.cpp 00012 // constructors, destructors and misc functions involving class prevariable 00013 #include "fvar.hpp" 00014 00015 #ifdef __TURBOC__ 00016 #pragma hdrstop 00017 #include <iostream.h> 00018 #endif 00019 00020 #ifdef __ZTC__ 00021 #include <iostream.hpp> 00022 #endif 00023 00024 00025 #include <stdio.h> 00026 #ifndef __SUN__ 00027 #endif 00028 #include <math.h> 00029 00030 void gradfree(dlink *); 00031 00036 double_and_int * gradnew() 00037 { 00038 #if defined (SAFE_ARRAYS) 00039 if (!gradient_structure::instances) 00040 { 00041 cerr << "Error -- you are trying to create a dvariable object" 00042 " when there is " << endl << "no object of type" 00043 " gradient_structure in scope " << endl; 00044 ad_exit(1); 00045 } 00046 #endif 00047 { 00048 dlink * tmp; 00049 tmp = gradient_structure::GRAD_LIST->last_remove(); 00050 if (!tmp) 00051 { 00052 tmp=gradient_structure::GRAD_LIST->create(); 00053 } 00054 00055 // cout << "In gradnew the address of the double * ptr is " 00056 // << _farptr_tolong(tmp) << "\n"; 00057 00058 return (double_and_int *) tmp; 00059 } 00060 } 00061 00066 void gradfree(dlink * v) 00067 { 00068 if (gradient_structure::GRAD_LIST) 00069 { 00070 if (gradient_structure::instances) 00071 { 00072 gradient_structure::GRAD_LIST->append(v); 00073 } 00074 else 00075 { 00076 delete (double_and_int *) v; 00077 v=NULL; 00078 } 00079 } 00080 } 00081 00082 //prevariable::prevariable(const prevariable& t) 00083 // { 00084 // v=t.v; 00085 // (*v).nc++; 00086 // } 00087 00093 dvariable::dvariable(const prevariable& t) 00094 { 00095 v=gradnew(); 00096 //(*v).nc=0; 00097 v->x=t.v->x; 00098 gradient_structure::GRAD_STACK1-> 00099 set_gradient_stack(default_evaluation1,&(v->x),&(t.v->x)); 00100 } 00101 00107 dvariable::dvariable(const dvariable& t) 00108 { 00109 v=gradnew(); 00110 v->x=t.v->x; 00111 gradient_structure::GRAD_STACK1-> 00112 set_gradient_stack(default_evaluation1,&(v->x),&(t.v->x)); 00113 } 00114 00120 dvariable::dvariable() 00121 { 00122 v=gradnew(); 00123 //(*v).nc=0; 00124 #ifdef SAFE_INITIALIZE 00125 (*v).x=0; 00126 gradient_structure::GRAD_STACK1->set_gradient_stack0(default_evaluation0,&((*v).x)); 00127 #endif 00128 } 00129 00133 dvariable::dvariable(kkludge_object) 00134 { 00135 v=gradnew(); 00136 //(*v).nc=0; 00137 } 00138 00142 dvariable::~dvariable() 00143 { 00144 gradfree( (dlink *) v ); 00145 } 00146 00153 dvariable::dvariable( CGNU_DOUBLE t) 00154 { 00155 v=gradnew(); 00156 v->x=t; 00157 //(*v).nc=0; 00158 gradient_structure::GRAD_STACK1->set_gradient_stack0(default_evaluation0, &(v->x) ); 00159 } 00160 00167 dvariable::dvariable(const int& t) 00168 { 00169 v=gradnew(); 00170 v->x=t; 00171 //(*v).nc=0; 00172 gradient_structure::GRAD_STACK1->set_gradient_stack0(default_evaluation0, &(v->x) ); 00173 }
|
|
Generated on Tue May 21 2013 12:31:50 for ADMB Documentation by 1.8.0
|