CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_SIGN_OP_INCLUDED 00003 # define CPPAD_SIGN_OP_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 CPPAD_BEGIN_NAMESPACE 00018 /*! 00019 \defgroup sign_op_hpp sign_op.hpp 00020 \{ 00021 \file sign_op.hpp 00022 Forward and reverse mode calculations for z = sign(x). 00023 */ 00024 00025 /*! 00026 Compute forward mode Taylor coefficient for result of op = SignOp. 00027 00028 The C++ source code corresponding to this operation is 00029 \verbatim 00030 z = sign(x) 00031 \endverbatim 00032 00033 \copydetails forward_unary1_op 00034 */ 00035 template <class Base> 00036 inline void forward_sign_op( 00037 size_t j , 00038 size_t i_z , 00039 size_t i_x , 00040 size_t nc_taylor , 00041 Base* taylor ) 00042 { 00043 // check assumptions 00044 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); 00045 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); 00046 CPPAD_ASSERT_UNKNOWN( i_x < i_z ); 00047 CPPAD_ASSERT_UNKNOWN( j < nc_taylor ); 00048 00049 // Taylor coefficients corresponding to argument and result 00050 Base* x = taylor + i_x * nc_taylor; 00051 Base* z = taylor + i_z * nc_taylor; 00052 00053 if( j == 0 ) 00054 z[j] = sign(x[j]); 00055 else z[j] = Base(0.); 00056 } 00057 00058 /*! 00059 Compute zero order forward mode Taylor coefficient for result of op = SignOp. 00060 00061 The C++ source code corresponding to this operation is 00062 \verbatim 00063 z = sign(x) 00064 \endverbatim 00065 00066 \copydetails forward_unary1_op_0 00067 */ 00068 template <class Base> 00069 inline void forward_sign_op_0( 00070 size_t i_z , 00071 size_t i_x , 00072 size_t nc_taylor , 00073 Base* taylor ) 00074 { 00075 00076 // check assumptions 00077 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); 00078 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); 00079 CPPAD_ASSERT_UNKNOWN( i_x < i_z ); 00080 CPPAD_ASSERT_UNKNOWN( 0 < nc_taylor ); 00081 00082 // Taylor coefficients corresponding to argument and result 00083 Base x0 = *(taylor + i_x * nc_taylor); 00084 Base* z = taylor + i_z * nc_taylor; 00085 00086 z[0] = sign(x0); 00087 } 00088 /*! 00089 Compute reverse mode partial derivatives for result of op = SignOp. 00090 00091 The C++ source code corresponding to this operation is 00092 \verbatim 00093 z = sign(x) 00094 \endverbatim 00095 00096 \copydetails reverse_unary1_op 00097 */ 00098 00099 template <class Base> 00100 inline void reverse_sign_op( 00101 size_t d , 00102 size_t i_z , 00103 size_t i_x , 00104 size_t nc_taylor , 00105 const Base* taylor , 00106 size_t nc_partial , 00107 Base* partial ) 00108 { 00109 // check assumptions 00110 CPPAD_ASSERT_UNKNOWN( NumArg(SignOp) == 1 ); 00111 CPPAD_ASSERT_UNKNOWN( NumRes(SignOp) == 1 ); 00112 CPPAD_ASSERT_UNKNOWN( i_x < i_z ); 00113 CPPAD_ASSERT_UNKNOWN( d < nc_taylor ); 00114 CPPAD_ASSERT_UNKNOWN( d < nc_partial ); 00115 00116 // nothing to do because partials of sign are zero 00117 return; 00118 } 00119 00120 /*! \} */ 00121 CPPAD_END_NAMESPACE 00122 # endif