CppAD: A C++ Algorithmic Differentiation Package  20171217
abs.hpp
Go to the documentation of this file.
3
4 /* --------------------------------------------------------------------------
6
8 the terms of the
9  Eclipse Public License Version 1.0.
10
11 A copy of this license is included in the COPYING file of this distribution.
13 -------------------------------------------------------------------------- */
14
15 /*
16 -------------------------------------------------------------------------------
17 $begin abs$$18 spell 19 fabs 20 Vec 21 std 22 faq 23 Taylor 24 Cpp 25 namespace 26 const 27 abs 28$$ 29 30$section AD Absolute Value Functions: abs, fabs$$31 32 head Syntax$$
33 $icode%y% = abs(%x%) 34 %$$35 icode%y% = fabs(%x%)%$$ 36 37$head x, y$$38 See the cref/possible types/unary_standard_math/Possible Types/$$
39 for a unary standard math function.
40
41 $head Atomic$$42 In the case where icode x$$ is an AD type, 43 this is an$cref/atomic operation/glossary/Operation/Atomic/$$. 44 45 head Complex Types$$
46 The functions $code abs$$and icode fabs$$ 47 are not defined for the base types 48$code std::complex<float>$$or code std::complex<double>$$
49 because the complex $code abs$$function is not complex differentiable 50 (see cref/complex types faq/Faq/Complex Types/$$). 51 52$head Derivative$$53 CppAD defines the derivative of the code abs$$ function is
54 the $cref sign$$function; i.e., 55 latex $56 {\rm abs}^{(1)} ( x ) = {\rm sign} (x ) = 57 \left\{ \begin{array}{rl} 58 +1 & {\rm if} \; x > 0 \\ 59 0 & {\rm if} \; x = 0 \\ 60 -1 & {\rm if} \; x < 0 61 \end{array} \right. 62$$$ 63 The result for$icode%x% == 0%$$used to be a directional derivative. 64 65 head Example$$
66 $children% 67 example/general/fabs.cpp 68 %$$69 The file 70 cref fabs.cpp$$ 71 contains an example and test of this function. 72 It returns true if it succeeds and false otherwise. 73 74$end
75 -------------------------------------------------------------------------------
76 */
77
80
81 template <class Base>
83 {
85  result.value_ = abs(value_);
87
88  if( Variable(*this) )
89  { // add this operation to the tape
93
96  // put operator in the tape
98  // make result a variable
99  result.tape_id_ = tape->id_;
100  }
101  return result;
102 }
103
104 template <class Base>
106 { return x.abs_me(); }
107
108 template <class Base>
111
112 } // END CppAD namespace
113
114 # endif
Base value_
size_t NumArg(OpCode op)
Number of arguments for a specified operator.
Definition: op_code.hpp:175
Definition: abs.hpp:105
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
Definition: op_code.hpp:281
Definition: abs.hpp:82
Definition: par_var.hpp:99
Check that exp is true, if not terminate execution.
local::recorder< Base > Rec_
This is where the information is recorded.