Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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 #include <stdio.h>
00025 #include <math.h>
00026 #if !defined(OPT_LIB)
00027
00032 void grad_stack::set_gradient_stack(void (* func)(void), double * dep_addr,
00033 double * ind_addr1, double mult1, double * ind_addr2, double mult2)
00034 {
00035 #ifdef NO_DERIVS
00036 if (!gradient_structure::no_derivatives)
00037 {
00038 #endif
00039 #if defined(MYDEBUG)
00040 int wrote_buffer=0;
00041 if (ptr < ptr_first)
00042 {
00043 cerr << "Illegal ptr value" << endl;
00044 ad_exit(1);
00045 }
00046 #endif
00047 if (ptr > ptr_last)
00048 {
00049
00050
00051 this->write_grad_stack_buffer();
00052 #if defined(MYDEBUG)
00053 wrote_buffer=1;
00054 #endif
00055 }
00056 ptr->func = func;
00057 ptr->dep_addr = dep_addr;
00058 ptr->ind_addr1 = ind_addr1;
00059 ptr->mult1=mult1;
00060 ptr->ind_addr2 = ind_addr2;
00061 ptr->mult2=mult2;
00062 ptr++;
00063 #ifdef NO_DERIVS
00064 }
00065 #endif
00066 }
00067 #endif
00068
00072 prevariable& operator*(double x, const prevariable& v2)
00073 {
00074 if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN)
00075 gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00076 gradient_structure::RETURN_PTR->v->x = x * v2.v->x;
00077 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation2,
00078 &(gradient_structure::RETURN_PTR->v->x),&(v2.v->x),x);
00079 return (*gradient_structure::RETURN_PTR);
00080 }
00085 prevariable& operator*(const prevariable& v1, double x)
00086 {
00087 if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN)
00088 gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00089 gradient_structure::RETURN_PTR->v->x = v1.v->x * x;
00090 gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation2,
00091 &(gradient_structure::RETURN_PTR->v->x),&(v1.v->x),x);
00092 return (*gradient_structure::RETURN_PTR);
00093 }
00098 void prevariable::operator/=(const prevariable& v1)
00099 {
00100 double tmp=1./(v1.v->x);
00101 v->x *= tmp;
00102 gradient_structure::GRAD_STACK1->set_gradient_stack(
00103 default_evaluation,&(v->x), &(v->x), tmp,&(v1.v->x), -(v->x)*tmp);
00104 }
00109 void prevariable::operator/=(double v1)
00110 {
00111 double tmp=1./v1;
00112 v->x *= tmp;
00113 gradient_structure::GRAD_STACK1->set_gradient_stack(
00114 default_evaluation,&(v->x), &(v->x), tmp);
00115 }
00120 void prevariable::operator*=(const prevariable& v1)
00121 {
00122 double* tmp=&((v1.v)->x);
00123 gradient_structure::GRAD_STACK1->set_gradient_stack(
00124 default_evaluation,&(v->x), &(v->x), *tmp, tmp, v->x);
00125 v->x *= *tmp;
00126 }
00131 void prevariable::operator*=(double v1)
00132 {
00133 gradient_structure::GRAD_STACK1->set_gradient_stack(
00134 default_evaluation,&(v->x), &(v->x), v1);
00135 v->x *= v1;
00136 }