00001 # ifndef CPPAD_PRINT_FOR_INCLUDED 00002 # define CPPAD_PRINT_FOR_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 $begin PrintFor$$ 00017 $spell 00018 VecAD 00019 std 00020 cout 00021 const 00022 $$ 00023 00024 $index print, forward mode$$ 00025 $index forward, mode print$$ 00026 00027 $section Printing AD Values During Forward Mode$$ 00028 00029 $head Syntax$$ 00030 $syntax%PrintFor(%text%, %y%)%$$ 00031 $pre 00032 $$ 00033 $syntax%%f%.Forward(0, %x%)%$$ 00034 00035 00036 $head Purpose$$ 00037 The current value of an $syntax%AD<%Base%>%$$ 00038 object $italic y$$ is the result of an AD of $italic Base$$ operation. 00039 This operation may be part of the 00040 $xref/glossary/Operation/Sequence/operation sequence/1/$$ 00041 that is transferred to an $xref/ADFun/$$ object $italic f$$. 00042 The $code ADFun$$ object can be evaluated at different values for the 00043 $cref/independent variables/glossary/Tape/Independent Variable/$$. 00044 This may result in a corresponding value for $italic y$$ 00045 that is different from when the operation sequence was recorded. 00046 The routine $code PrintFor$$ requests a printing, 00047 when $syntax%%f%.Forward(0, %x%)%$$ is executed, 00048 of the value for $italic y$$ that corresponds to the 00049 independent variable values specified by $italic x$$. 00050 00051 $head text$$ 00052 The argument $italic text$$ has prototype 00053 $syntax% 00054 const char *%text% 00055 %$$ 00056 The corresponding text is written to $code std::cout$$ before the 00057 value of $italic y$$. 00058 00059 $head y$$ 00060 The argument $italic y$$ has one of the following prototypes 00061 $syntax% 00062 const AD<%Base%> &%y% 00063 const VecAD<%Base%>::reference &%y% 00064 %$$ 00065 The value of $italic y$$ that corresponds to $italic x$$ 00066 is written to $code std::cout$$ during the execution of 00067 $syntax% 00068 %f%.Forward(0, %x%) 00069 %$$ 00070 00071 $head f.Forward(0, x)$$ 00072 The objects $italic f$$, $italic x$$, and the purpose 00073 for this operation, are documented in $xref/Forward/$$. 00074 00075 00076 $head Discussion$$ 00077 This is can be helpful for understanding why tape evaluations 00078 have trouble, for example, if the result of a tape calculation 00079 is the IEEE code for not a number $code Nan$$. 00080 00081 $head Alternative$$ 00082 The $xref/Output/$$ section describes the normal 00083 printing of values; i.e., printing when the corresponding 00084 code is executed. 00085 00086 $head Example$$ 00087 $children% 00088 print_for/print_for.cpp 00089 %$$ 00090 The program 00091 $xref/PrintFor.cpp/$$ 00092 is an example and test of this operation. 00093 The output of this program 00094 states the conditions for passing and failing the test. 00095 00096 $end 00097 ------------------------------------------------------------------------------ 00098 */ 00099 00100 namespace CppAD { 00101 template <class Base> 00102 void PrintFor(const char *text, const AD<Base> &u) 00103 { ADTape<Base> *tape = AD<Base>::tape_ptr(); 00104 CPPAD_ASSERT_KNOWN( 00105 tape != CPPAD_NULL, 00106 "PrintFor: cannot use this function because no tape" 00107 "\nis currently active (for this thread)." 00108 ); 00109 00110 if( Parameter(u) ) 00111 tape->RecordPripOp(text, u.value_); 00112 else tape->RecordPrivOp(text, u.taddr_); 00113 } 00114 template <class Base> 00115 void PrintFor(const char *text, const VecAD_reference<Base> &u) 00116 { PrintFor(text, u.ADBase()); } 00117 } 00118 00119 # endif