ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a18.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 cvdv_add(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 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   dvar_vector vtmp(v1.indexmin(),v1.indexmax());
00030   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00031   {
00032     vtmp.elem_value(i)=v1.elem(i)+v2.elem_value(i);
00033   }
00034 
00035   //dvar_vector vtmp=nograd_assign(tmp);
00036 
00037   // The derivative list considerations
00038   save_identifier_string("bbbb");
00039   v2.save_dvar_vector_position();
00040   vtmp.save_dvar_vector_position();
00041   save_identifier_string("aaaa");
00042   gradient_structure::GRAD_STACK1->
00043             set_gradient_stack(cvdv_add);
00044   return vtmp;
00045 }
00046 
00051 void cvdv_add(void)
00052 {
00053   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00054   verify_identifier_string("aaaa");
00055   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00056   dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);
00057   dvar_vector_position v2pos=restore_dvar_vector_position();
00058   verify_identifier_string("bbbb");
00059   dvector dfv2(dftmp.indexmin(),dftmp.indexmax());
00060   for (int i=dftmp.indexmin();i<=dftmp.indexmax();i++)
00061   {
00062     //vtmp.elem(i)=value(v1.elem(i))+value(v2.elem(i));
00063     dfv2(i)=dftmp.elem(i);
00064   }
00065   dfv2.save_dvector_derivatives(v2pos);
00066   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00067 }