CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
par_var.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_PAR_VAR_HPP
2 # define CPPAD_CORE_PAR_VAR_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 /*
15 ---------------------------------------------------------------------------
16 
17 $begin ParVar$$
18 $spell
19  VecAD
20  const
21  bool
22 $$
23 
24 $section Is an AD Object a Parameter or Variable$$
25 
26 $head Syntax$$
27 $icode%b% = Parameter(%x%)%$$
28 $pre
29 $$
30 $icode%b% = Variable(%x%)%$$
31 
32 
33 $head Purpose$$
34 Determine if $icode x$$ is a
35 $cref/parameter/glossary/Parameter/$$ or
36 $cref/variable/glossary/Variable/$$.
37 
38 $head x$$
39 The argument $icode x$$ has prototype
40 $codei%
41  const AD<%Base%> &%x%
42  const VecAD<%Base%> &%x%
43 %$$
44 
45 $head b$$
46 The return value $icode b$$ has prototype
47 $codei%
48  bool %b%
49 %$$
50 The return value for $code Parameter$$ ($code Variable$$)
51 is true if and only if $icode x$$ is a parameter (variable).
52 Note that a $cref/VecAD<Base>/VecAD/$$ object
53 is a variable if any element of the vector depends on the independent
54 variables.
55 
56 $head Operation Sequence$$
57 The result of this operation is not an
58 $cref/AD of Base/glossary/AD of Base/$$ object.
59 Thus it will not be recorded as part of an
60 AD of $icode Base$$
61 $cref/operation sequence/glossary/Operation/Sequence/$$.
62 
63 $head Example$$
64 $children%
65  example/general/par_var.cpp
66 %$$
67 The file
68 $cref par_var.cpp$$
69 contains an example and test of these functions.
70 It returns true if it succeeds and false otherwise.
71 
72 $end
73 -----------------------------------------------------------------------------
74 */
75 
76 namespace CppAD {
77  // Parameter
78  template <class Base>
80  bool Parameter(const AD<Base> &x)
81  { if( x.tape_id_ == 0 )
82  return true;
83  size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
84  return x.tape_id_ != *AD<Base>::tape_id_ptr(thread);
85  }
86 
87  template <class Base>
89  bool Parameter(const VecAD<Base> &x)
90  { if( x.tape_id_ == 0 )
91  return true;
92  size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
93  return x.tape_id_ != *AD<Base>::tape_id_ptr(thread);
94  }
95 
96  // Variable
97  template <class Base>
99  bool Variable(const AD<Base> &x)
100  { if( x.tape_id_ == 0 )
101  return false;
102  size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
103  return x.tape_id_ == *AD<Base>::tape_id_ptr(thread);
104  }
105 
106  template <class Base>
108  bool Variable(const VecAD<Base> &x)
109  { if( x.tape_id_ == 0 )
110  return false;
111  size_t thread = size_t(x.tape_id_ % CPPAD_MAX_NUM_THREADS);
112  return x.tape_id_ == *AD<Base>::tape_id_ptr(thread);
113  }
114 }
115 // END CppAD namespace
116 
117 
118 # endif
static tape_id_t * tape_id_ptr(size_t thread)
Pointer to the tape identifier for this AD&lt;Base&gt; class and the specific thread.
Definition: tape_link.hpp:81
Definition: ad.hpp:34
#define CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
A version of the inline command that works with MC compiler.
Definition: define.hpp:43
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION bool Variable(const AD< Base > &x)
Definition: par_var.hpp:99
tape_id_t tape_id_
tape id corresponding to the offset
Definition: vec_ad.hpp:481
tape_id_t tape_id_
Definition: ad.hpp:41
Vector of AD objects that tracks indexing operations on the tape.
Definition: vec_ad.hpp:462
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION bool Parameter(const AD< Base > &x)
Definition: par_var.hpp:80