25 template <
typename ScalarT>
26 ScalarT
func(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c) {
33 template <
typename ScalarT>
34 void func_deriv(
const ScalarT&
a,
const ScalarT& b,
const ScalarT&
c,
35 ScalarT& drda, ScalarT& drdb)
44 int main(
int argc,
char **argv)
64 std::cout <<
"Flop counts for function evaluation:";
73 std::cout <<
"\nFlop counts for analytic derivative evaluation:";
84 std::cout <<
"\nFlop counts for AD function and derivative evaluation:";
89 double drda = drdas.
val();
90 double drdb = drdbs.
val();
92 double r_ad = rfad.val().val();
93 double drda_ad = rfad.dx(0).val();
94 double drdb_ad = rfad.dx(1).val();
99 std::cout.setf(std::ios::scientific);
100 std::cout.precision(p);
101 std::cout <<
"\nValues/derivatives of computation" << std::endl
102 <<
" r = " << r <<
" (original) == " << std::setw(w) << r_ad
103 <<
" (AD) Error = " << std::setw(w) << r - r_ad << std::endl
104 <<
"dr/da = " << std::setw(w) << drda <<
" (analytic) == "
105 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
106 << drda - drda_ad << std::endl
107 <<
"dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
108 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
109 << drdb - drdb_ad << std::endl;
111 double tol = 1.0e-14;
120 std::cout <<
"\nExample passed!" << std::endl;
124 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
double totalFlopCount
Total flop count.
static FlopCounts getCounters()
Get the flop counts after a block of computations.
static void resetCounters()
Reset static flop counters before starting a block of computations.
const T & val() const
Return the current value.
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
static std::ostream & printCounters(std::ostream &out)
Print the current static flop counts to out.
Class storing flop counts and summary flop counts.
TypeTo as(const TypeFrom &t)
void func_deriv(double a, double b, double c, double &drda, double &drdb)
Templated flop counter class.
Sacado::Fad::DFad< SFC > FAD_SFC
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)
static void finalizeCounters()
Finalize total flop count after block of computations.
Sacado::FlopCounterPack::ScalarFlopCounter< double > SFC