52 template <
typename ScalarT>
53 ScalarT
func(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c) {
60 void func_deriv(
double a,
double b,
double c,
double& drda,
double& drdb)
66 int main(
int argc,
char **argv)
90 double r =
func(a, b, c);
97 rfad =
func(afad, bfad, cfad);
100 double r_ad = rfad.val();
101 double drda_ad = rfad.dx(0);
102 double drdb_ad = rfad.dx(1);
107 std::cout.setf(std::ios::scientific);
108 std::cout.precision(p);
109 std::cout <<
" r = " << r <<
" (original) == " << std::setw(w) << r_ad
110 <<
" (AD) Error = " << std::setw(w) << r - r_ad << std::endl
111 <<
"dr/da = " << std::setw(w) << drda <<
" (analytic) == "
112 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
113 << drda - drda_ad << std::endl
114 <<
"dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
115 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
116 << drdb - drdb_ad << std::endl;
118 double tol = 1.0e-14;
122 std::cout <<
"\nExample passed!" << std::endl;
126 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
MemPool * getMemoryPool(unsigned int dim)
Get memory pool for supplied dimension dim.
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
Derivative array storage class using dynamic memory allocation.
void func_deriv(double a, double b, double c, double &drda, double &drdb)
const T func(int n, T *x)
Forward-mode AD class using dynamic memory allocation and expression templates.