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

Go to the documentation of this file.
00001 # ifndef CPPAD_FORWARD_INCLUDED
00002 # define CPPAD_FORWARD_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 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 Forward$$
00017 
00018 $section Forward Mode$$
00019 
00020 $childtable%
00021         omh/forward.omh%
00022         cppad/local/cap_taylor.hpp%
00023         example/forward.cpp
00024 %$$
00025 
00026 $end
00027 -----------------------------------------------------------------------------
00028 */
00029 
00030 // documened after Forward but included here so easy to see
00031 # include <cppad/local/cap_taylor.hpp>
00032 
00033 // BEGIN CppAD namespace
00034 namespace CppAD {
00035 
00036 template <typename Base>
00037 template <typename Vector>
00038 Vector ADFun<Base>::Forward(size_t p, const Vector &up)
00039 {       // temporary indices
00040         size_t i, j;
00041 
00042         // number of independent variables
00043         size_t n = ind_taddr.size();
00044 
00045         // number of dependent variables
00046         size_t m = dep_taddr.size();
00047 
00048         // check Vector is Simple Vector class with Base type elements
00049         CheckSimpleVector<Base, Vector>();
00050 
00051         CPPAD_ASSERT_KNOWN(
00052                 up.size() == n,
00053                 "Second argument to Forward does not have length equal to\n"
00054                 "the dimension of the domain for the corresponding ADFun."
00055         );
00056         CPPAD_ASSERT_KNOWN(
00057                 p <= taylor_per_var,
00058                 "The number of Taylor coefficient currently stored\n"
00059                 "in this ADFun object is less than p."
00060         );  
00061 
00062         // check if the Taylor matrix needs more columns
00063         if( TaylorColDim <= p )
00064                 capacity_taylor(p + 1);
00065         CPPAD_ASSERT_UNKNOWN( TaylorColDim > p );
00066 
00067         // set the p-th order Taylor coefficients for independent variables
00068         for(j = 0; j < n; j++)
00069         {       CPPAD_ASSERT_UNKNOWN( ind_taddr[j] < totalNumVar );
00070 
00071                 // ind_taddr[j] is operator taddr for j-th independent variable
00072                 CPPAD_ASSERT_UNKNOWN( Rec.GetOp( ind_taddr[j] ) == InvOp );
00073 
00074                 // It is also variable taddr for j-th independent variable
00075                 Taylor[ind_taddr[j] * TaylorColDim + p] = up[j];
00076         }
00077 
00078         // evaluate the derivatives
00079         compareChange = ForwardSweep(
00080                 true, p, totalNumVar, &Rec, TaylorColDim, Taylor
00081         );
00082 
00083         // return the p-th order Taylor coefficients for dependent variables
00084         Vector vp(m);
00085         for(i = 0; i < m; i++)
00086         {       CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < totalNumVar );
00087                 vp[i] = Taylor[dep_taddr[i] * TaylorColDim + p];
00088         }
00089 
00090         // now we have p + 1  Taylor coefficients per variable
00091         taylor_per_var = p + 1;
00092 
00093         return vp;
00094 }
00095 
00096 } // END CppAD namespace
00097 
00098 
00099 # endif

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