ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a23.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 #include "fvar.hpp"
00012 void dvcv_sub(void);
00013 
00018 dvar_vector operator-(const dvar_vector& v1, const dvector& v2)
00019 {
00020   if (v1.indexmin()!=v2.indexmin()||v1.indexmax()!=v2.indexmax())
00021   {
00022     cerr << "Incompatible bounds in "
00023       "prevariable operator-(const dvar_vector& v1, const dvector& v2)" << endl;
00024     ad_exit(1);
00025   }
00026   //dvector cv1=value(v1);
00027   //dvector cv2=value(v2);
00028   dvar_vector vtmp(v1.indexmin(),v1.indexmax());
00029   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00030   {
00031     vtmp.elem_value(i)=v1.elem_value(i)-v2.elem(i);
00032   }
00033 
00034   //dvar_vector vtmp=nograd_assign(tmp);
00035 
00036   // The derivative list considerations
00037   save_identifier_string("bbbb");
00038   v1.save_dvar_vector_position();
00039   vtmp.save_dvar_vector_position();
00040   save_identifier_string("aaaa");
00041   gradient_structure::GRAD_STACK1->
00042             set_gradient_stack(dvcv_sub);
00043   return vtmp;
00044 }
00045 
00050 void dvcv_sub(void)
00051 {
00052   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00053   verify_identifier_string("aaaa");
00054   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00055   dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);
00056   dvar_vector_position v1pos=restore_dvar_vector_position();
00057   verify_identifier_string("bbbb");
00058   dvector dfv1(dftmp.indexmin(),dftmp.indexmax());
00059   for (int i=dftmp.indexmin();i<=dftmp.indexmax();i++)
00060   {
00061     //vtmp.elem(i)=value(v1.elem(i))+v2.elem(i);
00062     dfv1.elem(i)=dftmp.elem(i);
00063   }
00064   dfv1.save_dvector_derivatives(v1pos);
00065   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00066 }