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