ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a32.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 
00013 #ifndef OPT_LIB
00014   #include <cassert>
00015   #include <climits>
00016 #endif
00017 
00018 void dv_subassign(void);
00019 
00024 dvar_vector dvar_vector::operator()(const ivector& u)
00025  {
00026    dvar_vector tmp(u.indexmin(),u.indexmax());
00027 
00028    for (int i=u.indexmin();i<=u.indexmax();i++)
00029    {
00030      tmp.elem_value(i)=elem_value(u(i));
00031    }
00032    save_identifier_string("by");
00033    save_dvar_vector_position();
00034    tmp.save_dvar_vector_position();
00035    u.save_ivector_value();
00036    u.save_ivector_position();
00037    save_identifier_string("ay");
00038    gradient_structure::GRAD_STACK1->
00039      set_gradient_stack(dv_subassign);
00040    return tmp;
00041  }
00042 
00047 void dv_subassign(void)
00048 {
00049   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00050   verify_identifier_string("ay");
00051   ivector_position u_pos=restore_ivector_position();
00052   ivector u=restore_ivector_value(u_pos);
00053   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00054   dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);
00055   dvar_vector_position t_pos=restore_dvar_vector_position();
00056   dvector dft(t_pos.indexmin(),t_pos.indexmax());
00057   verify_identifier_string("by");
00058   dft.initialize();
00059   int mmin=dftmp.indexmin();
00060   int mmax=dftmp.indexmax();
00061   for (int i=mmin;i<=mmax;i++)
00062   {
00063      //tmp.elem_value(i)=this->elem_value(u(i));
00064      dft.elem(u(i))+=dftmp.elem(i);
00065   }
00066   dft.save_dvector_derivatives(t_pos);
00067 }
00068 
00073 dvar_vector dvar_vector::operator()(const lvector& u)
00074  {
00075    dvar_vector tmp(u.indexmin(),u.indexmax());
00076    for ( int i=u.indexmin(); i<=u.indexmax(); i++)
00077    {
00078 #ifdef OPT_LIB
00079      tmp(i)=(*this)((int)u(i));
00080 #else
00081      const long ui = u(i);
00082      assert(ui <= INT_MAX);
00083      tmp(i)=(*this)((int)ui);
00084 #endif
00085    }
00086    return tmp;
00087  }