CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ad_ctor.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_AD_CTOR_HPP
2 # define CPPAD_CORE_AD_CTOR_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 
18 $begin ad_ctor$$
19 $spell
20  cppad
21  ctor
22  initializes
23  Vec
24  const
25 $$
26 
27 
28 $section AD Constructors $$
29 $mindex convert Base VecAD$$
30 
31 $head Syntax$$
32 $codei%AD<%Base%> %y%()
33 %$$
34 $codei%AD<%Base%> %y%(%x%)
35 %$$
36 
37 $head Purpose$$
38 creates a new $codei%AD<%Base%>%$$ object $icode y$$
39 and initializes its value as equal to $icode x$$.
40 
41 $head x$$
42 
43 $subhead implicit$$
44 There is an implicit constructor where $icode x$$ has one of the following
45 prototypes:
46 $codei%
47  const %Base%& %x%
48  const VecAD<%Base%>& %x%
49 %$$
50 
51 $subhead explicit$$
52 There is an explicit constructor where $icode x$$ has prototype
53 $codei%
54  const %Type%& %x%
55 %$$
56 for any type that has an explicit constructor of the form
57 $icode%Base%(%x%)%$$.
58 
59 $head y$$
60 The target $icode y$$ has prototype
61 $codei%
62  AD<%Base%> %y%
63 %$$
64 
65 $head Example$$
66 $children%
67  example/general/ad_ctor.cpp
68 %$$
69 The files $cref ad_ctor.cpp$$ contain examples and tests of these operations.
70 It test returns true if it succeeds and false otherwise.
71 
72 $end
73 ------------------------------------------------------------------------------
74 */
75 
76 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
77 
78 /*!
79 \file ad_ctor.hpp
80 AD<Base> constructors and and copy operations.
81 */
82 
83 /*!
84 \page AD_default_ctor
85 Use default copy constructor
86 because they may be optimized better than the code below:
87 \code
88 template <class Base>
89 inline AD<Base>::AD(const AD &x)
90 {
91  value_ = x.value_;
92  tape_id_ = x.tape_id_;
93  taddr_ = x.taddr_;
94 
95  return;
96 }
97 \endcode
98 */
99 
100 /*!
101 Default Constructor.
102 
103 \tparam Base
104 Base type for this AD object.
105 */
106 template <class Base>
107 inline AD<Base>::AD(void)
108 : value_()
109 , tape_id_(0)
110 , taddr_(0)
111 { }
112 
113 // --------------------------------------------------------------------------
114 # ifdef CPPAD_FOR_TMB
115 /*!
116 Constructor from double.
117 
118 \param d
119 is value corresponding to this AD object.
120 The tape identifier will be an invalid tape identifier,
121 so this object is initially a parameter.
122 
123 \par CPPAD_FOR_TMB
124 This constructor is defined when CPPAD_FOR_TMB is defined.
125 */
126 template <class Base>
127 inline AD<Base>::AD(const double &d)
128 : value_( Base(d) )
129 , tape_id_(0)
130 , taddr_(0)
131 { // check that this is a parameter
133 }
134 // --------------------------------------------------------------------------
135 # else
136 // --------------------------------------------------------------------------
137 /*!
138 Constructor from Base type.
139 
140 \tparam Base
141 Base type for this AD object.
142 
143 \param b
144 is the Base type value corresponding to this AD object.
145 The tape identifier will be an invalid tape identifier,
146 so this object is initially a parameter.
147 
148 \par CPPAD_FOR_TMB
149 This constructor is defined when CPPAD_FOR_TMB is not defined.
150 */
151 template <class Base>
152 inline AD<Base>::AD(const Base &b)
153 : value_(b)
154 , tape_id_(0)
155 , taddr_(0)
156 { // check that this is a parameter
158 }
159 # endif
160 // --------------------------------------------------------------------------
161 
162 /*!
163 Constructor from an ADVec<Base> element drops the vector information.
164 
165 \tparam Base
166 Base type for this AD object.
167 */
168 template <class Base>
170 { *this = x.ADBase(); }
171 
172 /*!
173 Constructor from any other type, converts to Base type, and uses constructor
174 from Base type.
175 
176 \tparam Base
177 Base type for this AD object.
178 
179 \tparam T
180 is the the type that is being converted to AD<Base>.
181 There must be a constructor for Base from Type.
182 
183 \param t
184 is the object that is being converted from T to AD<Base>.
185 */
186 template <class Base>
187 template <class T>
188 inline AD<Base>::AD(const T &t)
189 : value_(Base(t))
190 , tape_id_(0)
191 , taddr_(0)
192 { }
193 
194 } // END_CPPAD_NAMESPACE
195 # endif
friend bool Parameter(const AD< Base > &u)
Definition: par_var.hpp:80
AD(void)
Default Constructor.
Definition: ad_ctor.hpp:107
AD< Base > ADBase(void) const
Conversion from VecAD_reference to AD&lt;Base&gt;. puts the correspond vecad load instruction in the tape...
Definition: vec_ad.hpp:392
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
Class used to hold a reference to an element of a VecAD object.
Definition: vec_ad.hpp:352