ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a22.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 dvdv_sub(void);
00013 
00018 dvar_vector operator-(const dvar_vector& v1, const dvar_vector& 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 dvar_vector& v2)"
00024     << endl;
00025     ad_exit(1);
00026   }
00027   //dvector cv1=value(v1);
00028   //dvector cv2=value(v2);
00029   kkludge_object kkk;
00030   dvar_vector vtmp(v1.indexmin(),v1.indexmax(),kkk);
00031   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00032   {
00033     vtmp.elem_value(i)=v1.elem_value(i)-v2.elem_value(i);
00034   }
00035 
00036   //dvar_vector vtmp=nograd_assign(tmp);
00037 
00038   // The derivative list considerations
00039   save_identifier_string("bbbb");
00040   v1.save_dvar_vector_position();
00041   v2.save_dvar_vector_position();
00042   vtmp.save_dvar_vector_position();
00043   save_identifier_string("aaaa");
00044   gradient_structure::GRAD_STACK1->
00045             set_gradient_stack(dvdv_sub);
00046   return vtmp;
00047 }
00048 
00053 void dvdv_sub(void)
00054 {
00055   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00056   verify_identifier_string("aaaa");
00057   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00058   dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);
00059   dvar_vector_position v2pos=restore_dvar_vector_position();
00060   dvar_vector_position v1pos=restore_dvar_vector_position();
00061   verify_identifier_string("bbbb");
00062   dvector dfv1(dftmp.indexmin(),dftmp.indexmax());
00063   dvector dfv2(dftmp.indexmin(),dftmp.indexmax());
00064   for (int i=dftmp.indexmin();i<=dftmp.indexmax();i++)
00065   {
00066     //vtmp.elem(i)=value(v1.elem(i))+value(v2.elem(i));
00067     dfv1.elem(i)=dftmp.elem(i);
00068     dfv2.elem(i)=-dftmp.elem(i);
00069   }
00070   dfv1.save_dvector_derivatives(v1pos);
00071   dfv2.save_dvector_derivatives(v2pos);
00072   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00073 }