# ifndef CPPAD_AD_INCLUDED # define CPPAD_AD_INCLUDED /* -------------------------------------------------------------------------- CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-08 Bradley M. Bell CppAD is distributed under multiple licenses. This distribution is under the terms of the Common Public License Version 1.0. A copy of this license is included in the COPYING file of this distribution. Please visit http://www.coin-or.org/CppAD/ for information on other licenses. -------------------------------------------------------------------------- */ // simple AD operations that must be defined for AD as well as base class # include # include // define the template classes that are used by the AD template class # include # include # include # include // BEGIN CppAD namespace namespace CppAD { template class AD { // template friend functions where template parameter is not bound template friend void Independent(VectorAD &x); // one argument functions friend bool GreaterThanZero (const AD &u); friend bool LessThanZero (const AD &u); friend bool LessThanOrZero (const AD &u); friend bool GreaterThanOrZero (const AD &u); friend bool Parameter (const AD &u); friend bool Parameter (const VecAD &u); friend bool Variable (const AD &u); friend bool Variable (const VecAD &u); friend bool IdenticalPar (const AD &u); friend bool IdenticalZero (const AD &u); friend bool IdenticalOne (const AD &u); friend int Integer (const AD &u); friend AD Var2Par (const AD &u); // power function friend AD pow (const AD &x, const AD &y); // IdenticalEqualPar function friend bool IdenticalEqualPar (const AD &u, const AD &v); // EqualOpSeq function friend bool EqualOpSeq (const AD &u, const AD &v); // NearEqual function friend bool NearEqual ( const AD &x, const AD &y, const Base &r, const Base &a); friend bool NearEqual ( const Base &x, const AD &y, const Base &r, const Base &a); friend bool NearEqual ( const AD &x, const Base &y, const Base &r, const Base &a); // CondExp function friend AD CondExpOp ( enum CompareOp cop , const AD &left , const AD &right , const AD &trueCase , const AD &falseCase ); // classes friend class ADTape; friend class ADDiscrete; friend class ADFun; friend class VecAD; friend class VecAD_reference; // arithematic binary operators friend AD operator + (const AD &left, const AD &right); friend AD operator - (const AD &left, const AD &right); friend AD operator * (const AD &left, const AD &right); friend AD operator / (const AD &left, const AD &right); // comparison operators friend bool operator < (const AD &left, const AD &right); friend bool operator <= (const AD &left, const AD &right); friend bool operator > (const AD &left, const AD &right); friend bool operator >= (const AD &left, const AD &right); friend bool operator == (const AD &left, const AD &right); friend bool operator != (const AD &left, const AD &right); // output operations friend std::ostream& operator << (std::ostream &os, const AD &x); friend void PrintFor (const char *text, const AD &x); public: // type of value typedef Base value_type; // default constructor inline AD(void); // use default copy constructor and assignment operator // inline AD(const AD &x); // inline AD& operator=(const AD &x); // construction and assingment from base type inline AD(const Base &b); inline AD& operator=(const Base &b); // contructor and assignment from VecAD::reference inline AD(const VecAD_reference &x); inline AD& operator=(const VecAD_reference &x); // construction and assignment from some other type template inline AD(const T &t); template inline AD& operator=(const T &right); // base type corresponding to an AD object friend Base Value (const AD &x); // computed assignment operators inline AD& operator += (const AD &right); inline AD& operator -= (const AD &right); inline AD& operator *= (const AD &right); inline AD& operator /= (const AD &right); // unary operators inline AD operator +(void) const; inline AD operator -(void) const; // destructor ~AD(void) { } // interface so these functions need not be friends inline AD Abs(void) const; inline AD acos(void) const; inline AD asin(void) const; inline AD atan(void) const; inline AD cos(void) const; inline AD cosh(void) const; inline AD exp(void) const; inline AD log(void) const; inline AD sin(void) const; inline AD sinh(void) const; inline AD sqrt(void) const; // ---------------------------------------------------------- // static public member functions static size_t omp_max_thread(size_t number); // These functions declared public so can be accessed by user through // a macro interface and are not intended for direct use. // The macro interface is documented in bool_fun.hpp. // Developer documentation for these fucntions is in bool_fun_link.hpp static inline bool UnaryBool( bool FunName(const Base &x), const AD &x ); static inline bool BinaryBool( bool FunName(const Base &x, const Base &y), const AD &x , const AD &y ); private: // value_ corresponding to this object Base value_; // tape identifier corresponding to taddr // This is a variable if and only if id_ == *id_handle() size_t id_; // taddr_ in tape for this variable size_t taddr_; // // Make this variable a parameter // void make_parameter(void) { CPPAD_ASSERT_UNKNOWN( Variable(*this) ); // currently a var id_ = 0; } // // Make this parameter a new variable // void make_variable(size_t id, size_t taddr) { CPPAD_ASSERT_UNKNOWN( Parameter(*this) ); // currently a par CPPAD_ASSERT_UNKNOWN( taddr > 0 ); // sure valid taddr taddr_ = taddr; id_ = id; } // --------------------------------------------------------------- // tape linking functions // // not static inline ADTape *tape_this(void) const; // // static inline static size_t *id_handle (size_t thread); inline static ADTape **tape_handle(size_t thread); static size_t tape_new(void); static void tape_delete(size_t id); inline static ADTape *tape_ptr(void); inline static ADTape *tape_ptr(size_t id); }; // --------------------------------------------------------------------------- } // END CppAD namespace // tape linking private functions # include // operations that expect the AD template class to be defined # endif