Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011
00012
00013
00014 #include "fvar.hpp"
00015
00016 #ifdef __TURBOC__
00017 #pragma hdrstop
00018 #include <iostream.h>
00019 #endif
00020
00021 #ifdef __ZTC__
00022 #include <iostream.hpp>
00023 #endif
00024
00025
00026 #include <stdio.h>
00027 #include <math.h>
00028 #if !defined(OPT_LIB)
00029
00034 void grad_stack::set_gradient_stack(void (* func)(void),
00035 double * dep_addr,double * ind_addr1, double mult1, double * ind_addr2,
00036 double mult2)
00037 {
00038 #ifdef NO_DERIVS
00039 if (!gradient_structure::no_derivatives)
00040 {
00041 #endif
00042 # if defined(MYDEBUG)
00043 int wrote_buffer=0;
00044 if (ptr < ptr_first)
00045 {
00046 cerr << "Illegal ptr value" << endl;
00047 ad_exit(1);
00048 }
00049 # endif
00050 if (ptr > ptr_last)
00051 {
00052
00053
00054 this->write_grad_stack_buffer();
00055 # if defined(MYDEBUG)
00056 wrote_buffer=1;
00057 # endif
00058 }
00059 # if defined(MYDEBUG)
00060 # endif
00061 ptr->func = func;
00062 ptr->dep_addr = dep_addr;
00063 ptr->ind_addr1 = ind_addr1;
00064 ptr->mult1=mult1;
00065 ptr->ind_addr2 = ind_addr2;
00066 ptr->mult2=mult2;
00067 ptr++;
00068 #ifdef NO_DERIVS
00069 }
00070 #endif
00071 }
00072 #endif
00073
00078 prevariable& operator*( CGNU_DOUBLE x, const prevariable& v2)
00079 {
00080 if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN) gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00081 gradient_structure::RETURN_PTR->v->x = x * v2.v->x;
00082 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation2,
00083 &(gradient_structure::RETURN_PTR->v->x),&(v2.v->x),x);
00084 return(*gradient_structure::RETURN_PTR);
00085 }
00086
00091 prevariable& operator*(const prevariable& v1, CGNU_DOUBLE x)
00092 {
00093 if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN) gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00094 gradient_structure::RETURN_PTR->v->x= v1.v->x * x;
00095 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation2,
00096 &(gradient_structure::RETURN_PTR->v->x),&(v1.v->x),x);
00097 return(*gradient_structure::RETURN_PTR);
00098 }
00099
00104 void prevariable::operator/=(const prevariable& v1)
00105 {
00106 double tmp=1./(v1.v->x);
00107 v->x *= tmp;
00108 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation,&(v->x),
00109 &(v->x),tmp,&(v1.v->x),-(v->x)*tmp);
00110 }
00111
00116 void prevariable::operator /=( CGNU_DOUBLE v1)
00117 {
00118 double tmp=1./v1;
00119 v->x *= tmp;
00120 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation,&(v->x),
00121 &(v->x),tmp);
00122 }
00123
00128 void prevariable::operator*=(const prevariable& v1)
00129 {
00130 double * tmp=&((v1.v)->x);
00131 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation,&(v->x),
00132 &(v->x),*tmp,tmp,v->x);
00133 v->x *= *tmp;
00134 }
00135
00140 void prevariable::operator *=( CGNU_DOUBLE v1)
00141 {
00142 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation,&(v->x),
00143 &(v->x),v1);
00144 v->x *= v1;
00145 }