27 template <
typename ScalarRes,
typename Scalar1,
typename Scalar2>
28 ScalarRes
func(
const Scalar1&
a,
const Scalar1& b,
const Scalar2&
c) {
35 void func_deriv(
double a,
double b,
double c,
double& drda,
double& drdb)
41 int main(
int argc,
char **argv)
55 const int num_deriv = 2;
56 Kokkos::View<double**,Kokkos::LayoutLeft,Kokkos::HostSpace> v(
"v", 2, num_deriv );
59 Kokkos::deep_copy( v, 0.0 );
73 ViewFadType afad( &v(0,0), &a, num_deriv, v.stride_1() );
74 ViewFadType bfad( &v(1,0), &b, num_deriv, v.stride_1() );
79 double r = func<double>(
a, b,
c);
86 rfad = func<FadType>(afad, bfad, cfad);
89 double r_ad = rfad.val();
90 double drda_ad = rfad.dx(0);
91 double drdb_ad = rfad.dx(1);
96 std::cout.setf(std::ios::scientific);
97 std::cout.precision(p);
98 std::cout <<
" r = " << r <<
" (original) == " << std::setw(w) << r_ad
99 <<
" (AD) Error = " << std::setw(w) << 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;
107 double tol = 1.0e-14;
111 std::cout <<
"\nExample passed!" << std::endl;
115 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
Sacado::Fad::DFad< double > FadType
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)