CppAD: A C++ Algorithmic Differentiation Package 20110419
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_VAR2PAR_INCLUDED 00003 # define CPPAD_VAR2PAR_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-08 Bradley M. Bell 00007 00008 CppAD is distributed under multiple licenses. This distribution is under 00009 the terms of the 00010 Common Public License Version 1.0. 00011 00012 A copy of this license is included in the COPYING file of this distribution. 00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00014 -------------------------------------------------------------------------- */ 00015 00016 /* 00017 ------------------------------------------------------------------------------ 00018 00019 $begin Var2Par$$ 00020 $spell 00021 var 00022 const 00023 $$ 00024 00025 $index Var2Par$$ 00026 $index variable, convert to parameter$$ 00027 $index parameter, convert from variable$$ 00028 $index value_, obtain during taping$$ 00029 00030 $section Convert an AD Variable to a Parameter$$ 00031 00032 $head Syntax$$ 00033 $syntax%%y% = Var2Par(%x%)%$$ 00034 00035 00036 $head Purpose$$ 00037 Returns a 00038 $cref/parameter/glossary/Parameter/$$ $italic y$$ 00039 with the same value as the 00040 $cref/variable/glossary/Variable/$$ $italic x$$. 00041 00042 $head x$$ 00043 The argument $italic x$$ has prototype 00044 $syntax% 00045 const AD<%Base%> &x 00046 %$$ 00047 The argument $italic x$$ may be a variable or parameter. 00048 00049 00050 $head y$$ 00051 The result $italic y$$ has prototype 00052 $syntax% 00053 AD<%Base%> &y 00054 %$$ 00055 The return value $italic y$$ will be a parameter. 00056 00057 00058 $head Example$$ 00059 $children% 00060 example/var_2par.cpp 00061 %$$ 00062 The file 00063 $xref/Var2Par.cpp/$$ 00064 contains an example and test of this operation. 00065 It returns true if it succeeds and false otherwise. 00066 00067 $end 00068 ------------------------------------------------------------------------------ 00069 */ 00070 00071 // BEGIN CppAD namespace 00072 namespace CppAD { 00073 00074 template <class Base> 00075 CPPAD_INLINE AD<Base> Var2Par(const AD<Base> &x) 00076 { AD<Base> y(x.value_); 00077 return y; 00078 } 00079 00080 00081 template <class Base> 00082 CPPAD_INLINE AD<Base> Var2Par(const VecAD_reference<Base> &x) 00083 { AD<Base> y(x.ADBase()); 00084 y.id_ = 0; 00085 } 00086 00087 00088 } // END CppAD namespace 00089 00090 # endif