ADMB Documentation  11.2.2828
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a16.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_a16.cpp 1919 2014-04-22 22:02:01Z 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 
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 void dvcv_dot(void);
00026 
00031 dvariable operator*(const dvar_vector& v2, const dvector& cv1)
00032 {
00033   if (cv1.indexmin()!=v2.indexmin()||cv1.indexmax()!=v2.indexmax())
00034   {
00035     cerr << "Incompatible bounds in "
00036     "prevariable operator*(const dvar_vector& v1, const dvar_vector& v2)"
00037     << endl;
00038     ad_exit(1);
00039   }
00040   //dvector cv1;
00041   //dvector cv2=value(v2);
00042   double tmp=0;
00043 
00044 #ifdef OPT_LIB
00045     int mmin=cv1.indexmin();
00046     int mmax=cv1.indexmax();
00047     const double * pt1=&cv1.elem(mmin);
00048     const double * pt1m=&cv1.elem(mmax);
00049     const double * pt2=&v2.elem_value(mmin);
00050     do
00051     {
00052       tmp+= *pt1++ * *pt2++;
00053     }
00054     while (pt1<=pt1m);
00055 #else
00056   #ifndef USE_ASSEMBLER
00057     int mmin=cv1.indexmin();
00058     int mmax=cv1.indexmax();
00059     for (int i=mmin;i<=mmax;i++)
00060     {
00061       tmp+=cv1.elem(i)*v2.elem_value(i);
00062     }
00063   #else
00064     int min=cv1.indexmin();
00065     int n=cv1.indexmax()-min+1;
00066     dp_dotproduct(&tmp,&(cv1.elem(min)),&(v2.elem_value(min)),n);
00067   #endif
00068 #endif
00069 
00070   dvariable vtmp=nograd_assign(tmp);
00071 
00072   // The derivative list considerations
00073   save_identifier_string("yyyy");
00074   cv1.save_dvector_value();
00075   cv1.save_dvector_position();
00076   v2.save_dvar_vector_position();
00077   vtmp.save_prevariable_position();
00078   save_identifier_string("uuuu");
00079   gradient_structure::GRAD_STACK1->
00080             set_gradient_stack(dvcv_dot);
00081   return vtmp;
00082 }
00083 
00088 void dvcv_dot(void)
00089 {
00090   verify_identifier_string("uuuu");
00091   double dftmp=restore_prevariable_derivative();
00092   dvar_vector_position v2pos=restore_dvar_vector_position();
00093   dvector_position dpos=restore_dvector_position();
00094   dvector cv1=restore_dvector_value(dpos);
00095   verify_identifier_string("yyyy");
00096 
00097   dvector dfv2(cv1.indexmin(),cv1.indexmax());
00098 
00099 #ifdef OPT_LIB
00100   double * pc1=&cv1.elem(cv1.indexmin());
00101   double * pc1m=&cv1(cv1.indexmax());
00102   double * pdf=&dfv2.elem(cv1.indexmin());
00103   do
00104   {
00105     *pdf++=dftmp* *pc1++;
00106   }
00107   while (pc1 <=pc1m);
00108 #else
00109   for (int i=cv1.indexmin();i<=cv1.indexmax();i++)
00110   {
00111     //tmp+=cv1(i)*cv2(i);
00112     dfv2.elem(i)=dftmp*cv1.elem(i);
00113   }
00114 #endif
00115   dfv2.save_dvector_derivatives(v2pos);
00116 }