25 #ifndef AD_BINARY_FUNCS_HPP
26 #define AD_BINARY_FUNCS_HPP
61 #ifndef __AdBinaryFunctions_H
62 #define __AdBinaryFunctions_H 1
65 # include <boost/preprocessor/comparison/less.hpp>
66 # include <boost/preprocessor/logical/and.hpp>
67 # include <boost/preprocessor/control/if.hpp>
68 # include <boost/preprocessor/list/at.hpp>
69 # include <boost/preprocessor/list/cat.hpp>
70 # include <boost/preprocessor/list/for_each_product.hpp>
71 # include <boost/preprocessor/logical/or.hpp>
72 # include <boost/preprocessor/tuple/to_list.hpp>
73 # include <boost/preprocessor/tuple/eat.hpp>
74 # include <boost/preprocessor/facilities/empty.hpp>
75 # include <boost/preprocessor/punctuation/comma.hpp>
76 # include <boost/preprocessor/facilities/identity.hpp>
77 # include <boost/preprocessor/stringize.hpp>
83 # define AD_BINARY_FUNCTION_NAME(O) BOOST_PP_TUPLE_ELEM(5, 0, O)
84 # define AD_BINARY_FUNCTION_SYMBOL(O) BOOST_PP_TUPLE_ELEM(5, 1, O)
85 # define AD_BINARY_FUNCTION_COMMENT(O) BOOST_PP_TUPLE_ELEM(5, 2, O)
86 # define AD_BINARY_FUNCTION_GRAD(O) BOOST_PP_TUPLE_ELEM(5, 3, O)
87 # define AD_BINARY_FUNCTION_HESS(O) BOOST_PP_TUPLE_ELEM(5, 4, O)
90 # define AD_BINARY_FUNCTIONS \
91 BOOST_PP_TUPLE_TO_LIST( \
94 ( ADBinFunPow , pow, "Power function", (expr2_.value() * expr1_.grad(__i) * math::pow(expr1_.value(),expr2_.value()-1)), (expr2_.value() * ( (expr2_.value()-1) * expr1_.grad(__i) * expr1_.grad(__j) * math::pow(expr1_.value(),expr2_.value()-2) + expr1_.hessian(__i,__j) * math::pow(expr1_.value(),expr2_.value()-1))) ) \
111 enum { nvar = Expr1::nvar };
114 typedef typename Expr1::value_type value_type;
124 AdFuncPow (
const Expr1 & expr1,
const Expr2& expr2 ) : expr1_( expr1 ), expr2_( expr2 )
130 template<
int isFundamental,
typename Expr1_,
typename Expr2_>
134 typedef typename Expr1_::value_type value_type;
136 static value_type value( Expr1_
const& expr1_, Expr2_
const& expr2_ )
138 return pow( expr1_.value(), expr2_.value() );
140 static value_type grad( Expr1_
const& expr1_, Expr2_
const& expr2_,
int __i )
142 return expr2_.value() * expr1_.grad( __i ) * pow( expr1_.value(),expr2_.value()-1 );
144 static value_type
hessian( Expr1_
const& expr1_, Expr2_
const& expr2_,
int __i,
int __j )
146 return expr2_.value() * ( ( expr2_.value()-1 ) * expr1_.grad( __i ) * expr1_.grad( __j ) * pow( expr1_.value(),expr2_.value()-2 ) + expr1_.hessian( __i,__j ) * pow( expr1_.value(),expr2_.value()-1 ) );
149 template<
typename Expr1_,
typename Expr2_>
150 struct Value<true, Expr1_, Expr2_>
152 typedef typename Expr1_::value_type value_type;
154 static value_type value( Expr1_
const& expr1_, Expr2_
const& expr2_ )
156 return std::pow( expr1_.value(), expr2_.value() );
158 static value_type grad( Expr1_
const& expr1_, Expr2_
const& expr2_,
int __i )
160 return expr2_.value() * expr1_.grad( __i ) * std::pow( expr1_.value(),expr2_.value()-1 );
162 static value_type
hessian( Expr1_
const& expr1_, Expr2_
const& expr2_,
int __i,
int __j )
164 return expr2_.value() * ( ( expr2_.value()-1 ) * expr1_.grad( __i ) * expr1_.grad( __j ) * std::pow( expr1_.value(),expr2_.value()-2 ) + expr1_.hessian( __i,__j ) * std::pow( expr1_.value(),expr2_.value()-1 ) );
168 inline value_type value()
const
170 return Value<
true,Expr1,Expr2>::value( expr1_, expr2_ );
172 inline value_type grad(
int __i )
const
174 return Value<
true,Expr1,Expr2>::grad( expr1_, expr2_, __i );
176 inline value_type hessian(
int __i,
int __j )
const
178 return Value<
true,Expr1, Expr2>::hessian( expr1_, expr2_, __i, __j );
180 inline bool deps(
int __i )
const
182 return expr1_.deps( __i ) || expr2_.deps( __i );
186 template <
class Expr1,
class Expr2>
195 template <
class T,
int Nvar,
int Order,
int Var>
204 template <
class W,
class T,
int Nvar,
int Order,
int Var>
209 typedef AdFuncPow< ADType<T, Nvar, Order, Var>, ADCst<W> > expr_t;
brief description
Definition: adbinaryfunctions.hpp:107
PolynomialSet< Poly, Tensor2 > hessian(PolynomialSet< Poly, Scalar > const &p)
compute the gradient of a vectorial polynomial set
Definition: operations.hpp:231
Automatically Diffentiated Numerical Type.
Definition: adtype.hpp:92
brief description
Definition: adexpr.hpp:44