45 template <
typename ScalarT>
46 ScalarT
func(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c) {
52 void func_deriv(
double a,
double b,
double c,
double& drda,
double& drdb)
59 void func_deriv2(
double a,
double b,
double c,
double& d2rda2,
double& d2rdb2,
67 int main(
int argc,
char **argv)
90 double r =
func(a, b, c);
97 double d2rda2, d2rdb2, d2rdadb;
101 rfad =
func(afad, bfad, cfad);
104 double r_ad = rfad.val().val();
105 double drda_ad = rfad.dx(0).val();
106 double drdb_ad = rfad.dx(1).val();
107 double d2rda2_ad = rfad.dx(0).dx(0);
108 double d2rdadb_ad = rfad.dx(0).dx(1);
109 double d2rdbda_ad = rfad.dx(1).dx(0);
110 double d2rdb2_ad = rfad.dx(1).dx(1);
115 std::cout.setf(std::ios::scientific);
116 std::cout.precision(p);
117 std::cout <<
" r = " << std::setw(w) << r <<
" (original) == "
118 << std::setw(w) << r_ad <<
" (AD) Error = " << std::setw(w)
119 << r - r_ad << std::endl
120 <<
" dr/da = " << std::setw(w) << drda <<
" (analytic) == "
121 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
122 << drda - drda_ad << std::endl
123 <<
" dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
124 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
125 << drdb - drdb_ad << std::endl
126 <<
"d^2r/da^2 = " << std::setw(w) << d2rda2 <<
" (analytic) == "
127 << std::setw(w) << d2rda2_ad <<
" (AD) Error = " << std::setw(w)
128 << d2rda2 - d2rda2_ad << std::endl
129 <<
"d^2r/db^2 = " << std::setw(w) << d2rdb2 <<
" (analytic) == "
130 << std::setw(w) << d2rdb2_ad <<
" (AD) Error = " << std::setw(w)
131 << d2rdb2 - d2rdb2_ad << std::endl
132 <<
"d^2r/dadb = " << std::setw(w) << d2rdadb <<
" (analytic) == "
133 << std::setw(w) << d2rdadb_ad <<
" (AD) Error = " << std::setw(w)
134 << d2rdadb - d2rdadb_ad << std::endl
135 <<
"d^2r/dbda = " << std::setw(w) << d2rdadb <<
" (analytic) == "
136 << std::setw(w) << d2rdbda_ad <<
" (AD) Error = " << std::setw(w)
137 << d2rdadb - d2rdbda_ad << std::endl;
139 double tol = 1.0e-14;
146 std::cout <<
"\nExample passed!" << std::endl;
150 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)
Sacado::Fad::DFad< double > DFadType
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)