25 template <
typename ScalarT>
26 ScalarT
func(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c) {
32 void func_deriv(
double a,
double b,
double c,
double& drda,
double& drdb)
39 void func_deriv2(
double a,
double b,
double c,
double& d2rda2,
double& d2rdb2,
47 int main(
int argc,
char **argv)
68 double r =
func(a, b, c);
75 double d2rda2, d2rdb2, d2rdadb;
79 rrad =
func(arad, brad, crad);
84 double r_ad = rrad.
val().val();
85 double drda_ad = arad.
adj().val();
86 double drdb_ad = brad.adj().val();
87 double d2rda2_ad = arad.
adj().dx(0);
88 double d2rdadb_ad = arad.
adj().dx(1);
89 double d2rdbda_ad = brad.adj().dx(0);
90 double d2rdb2_ad = brad.adj().dx(1);
95 std::cout.setf(std::ios::scientific);
96 std::cout.precision(p);
97 std::cout <<
" r = " << std::setw(w) << r <<
" (original) == "
98 << std::setw(w) << r_ad <<
" (AD) Error = " << std::setw(w)
99 << r - r_ad << std::endl
100 <<
" dr/da = " << std::setw(w) << drda <<
" (analytic) == "
101 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
102 << drda - drda_ad << std::endl
103 <<
" dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
104 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
105 << drdb - drdb_ad << std::endl
106 <<
"d^2r/da^2 = " << std::setw(w) << d2rda2 <<
" (analytic) == "
107 << std::setw(w) << d2rda2_ad <<
" (AD) Error = " << std::setw(w)
108 << d2rda2 - d2rda2_ad << std::endl
109 <<
"d^2r/db^2 = " << std::setw(w) << d2rdb2 <<
" (analytic) == "
110 << std::setw(w) << d2rdb2_ad <<
" (AD) Error = " << std::setw(w)
111 << d2rdb2 - d2rdb2_ad << std::endl
112 <<
"d^2r/dadb = " << std::setw(w) << d2rdadb <<
" (analytic) == "
113 << std::setw(w) << d2rdadb_ad <<
" (AD) Error = " << std::setw(w)
114 << d2rdadb - d2rdadb_ad << std::endl
115 <<
"d^2r/dbda = " << std::setw(w) << d2rdadb <<
" (analytic) == "
116 << std::setw(w) << d2rdbda_ad <<
" (AD) Error = " << std::setw(w)
117 << d2rdadb - d2rdbda_ad << std::endl;
125 double tol = 1.0e-14;
132 std::cout <<
"\nExample passed!" << std::endl;
136 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
void func_deriv2(double a, double b, double c, double &d2rda2, double &d2rdb2, double &d2rdadb)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
void func_deriv(double a, double b, double c, double &drda, double &drdb)
const T func(int n, T *x)
SACADO_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)