ADMB Documentation  11.1.2542
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a21.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_a21.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 #include "fvar.hpp"
00012 void cvdv_sub(void);
00013 
00018 dvar_vector operator-(const dvector& 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 dvector& v1, const dvar_vector& 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(i)-v2.elem_value(i);
00032   }
00033 
00034   //dvar_vector vtmp=nograd_assign(tmp);
00035 
00036   // The derivative list considerations
00037   save_identifier_string("bbbb");
00038   v2.save_dvar_vector_position();
00039   vtmp.save_dvar_vector_position();
00040   save_identifier_string("aaaa");
00041   gradient_structure::GRAD_STACK1->
00042             set_gradient_stack(cvdv_sub);
00043   return vtmp;
00044 }
00045 
00050 void cvdv_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 v2pos=restore_dvar_vector_position();
00057   verify_identifier_string("bbbb");
00058   dvector dfv2(dftmp.indexmin(),dftmp.indexmax());
00059   for (int i=dftmp.indexmin();i<=dftmp.indexmax();i++)
00060   {
00061     //vtmp.elem(i)=v1.elem(i)-value(v2.elem(i));
00062     dfv2(i)=-dftmp.elem(i);
00063   }
00064   dfv2.save_dvector_derivatives(v2pos);
00065   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00066 }