/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/ad_copy.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_AD_COPY_INCLUDED
00002 # define CPPAD_AD_COPY_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 
00015 /*
00016 ------------------------------------------------------------------------------
00017 
00018 $begin ad_copy$$
00019 $spell
00020         Vec
00021         const
00022 $$
00023 
00024 $index AD, copy$$
00025 $index AD, assignment$$
00026 
00027 $index constructor, AD$$
00028 $index assignment, AD$$
00029 
00030 $index convert, to AD$$
00031 $index Base, convert to AD$$
00032 $index double, convert to AD$$
00033 $index VecAD, convert to AD$$
00034 
00035 $section AD Copy Constructor and Assignment Operator$$
00036 
00037 $head Syntax$$
00038 
00039 $subhead Constructor$$
00040 $syntax%AD<%Base%> %y%(%x%)
00041 %$$
00042 $syntax%AD<%Base%> %y% = %x%$$
00043 
00044 $subhead Assignment$$
00045 $syntax%%y% = %x%$$
00046 
00047 $head Purpose$$
00048 The constructor creates a new $syntax%AD<%Base%>%$$ object $italic y$$ 
00049 and the assignment operator uses an existing $italic y$$.
00050 In either case, 
00051 $italic y$$ has the same value as $italic x$$,
00052 and the same dependence on the 
00053 $cref/independent variables/glossary/Tape/Independent Variable/$$
00054 ($italic y$$ is a 
00055 $xref/glossary/Variable/variable/$$ if and only if $italic x$$ is a variable).
00056 
00057 $head x$$
00058 The argument $italic x$$ has prototype
00059 $syntax%
00060         const %Type% &%x%
00061 %$$ 
00062 where $italic Type$$ is
00063 $syntax%VecAD<%Base%>::reference%$$,
00064 $syntax%AD<%Base%>%$$,
00065 $italic Base$$, or
00066 $code double$$.
00067 
00068 $head y$$
00069 The target $italic y$$ has prototype
00070 $syntax%
00071         AD<%Base%> &%y%
00072 %$$
00073 
00074 $head Example$$
00075 $children%
00076         example/copy_ad.cpp%
00077         example/copy_base.cpp%
00078         example/eq.cpp
00079         
00080 %$$
00081 The following files contain examples and tests of these operations.
00082 Each test returns true if it succeeds and false otherwise.
00083 $table
00084 $rref CopyAD.cpp$$
00085 $rref CopyBase.cpp$$
00086 $rref Eq.cpp$$
00087 $tend
00088 
00089 $end
00090 ------------------------------------------------------------------------------
00091 */
00092 
00093 //  BEGIN CppAD namespace
00094 namespace CppAD {
00095 
00096 # if 0
00097 // use default copy constructor and assignment operator
00098 // because they may be optimized better by the compiler
00099 template <class Base>
00100 inline AD<Base>::AD(const AD &x) 
00101 {
00102         value_   = x.value_;
00103         id_     = x.id_;
00104         taddr_  = x.taddr_;
00105 
00106         return;
00107 }
00108 template <class Base>
00109 inline AD<Base>& AD<Base>::operator=(const AD<Base> &right)
00110 {       value_   = right.value_;
00111         id_     = right.id_;
00112         taddr_  = right.taddr_;
00113 
00114         // check that all variables are parameters while tape is empty
00115         CPPAD_ASSERT_UNKNOWN(
00116                 Parameter(*this) || (tape_this() != CPPAD_NULL)
00117         );
00118 
00119         return *this;
00120 }
00121 # endif
00122 
00123 // constructor and assignment from Base type
00124 // (if id_ is 1, taddr_ is not used, set anyway to avoid compile warning)
00125 template <class Base>
00126 inline AD<Base>::AD(const Base &b) : value_(b), id_(1), taddr_(0)
00127 { }     
00128 template <class Base>
00129 inline AD<Base>& AD<Base>::operator=(const Base &b)
00130 {       value_ = b;
00131         id_    = 1;
00132 
00133         // check that this is a parameter
00134         CPPAD_ASSERT_UNKNOWN( Parameter(*this) );
00135 
00136         return *this;
00137 }
00138 
00139 // constructor and assignment from VecAD_reference<Base>
00140 template <class Base>
00141 inline AD<Base>::AD(const VecAD_reference<Base> &x)
00142 {       *this = x.ADBase(); }
00143 template <class Base>
00144 inline AD<Base>& AD<Base>::operator=(const VecAD_reference<Base> &x)
00145 {       return *this = x.ADBase(); }
00146 
00147 // constructor and assignment from any other type 
00148 // (if id_ is 1, taddr_ is not used, set anyway to avoid compile warning)
00149 template <class Base>
00150 template <class T>
00151 inline AD<Base>::AD(const T &t) : value_(Base(t)), id_(1), taddr_(0)
00152 { }
00153 template <class Base>
00154 template <class T>
00155 inline AD<Base>& AD<Base>::operator=(const T &t)
00156 {       return *this = Base(t); }
00157 
00158 
00159 } // END CppAD namespace
00160 
00161 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7