CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_AD_CTOR_INCLUDED 00003 # define CPPAD_AD_CTOR_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 00019 $begin ad_ctor$$ 00020 $spell 00021 initializes 00022 Vec 00023 const 00024 $$ 00025 00026 $index AD, constructor$$ 00027 $index constructor, AD$$ 00028 $index convert, to AD$$ 00029 $index Base, convert to AD$$ 00030 $index VecAD, convert to AD$$ 00031 00032 $section AD Constructors $$ 00033 00034 $head Syntax$$ 00035 $codei%AD<%Base%> %y%() 00036 %$$ 00037 $codei%AD<%Base%> %y%(%x%) 00038 %$$ 00039 $codei%AD<%Base%> %y% = %x%$$ 00040 00041 $head Purpose$$ 00042 creates a new $codei%AD<%Base%>%$$ object $icode y$$ 00043 and initializes its value as equal to $icode x$$. 00044 00045 $head x$$ 00046 The argument $icode x$$ has prototype 00047 $codei% 00048 const %Type% &%x% 00049 %$$ 00050 where $icode Type$$ is 00051 $codei%VecAD<%Base%>::reference%$$, 00052 $codei%AD<%Base%>%$$, 00053 $icode Base$$, 00054 or any type that has a constructor of the form 00055 $icode%Base%(%x%)%$$. 00056 00057 $head y$$ 00058 The target $icode y$$ has prototype 00059 $codei% 00060 AD<%Base%> %y% 00061 %$$ 00062 00063 $head Example$$ 00064 $children% 00065 example/ad_ctor.cpp 00066 %$$ 00067 The files $cref ad_ctor.cpp$$ contain examples and tests of these operations. 00068 It test returns true if it succeeds and false otherwise. 00069 00070 $end 00071 ------------------------------------------------------------------------------ 00072 */ 00073 00074 CPPAD_BEGIN_NAMESPACE 00075 00076 /*! 00077 \defgroup ad_ctor_hpp ad_ctor.hpp 00078 \{ 00079 \file ad_ctor.hpp 00080 AD<Base> constructors and and copy operations. 00081 */ 00082 00083 /*! 00084 \page AD_default_ctor 00085 Use default copy constructor 00086 because they may be optimized better than the code below: 00087 \code 00088 template <class Base> 00089 inline AD<Base>::AD(const AD &x) 00090 { 00091 value_ = x.value_; 00092 tape_id_ = x.tape_id_; 00093 taddr_ = x.taddr_; 00094 00095 return; 00096 } 00097 \endcode 00098 */ 00099 00100 /*! 00101 Default Constructor. 00102 00103 \tparam Base 00104 Base type for this AD object. 00105 */ 00106 template <class Base> 00107 inline AD<Base>::AD(void) 00108 : value_() 00109 , tape_id_(0) 00110 , taddr_(0) 00111 { } 00112 00113 00114 /*! 00115 Constructor from Base type. 00116 00117 \tparam Base 00118 Base type for this AD object. 00119 00120 \param b 00121 is the Base type value corresponding to this AD object. 00122 The tape identifier will be an invalid tape identifier, 00123 so this object is initially a parameter. 00124 */ 00125 template <class Base> 00126 inline AD<Base>::AD(const Base &b) 00127 : value_(b) 00128 , tape_id_(0) 00129 , taddr_(0) 00130 { // check that this is a parameter 00131 CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); 00132 } 00133 00134 /*! 00135 Constructor from an ADVec<Base> element drops the vector information. 00136 00137 \tparam Base 00138 Base type for this AD object. 00139 */ 00140 template <class Base> 00141 inline AD<Base>::AD(const VecAD_reference<Base> &x) 00142 { *this = x.ADBase(); } 00143 00144 /*! 00145 Constructor from any other type, converts to Base type, and uses constructor 00146 from Base type. 00147 00148 \tparam Base 00149 Base type for this AD object. 00150 00151 \tparam T 00152 is the the type that is being converted to AD<Base>. 00153 There must be a constructor for Base from Type. 00154 00155 \param t 00156 is the object that is being converted from T to AD<Base>. 00157 */ 00158 template <class Base> 00159 template <class T> 00160 inline AD<Base>::AD(const T &t) 00161 : value_(Base(t)) 00162 , tape_id_(0) 00163 , taddr_(0) 00164 { } 00165 00166 /*! \} */ 00167 CPPAD_END_NAMESPACE 00168 # endif