49 template <
typename ScalarRes,
typename Scalar1,
typename Scalar2>
50 ScalarRes
func(
const Scalar1&
a,
const Scalar1& b,
const Scalar2&
c) {
57 void func_deriv(
double a,
double b,
double c,
double& drda,
double& drdb)
63 int main(
int argc,
char **argv)
77 const int num_deriv = 2;
78 Kokkos::View<double**,Kokkos::LayoutLeft,Kokkos::HostSpace> v(
"v", 2, num_deriv );
81 Kokkos::deep_copy( v, 0.0 );
95 ViewFadType afad( &v(0,0), &a, num_deriv, v.stride_1() );
96 ViewFadType bfad( &v(1,0), &b, num_deriv, v.stride_1() );
101 double r = func<double>(
a, b,
c);
108 rfad = func<FadType>(afad, bfad, cfad);
111 double r_ad = rfad.val();
112 double drda_ad = rfad.dx(0);
113 double drdb_ad = rfad.dx(1);
118 std::cout.setf(std::ios::scientific);
119 std::cout.precision(p);
120 std::cout <<
" r = " << r <<
" (original) == " << std::setw(w) << r_ad
121 <<
" (AD) Error = " << std::setw(w) << 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;
129 double tol = 1.0e-14;
133 std::cout <<
"\nExample passed!" << std::endl;
137 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
Sacado::Fad::DFad< double > FadType
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)