1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
// SPDX-FileContributor: 2003-22 Bradley M. Bell
// ----------------------------------------------------------------------------
// Test hash coding of parameter during recording
# include <cppad/cppad.hpp>
namespace { // BEGIN empty namespace
template <class Float>
bool test_repeat(void)
{ bool ok = true;
using namespace CppAD;
// number of different constant parameters
size_t n_constant = 13;
// number of normal parameter repeats
size_t n_repeat = 17;
// number of independent dynamic parameters
size_t n_dynamic = 5;
// independent variable vector
size_t n = n_constant * n_repeat;
CPPAD_TESTVECTOR(AD<Float>) ax(n), dynamic(n_dynamic);
// dynamic parameter all have same value, but that could change
for(size_t j = 0; j < n_dynamic; ++j)
dynamic[j] = 3.0;
for(size_t j = 0; j < n; j++)
ax[j] = Float(j);
size_t abort_op_index = 0;
bool record_compare = true;
Independent(ax, abort_op_index, record_compare, dynamic);
// dependent variable vector and indices
size_t m = n;
CPPAD_TESTVECTOR(AD<Float>) ay(m);
for(size_t i = 0; i < m; i++)
{ // must avoid Float(k) = 0 because it would get optimized out
size_t k = (i % n_constant);
k = k * k * 10 + 1;
size_t j = i;
ay[i] = ax[j] + Float(k);
}
// create f: ax -> ay
ADFun<Float> f(ax, ay);
// add one for the phantom parameter at index zero
ok = f.size_par() == 1 + n_constant + n_dynamic;
return ok;
}
} // END empty namespace
bool parameter(void)
{ bool ok = true;
ok &= test_repeat<double>();
ok &= test_repeat<float>();
//
return ok;
}
|