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)
61 std::cout <<
"Flop counts for function evaluation:";
70 std::cout <<
"\nFlop counts for analytic derivative evaluation:";
82 std::cout <<
"\nFlop counts for AD function and derivative evaluation:";
87 double drda = drdas.
val();
88 double drdb = drdbs.
val();
90 double r_ad = rrad.
val().val();
91 double drda_ad = arad.
adj().val();
92 double drdb_ad = brad.
adj().val();
97 std::cout.setf(std::ios::scientific);
98 std::cout.precision(p);
99 std::cout <<
"\nValues/derivatives of computation" << std::endl
100 <<
" r = " << r <<
" (original) == " << std::setw(w) << r_ad
101 <<
" (AD) Error = " << std::setw(w) << r - r_ad << std::endl
102 <<
"dr/da = " << std::setw(w) << drda <<
" (analytic) == "
103 << std::setw(w) << drda_ad <<
" (AD) Error = " << std::setw(w)
104 << drda - drda_ad << std::endl
105 <<
"dr/db = " << std::setw(w) << drdb <<
" (analytic) == "
106 << std::setw(w) << drdb_ad <<
" (AD) Error = " << std::setw(w)
107 << drdb - drdb_ad << std::endl;
109 double tol = 1.0e-14;
118 std::cout <<
"\nExample passed!" << std::endl;
122 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.
Sacado::Rad::ADvar< SFC > RAD_SFC
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.
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