ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a45.cpp
Go to the documentation of this file.
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 dvdv_elem_prod(void);
00027 
00032 dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)
00033 {
00034   RETURN_ARRAYS_INCREMENT();
00035   if (v1.indexmin()!=v2.indexmin()||v1.indexmax()!=v2.indexmax())
00036   {
00037     cerr << "Incompatible bounds in "
00038     "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
00039     << endl;
00040     ad_exit(1);
00041   }
00042   dvar_vector tmp(v1.indexmin(),v1.indexmax());
00043 
00044   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00045   {
00046     tmp.elem_value(i)=v1.elem_value(i)*v2.elem_value(i);
00047   }
00048 
00049   // The derivative list considerations
00050   save_identifier_string("b");
00051   v1.save_dvar_vector_value();
00052   v1.save_dvar_vector_position();
00053   v2.save_dvar_vector_value();
00054   v2.save_dvar_vector_position();
00055   tmp.save_dvar_vector_position();
00056   save_identifier_string("a");
00057   gradient_structure::GRAD_STACK1->set_gradient_stack(dvdv_elem_prod);
00058   RETURN_ARRAYS_DECREMENT();
00059   return tmp;
00060 }
00061 
00066 void dvdv_elem_prod(void)
00067 {
00068   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00069   verify_identifier_string("a");
00070   dvar_vector_position tmppos=restore_dvar_vector_position();
00071   dvector dftmp=restore_dvar_vector_derivatives(tmppos);
00072   dvar_vector_position v2pos=restore_dvar_vector_position();
00073   dvector cv2=restore_dvar_vector_value(v2pos);
00074   dvar_vector_position v1pos=restore_dvar_vector_position();
00075   dvector cv1=restore_dvar_vector_value(v1pos);
00076   verify_identifier_string("b");
00077   dvector dfv1(cv1.indexmin(),cv1.indexmax());
00078   dvector dfv2(cv2.indexmin(),cv2.indexmax());
00079   for (int i=cv1.indexmin();i<=cv1.indexmax();i++)
00080   {
00081     //tmp+=cv1(i)*cv2(i);
00082     dfv1(i)=dftmp.elem(i)*cv2.elem(i);
00083     dfv2(i)=dftmp.elem(i)*cv1.elem(i);
00084   }
00085   dfv1.save_dvector_derivatives(v1pos);
00086   dfv2.save_dvector_derivatives(v2pos);
00087   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00088 }
00089 
00090 void cvdv_elem_prod(void);
00091 
00096 dvar_vector elem_prod(const dvector& v1, const dvar_vector& v2)
00097 {
00098   RETURN_ARRAYS_INCREMENT();
00099   if (v1.indexmin()!=v2.indexmin()||v1.indexmax()!=v2.indexmax())
00100   {
00101     cerr << "Incompatible bounds in "
00102     "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
00103     << endl;
00104     ad_exit(1);
00105   }
00106   dvar_vector tmp(v1.indexmin(),v1.indexmax());
00107 
00108   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00109   {
00110     tmp.elem_value(i)=v1.elem(i)*v2.elem_value(i);
00111   }
00112 
00113   // The derivative list considerations
00114   save_identifier_string("b");
00115   v1.save_dvector_value();
00116   v1.save_dvector_position();
00117   v2.save_dvar_vector_position();
00118   tmp.save_dvar_vector_position();
00119   save_identifier_string("a");
00120   gradient_structure::GRAD_STACK1->set_gradient_stack(cvdv_elem_prod);
00121   RETURN_ARRAYS_DECREMENT();
00122   return tmp;
00123 }
00124 
00129 void cvdv_elem_prod(void)
00130 {
00131   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00132   verify_identifier_string("a");
00133   dvar_vector_position tmppos=restore_dvar_vector_position();
00134   dvector dftmp=restore_dvar_vector_derivatives(tmppos);
00135   dvar_vector_position v2pos=restore_dvar_vector_position();
00136   dvector_position v1pos=restore_dvector_position();
00137   dvector cv1=restore_dvector_value(v1pos);
00138   verify_identifier_string("b");
00139   dvector dfv2(cv1.indexmin(),cv1.indexmax());
00140   for (int i=cv1.indexmin();i<=cv1.indexmax();i++)
00141   {
00142     //tmp+=cv1(i)*cv2(i);
00143     dfv2(i)=dftmp.elem(i)*cv1.elem(i);
00144   }
00145   dfv2.save_dvector_derivatives(v2pos);
00146   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00147 }
00148 
00149 void dvcv_elem_prod(void);
00150 
00155 dvar_vector elem_prod(const dvar_vector& v1, const dvector& v2)
00156 {
00157   RETURN_ARRAYS_INCREMENT();
00158   if (v1.indexmin()!=v2.indexmin()||v1.indexmax()!=v2.indexmax())
00159   {
00160     cerr << "Incompatible bounds in "
00161     "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
00162     << endl;
00163     ad_exit(1);
00164   }
00165   dvar_vector tmp(v1.indexmin(),v1.indexmax());
00166 
00167   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00168   {
00169     tmp.elem_value(i)=v1.elem_value(i)*v2.elem(i);
00170   }
00171 
00172   // The derivative list considerations
00173   save_identifier_string("b");
00174   v1.save_dvar_vector_position();
00175   v2.save_dvector_value();
00176   v2.save_dvector_position();
00177   tmp.save_dvar_vector_position();
00178   save_identifier_string("a");
00179   gradient_structure::GRAD_STACK1->set_gradient_stack(dvcv_elem_prod);
00180   RETURN_ARRAYS_DECREMENT();
00181   return tmp;
00182 }
00183 
00188 void dvcv_elem_prod(void)
00189 {
00190   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00191   verify_identifier_string("a");
00192   dvar_vector_position tmppos=restore_dvar_vector_position();
00193   dvector dftmp=restore_dvar_vector_derivatives(tmppos);
00194   dvector_position v2pos=restore_dvector_position();
00195   dvector cv2=restore_dvector_value(v2pos);
00196   dvar_vector_position v1pos=restore_dvar_vector_position();
00197   verify_identifier_string("b");
00198   dvector dfv1(cv2.indexmin(),cv2.indexmax());
00199   for (int i=cv2.indexmin();i<=cv2.indexmax();i++)
00200   {
00201     //tmp+=cv1(i)*cv2(i);
00202     dfv1(i)=dftmp.elem(i)*cv2.elem(i);
00203   }
00204   dfv1.save_dvector_derivatives(v1pos);
00205   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00206 }