00001 /* 00002 * $Id$ 00003 * 00004 * Author: David Fournier 00005 * Copyright (c) 2008-2012 Regents of the University of California 00006 */ 00011 // file fvar.cpp 00012 // constructors, destructors and misc functions involving class prevariable 00013 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 void cvdv_dot(void); 00027 00032 dvariable operator*(const dvector& cv1, const dvar_vector& v2) 00033 { 00034 if (cv1.indexmin()!=v2.indexmin()||cv1.indexmax()!=v2.indexmax()) 00035 { 00036 cerr << "Incompatible bounds in " 00037 "prevariable operator * (const dvar_vector& v1, const dvar_vector& v2)" 00038 << endl; 00039 ad_exit(1); 00040 } 00041 double tmp=0; 00042 int mmin=cv1.indexmin(); 00043 int mmax=cv1.indexmax(); 00044 #ifdef OPT_LIB 00045 const double * pt1=&cv1.elem(mmin); 00046 const double * pt1m=&cv1.elem(mmax); 00047 const double * pt2=&v2.elem_value(mmin); 00048 do 00049 { 00050 tmp+= *pt1++ * *pt2++; 00051 } 00052 while (pt1<=pt1m); 00053 #else 00054 #ifndef USE_ASSEMBLER 00055 for (int i=mmin;i<=mmax;i++) 00056 { 00057 tmp+=cv1.elem(i)*v2.elem_value(i); 00058 } 00059 #else 00060 int min=cv1.indexmin(); 00061 int n=cv1.indexmax()-min+1; 00062 dp_dotproduct(&tmp,&(cv1.elem(min)),&(v2.elem_value(min)),n); 00063 #endif 00064 #endif 00065 dvariable vtmp=nograd_assign(tmp); 00066 00067 // The derivative list considerations 00068 save_identifier_string("bbbb"); 00069 cv1.save_dvector_value(); 00070 cv1.save_dvector_position(); 00071 v2.save_dvar_vector_position(); 00072 vtmp.save_prevariable_position(); 00073 save_identifier_string("aaaa"); 00074 gradient_structure::GRAD_STACK1-> 00075 set_gradient_stack(cvdv_dot); 00076 return vtmp; 00077 } 00078 00083 void cvdv_dot(void) 00084 { 00085 verify_identifier_string("aaaa"); 00086 double dftmp=restore_prevariable_derivative(); 00087 dvar_vector_position v2pos=restore_dvar_vector_position(); 00088 dvector_position dpos=restore_dvector_position(); 00089 dvector cv1=restore_dvector_value(dpos); 00090 dvector dfv2(cv1.indexmin(),cv1.indexmax()); 00091 verify_identifier_string("bbbb"); 00092 #ifdef OPT_LIB 00093 double * pc1=&cv1.elem(cv1.indexmin()); 00094 double * pc1m=&cv1(cv1.indexmax()); 00095 double * pdf=&dfv2.elem(cv1.indexmin()); 00096 do 00097 { 00098 *pdf++=dftmp* *pc1++; 00099 } 00100 while (pc1 <=pc1m); 00101 #else 00102 for (int i=cv1.indexmin();i<=cv1.indexmax();i++) 00103 { 00104 //tmp+=cv1(i)*cv2(i); 00105 //dfv1(i)=dftmp*cv2(i); 00106 dfv2.elem(i)=dftmp*cv1.elem(i); 00107 } 00108 #endif 00109 //dfv1.save_dvector_derivatives(v1pos); 00110 dfv2.save_dvector_derivatives(v2pos); 00111 }
Generated on Tue Mar 8 2016 19:51:33 for ADMB Documentation by 1.8.0 |