47 template <
typename ScalarT>
48 ScalarT
func(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c) {
54 void func_deriv(
double a,
double b,
double c,
double& drda,
double& drdb)
61 void func_deriv2(
double a,
double b,
double c,
double& d2rda2,
double& d2rdb2,
69 int main(
int argc,
char **argv)
90 double r =
func(a, b, c);
97 double d2rda2, d2rdb2, d2rdadb;
101 rrad =
func(arad, brad, crad);
106 double r_ad = rrad.
val().val();
107 double drda_ad = arad.
adj().val();
108 double drdb_ad = brad.adj().val();
109 double d2rda2_ad = arad.
adj().dx(0);
110 double d2rdadb_ad = arad.
adj().dx(1);
111 double d2rdbda_ad = brad.adj().dx(0);
112 double d2rdb2_ad = brad.adj().dx(1);
117 std::cout.setf(std::ios::scientific);
118 std::cout.precision(p);
119 std::cout <<
" r = " << std::setw(w) << r <<
" (original) == "
120 << std::setw(w) << r_ad <<
" (AD) Error = " << std::setw(w)
121 << r - r_ad << std::endl
122 <<
" dr/da = " << std::setw(w) << drda <<
" (analytic) == "
123 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
124 << drda - drda_ad << std::endl
125 <<
" dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
126 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
127 << drdb - drdb_ad << std::endl
128 <<
"d^2r/da^2 = " << std::setw(w) << d2rda2 <<
" (analytic) == "
129 << std::setw(w) << d2rda2_ad <<
" (AD) Error = " << std::setw(w)
130 << d2rda2 - d2rda2_ad << std::endl
131 <<
"d^2r/db^2 = " << std::setw(w) << d2rdb2 <<
" (analytic) == "
132 << std::setw(w) << d2rdb2_ad <<
" (AD) Error = " << std::setw(w)
133 << d2rdb2 - d2rdb2_ad << std::endl
134 <<
"d^2r/dadb = " << std::setw(w) << d2rdadb <<
" (analytic) == "
135 << std::setw(w) << d2rdadb_ad <<
" (AD) Error = " << std::setw(w)
136 << d2rdadb - d2rdadb_ad << std::endl
137 <<
"d^2r/dbda = " << std::setw(w) << d2rdadb <<
" (analytic) == "
138 << std::setw(w) << d2rdbda_ad <<
" (AD) Error = " << std::setw(w)
139 << d2rdadb - d2rdbda_ad << std::endl;
141 double tol = 1.0e-14;
148 std::cout <<
"\nExample passed!" << std::endl;
152 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
void func_deriv2(double a, double b, double c, double &d2rda2, double &d2rdb2, double &d2rdadb)
KOKKOS_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)
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)