ADMB Documentation  11.1.2270
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_op7.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_op7.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 
00017 double upick(double x)
00018 {
00019   return x*x;
00020 }
00021 
00026 dvariable& square(const prevariable& v1)
00027 {
00028   double& x=value(v1);
00029   if (++gradient_structure::RETURN_PTR > gradient_structure::MAX_RETURN)
00030     gradient_structure::RETURN_PTR = gradient_structure::MIN_RETURN;
00031   gradient_structure::RETURN_PTR->v->x=x*x;
00032    gradient_structure::GRAD_STACK1->set_gradient_stack(default_evaluation2,
00033      &(gradient_structure::RETURN_PTR->v->x), &(v1.v->x),2*x );
00034    return(*gradient_structure::RETURN_PTR);
00035  }
00036 
00041 dvar_matrix square(const dvar_matrix& m)
00042    {
00043      dvar_matrix tmp;
00044      tmp.allocate(m);
00045      for (int i=tmp.rowmin();i<=tmp.rowmax();i++)
00046      {
00047        tmp(i)=square(m(i));
00048      }
00049      return tmp;
00050    }