CppAD: A C++ Algorithmic Differentiation Package  20130102
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-12 Bradley M. Bell
00007 
00008 CppAD is distributed under multiple licenses. This distribution is under
00009 the terms of the 
00010                     Eclipse 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 $icode%b% = Parameter(%x%)%$$
00031 $pre
00032 $$
00033 $icode%b% = Variable(%x%)%$$
00034 
00035 
00036 $head Purpose$$
00037 Determine if $icode x$$ is a 
00038 $cref/parameter/glossary/Parameter/$$ or 
00039 $cref/variable/glossary/Variable/$$. 
00040 
00041 $head x$$
00042 The argument $icode x$$ has prototype
00043 $codei%
00044      const AD<%Base%>    &%x%
00045      const VecAD<%Base%> &%x%
00046 %$$
00047 
00048 $head b$$
00049 The return value $icode b$$ has prototype
00050 $codei%
00051      bool %b%
00052 %$$
00053 The return value for $code Parameter$$ ($code Variable$$)
00054 is true if and only if $icode 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 $cref/AD of Base/glossary/AD of Base/$$ object.
00062 Thus it will not be recorded as part of an
00063 AD of $icode Base$$
00064 $cref/operation sequence/glossary/Operation/Sequence/$$.
00065 
00066 $head Example$$
00067 $children%
00068      example/par_var.cpp
00069 %$$
00070 The file
00071 $cref par_var.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_FRIEND_TEMPLATE_FUNCTION
00083      bool Parameter(const AD<Base> &x)
00084      {    if( x.tape_id_ == 0 )
00085                return true;
00086           size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
00087           return x.tape_id_ != *AD<Base>::tape_id_ptr(thread); 
00088      }
00089 
00090      template <class Base>
00091      CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
00092      bool Parameter(const VecAD<Base> &x)
00093      {    if( x.tape_id_ == 0 )
00094                return true;
00095           size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
00096           return x.tape_id_ != *AD<Base>::tape_id_ptr(thread); 
00097      }
00098 
00099      // Variable
00100      template <class Base>
00101      CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
00102      bool Variable(const AD<Base> &x)
00103      {    if( x.tape_id_ == 0 )
00104                return false;
00105           size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
00106           return x.tape_id_ == *AD<Base>::tape_id_ptr(thread); 
00107      }
00108 
00109      template <class Base>
00110      CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
00111      bool Variable(const VecAD<Base> &x)
00112      {    if( x.tape_id_ == 0 )
00113                return false;
00114           size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
00115           return x.tape_id_ == *AD<Base>::tape_id_ptr(thread); 
00116      }
00117 } 
00118 // END CppAD namespace
00119 
00120 
00121 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines