CppAD: A C++ Algorithmic Differentiation Package  20130918
num_skip.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_NUM_SKIP_INCLUDED
00003 # define CPPAD_NUM_SKIP_INCLUDED
00004 
00005 /* --------------------------------------------------------------------------
00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 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 $begin number_skip$$
00018 $spell
00019      optimizer
00020      var
00021      taylor_
00022 $$
00023 
00024 $index number_skip$$
00025 $index number, skip variables$$
00026 $index skip, number variables$$
00027 $index variables, skip$$
00028 
00029 $section Number of Variables that Can be Skipped$$
00030 
00031 $head Syntax$$
00032 $icode%n% = %f%.number_skip()%$$
00033 
00034 $subhead See Also$$
00035 $cref seq_property$$
00036 
00037 $head Purpose$$
00038 The $cref/conditional expressions/CondExp/$$ use either the
00039 $cref/if_true/CondExp/$$ or $cref/if_false/CondExp/$$.
00040 This leads to the fact that some terms only need to be evaluated
00041 depending on the value of the comparison in the conditional expression.
00042 The $cref optimize$$ option is capable of detecting some of these 
00043 case and determining variables that can be skipped.
00044 This routine returns the number such variables.
00045 
00046 $head n$$
00047 The return value $icode n$$ has type $code size_t$$
00048 is the number of variables that the optimizer has determined can be skipped 
00049 (given the independent variable values specified by the previous call to
00050 $cref/f.Forward/Forward/$$ for order zero).
00051 
00052 $head f$$
00053 The object $icode f$$ has prototype
00054 $codei%
00055      ADFun<%Base%> %f%
00056 %$$
00057 
00058 $children%
00059      example/number_skip.cpp
00060 %$$
00061 $head Example$$
00062 The file $cref number_skip.cpp$$
00063 contains an example and test of this function.
00064 It returns true if it succeeds and false otherwise.
00065 
00066 $end
00067 -----------------------------------------------------------------------------
00068 */
00069 
00070 // BEGIN CppAD namespace
00071 namespace CppAD {
00072 
00073 // This routine is not const becasue it runs through the operations sequence
00074 // 2DO: compute this value during zero order forward operations.
00075 template <typename Base>
00076 size_t ADFun<Base>::number_skip(void)
00077 {    // must pass through operation sequence to map operations to variables
00078      OpCode op;
00079      size_t        i_op;
00080      size_t        i_var;
00081      const addr_t* arg;
00082 
00083      // number of variables skipped
00084      size_t n_skip = 0;
00085 
00086      // start playback
00087      play_.forward_start(op, arg, i_op, i_var);
00088      CPPAD_ASSERT_UNKNOWN(op == BeginOp)
00089      while(op != EndOp)
00090      {    // next op
00091           play_.forward_next(op, arg, i_op, i_var);
00092           if( op == CSumOp)
00093                play_.forward_csum(op, arg, i_op, i_var);
00094           else if (op == CSkipOp)
00095                play_.forward_cskip(op, arg, i_op, i_var);
00096           //
00097           if( cskip_op_[i_op] )
00098                n_skip += NumRes(op);
00099      }
00100      return n_skip;
00101 }
00102 
00103 } // END CppAD namespace
00104      
00105 
00106 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines