source: trunk/test_more/parameter.cpp @ 2354

Last change on this file since 2354 was 2005, checked in by bradbell, 9 years ago
  1. Fix bug: all threads were using the same parameter static hash table.
  2. In output stream, change Ok: to OK: to be consistent.
  3. Add parameter.cpp, a test that the parameter hash coding works well.
  4. Reduce hash table size and use a different one for each possible thread.
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1/* $Id: parameter.cpp 2005 2011-07-12 15:00:51Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Common 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_TEST_VECTOR< 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_TEST_VECTOR< 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.