source: branches/cache/bug/cache.sh @ 3343

Last change on this file since 3343 was 3343, checked in by bradbell, 6 years ago

Fix and automate zero order forward mode test.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#! /bin/bash -e
2# $Id: cache.sh 3343 2014-09-19 19:24:59Z bradbell $
3# -----------------------------------------------------------------------------
4# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
5#
6# CppAD is distributed under multiple licenses. This distribution is under
7# the terms of the
8#                     Eclipse Public License Version 1.0.
9#
10# A copy of this license is included in the COPYING file of this distribution.
11# Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
12# -----------------------------------------------------------------------------
13#!/bin/bash -e
14#
15echo "Script for testing cache feature: Under Construction"
16#
17if [ ! -e build ]
18then
19        mkdir build
20fi
21cd build
22if [ ! -e ../../cppad/configure.hpp ]
23then
24        cmake ../..
25fi
26#
27echo "$0"
28name=`echo $0 | sed -e 's|.*/||' -e 's|\..*||'`
29echo "create $name.cpp"
30cat << EOF > $name.cpp
31// BEGIN PROGRAM
32# include <cppad/cppad.hpp>
33
34// Test routine
35bool test_cache(void)
36{       bool ok = true;
37        using CppAD::vector;
38        using CppAD::AD;
39        using CppAD::ADFun;
40       
41        vector< AD<double> > ax(2), ay(2);
42
43        ax[0] = 0.0;
44        ax[1] = 0.0;
45        CppAD::Independent(ax);
46
47        ay[0] = 5 * (ax[0] + ax[1]);
48        ay[1] = ay[0] + 5 * (ax[0] - ax[1]);
49
50        ADFun<double> f;
51        f.Dependent(ax, ay);
52
53        vector<double> x(2), y(2), w(2), dw(2);
54        x[0] = 1.0;
55        x[1] = 2.0;
56        y = f.Forward(0, x);
57        w[0] = 1.0;
58        w[1] = 2.0;
59        dw = f.Reverse(1, w);
60
61        f.cache();
62
63        // test zero order forward mode
64        vector<double> y_cache(2);
65        y_cache = f.Forward(0, x);
66        ok &= y[0] == y_cache[0];
67        ok &= y[1] == y_cache[1];
68
69        return ok;
70}
71int main(void)
72{       bool ok = test_cache();
73        std::cout << "OK = " << ok << std::endl;
74        return int(! ok);
75}
76EOF
77# Turn on tracing
78forward='../../cppad/local/forward0sweep.hpp'
79sed \
80        -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 0|\1 1|' \
81        -i $forward
82reverse='../../cppad/local/reverse_sweep.hpp'
83sed \
84        -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 0|\1 1|' \
85        -i $reverse
86#
87echo "g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name"
88g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name
89#
90echo "./$name"
91./$name
92#
93#
94sed \
95        -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 1|\1 0|' \
96        -i $forward
97#
98sed \
99        -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 1|\1 0|' \
100        -i $reverse
Note: See TracBrowser for help on using the repository browser.