CppAD: A C++ Algorithmic Differentiation Package 20110419
par_var.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_PAR_VAR_INCLUDED
00003 # define CPPAD_PAR_VAR_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 $begin ParVar$$
00019 $spell
00020         VecAD
00021         const
00022         bool
00023 $$
00024 
00025 $index Parameter$$
00026 $index Variable$$
00027 $section Is an AD Object a Parameter or Variable$$
00028 
00029 $head Syntax$$
00030 $syntax%%b% = Parameter(%x%)%$$
00031 $pre
00032 $$
00033 $syntax%%b% = Variable(%x%)%$$
00034 
00035 
00036 $head Purpose$$
00037 Determine if $italic x$$ is a 
00038 $xref/glossary/Parameter/parameter/$$ or 
00039 $xref/glossary/Variable/variable/$$. 
00040 
00041 $head x$$
00042 The argument $italic x$$ has prototype
00043 $syntax%
00044         const AD<%Base%>    &%x%
00045         const VecAD<%Base%> &%x%
00046 %$$
00047 
00048 $head b$$
00049 The return value $italic b$$ has prototype
00050 $syntax%
00051         bool %b%
00052 %$$
00053 The return value for $code Parameter$$ ($code Variable$$)
00054 is true if and only if $italic x$$ is a parameter (variable).
00055 Note that a $cref/VecAD<Base>/VecAD/$$ object
00056 is a variable if any element of the vector depends on the independent
00057 variables.
00058 
00059 $head Operation Sequence$$
00060 The result of this operation is not an
00061 $xref/glossary/AD of Base/AD of Base/$$ object.
00062 Thus it will not be recorded as part of an
00063 AD of $italic Base$$
00064 $xref/glossary/Operation/Sequence/operation sequence/1/$$.
00065 
00066 $head Example$$
00067 $children%
00068         example/par_var.cpp
00069 %$$
00070 The file
00071 $xref/ParVar.cpp/$$
00072 contains an example and test of these functions.
00073 It returns true if it succeeds and false otherwise.
00074 
00075 $end
00076 -----------------------------------------------------------------------------
00077 */
00078 
00079 namespace CppAD {
00080         // Parameter
00081         template <class Base>
00082         CPPAD_INLINE bool Parameter(const AD<Base> &x)
00083         {       size_t thread = x.id_ % CPPAD_MAX_NUM_THREADS;
00084                 return x.id_ != * AD<Base>::id_handle(thread); 
00085         }
00086 
00087         template <class Base>
00088         CPPAD_INLINE bool Parameter(const VecAD<Base> &x)
00089         {       size_t thread = x.id_ % CPPAD_MAX_NUM_THREADS;
00090                 return x.id_ != * AD<Base>::id_handle(thread); 
00091         }
00092 
00093         // Variable
00094         template <class Base>
00095         CPPAD_INLINE bool Variable(const AD<Base> &x)
00096         {       size_t thread = x.id_ % CPPAD_MAX_NUM_THREADS;
00097                 return x.id_ == * AD<Base>::id_handle(thread); 
00098         }
00099 
00100         template <class Base>
00101         CPPAD_INLINE bool Variable(const VecAD<Base> &x)
00102         {       size_t thread = x.id_ % CPPAD_MAX_NUM_THREADS;
00103                 return x.id_ == * AD<Base>::id_handle(thread); 
00104         }
00105 } 
00106 // END CppAD namespace
00107 
00108 
00109 # endif