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