source: trunk/test_more/parameter.cpp @ 3779

Last change on this file since 3779 was 3779, checked in by bradbell, 4 years ago

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: cf5ca238670f67655fbbf3e23727437f7ed7b182
end hash code: 5661e2a629cceb77e7b703225bc1f3f8cf422129

commit 5661e2a629cceb77e7b703225bc1f3f8cf422129
Author: Brad Bell <bradbell@…>
Date: Fri Jan 1 04:23:41 2016 -0700

push_git2svn.py: Include changes in copyright date when checking for difference.

commit f0e9d149dc00ccf410a268389e3dcfd95499b863
Author: Brad Bell <bradbell@…>
Date: Fri Jan 1 03:57:09 2016 -0700

Advance copyright year to 2016.

commit 01d25679b7baddca878129635b0758f4ebb263fb
Author: Brad Bell <bradbell@…>
Date: Fri Jan 1 03:54:41 2016 -0700

download.omh: improve the no documentation download instructions.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1// $Id: parameter.cpp 3779 2016-01-01 11:26:11Z bradbell $
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Eclipse Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13// Test hash coding of parameter during recording
14
15# include <cppad/cppad.hpp>
16
17namespace { // BEGIN empty namespace
18
19template <class Float>
20bool test(void)
21{       bool ok = true;
22        using namespace CppAD;
23
24        // number of different parameter values
25        size_t n_parameter = 13;
26
27        // number of parameter repeats
28        size_t n_repeat = 17;
29
30        // independent variable vector
31        size_t j, n = n_parameter * n_repeat;
32        CPPAD_TESTVECTOR(AD<Float>) ax(n);
33        for(j = 0; j < n; j++)
34                ax[j] = Float(j);
35        Independent(ax);
36
37        // dependent variable vector and indices
38        size_t i, m = n;
39        CPPAD_TESTVECTOR(AD<Float>) ay(m);
40        for(i = 0; i < m; i++)
41        {       // must avoid Float(k) = 0 because it would get optimized out
42                size_t k = (i % n_parameter);
43                k        = k * k * 10 + 1;
44                j        = i;
45                ay[i] = ax[j] + Float(k);
46        }
47
48        // create f: ax -> ay
49        ADFun<Float> f(ax, ay);
50
51        ok = f.size_par() == n_parameter;
52
53        return ok;
54}
55
56} // END empty namespace
57
58bool parameter(void)
59{       bool ok = true;
60        ok &= test<double>();
61        ok &= test<float>();
62        return ok;
63}
Note: See TracBrowser for help on using the repository browser.