47 template <
typename Scalar>
48 Scalar
func(
const int m,
const Scalar x[]) {
51 for (
int i=0; i<m; ++i)
64 static type apply(
const int n,
const int i,
const double x) {
69 static type apply(
const int n,
const double x,
const double v[]) {
71 for (
int i=0; i<
n; ++i)
72 x_fad.fastAccessDx(i) = v[i];
81 static type apply(
const int n,
const int i,
const double x) {
86 static type apply(
const int n,
const double x,
const double v[]) {
88 for (
int i=0; i<
n; ++i)
89 x_fad.fastAccessDx(i) = v[i];
96 template <
typename TermIterator>
102 template <
typename T,
typename TermIterator>
107 if (term == term_end)
117 int main(
int argc,
char **argv)
122 const double x0[m] = { 1.0, 1.0, 1.0 };
123 const double V[m][
n] = { {0.1, 0.2},
129 std::vector<int> term = { 0, 0, 0, 1, 1, 1 };
134 NestedFadType x_fad[m];
135 for (
int i=0; i<m; ++i)
137 const NestedFadType f_fad =
func(m,x_fad);
142 NestedFadType x_fad2[m];
143 for (
int i=0; i<m; ++i)
145 const NestedFadType f_fad2 =
func(m,x_fad2);
154 const int r = term.size();
155 std::vector<int> t(r, 0);
156 bool finished =
false;
160 for (
int i=0; i<r; ++i) {
161 c *= V[t[i]][term[i]];
168 while (j<r-1 && t[j] >= m) {
178 std::cout <<
"z (reduced) = " << z1 <<
" z (full) = " << z2
179 <<
" error = " <<
error << std::endl;
181 const double tol = 1.0e-14;
183 std::cout <<
"\nExample passed!" << std::endl;
187 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;