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

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

Change reverse mode plan and have multiple weights in reverse mode example.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1#! /bin/bash -e
2# $Id: cache.sh 3329 2014-09-14 11:58:41Z 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);
54        x[0] = 1.0;
55        x[1] = 2.0;
56        f.Forward(0, x);
57        w[0] = 1.0;
58        w[1] = 2.0;
59        f.Reverse(1, w);
60
61        f.cache();
62
63
64        return ok;
65}
66int main(void)
67{       bool ok = test_cache();
68        std::cout << "OK = " << ok << std::endl;
69        return int(! ok);
70}
71EOF
72# Turn on tracing
73forward='../../cppad/local/forward0sweep.hpp'
74sed \
75        -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 0|\1 1|' \
76        -i $forward
77reverse='../../cppad/local/reverse_sweep.hpp'
78sed \
79        -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 0|\1 1|' \
80        -i $reverse
81#
82echo "g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name"
83g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name
84#
85echo "./$name"
86./$name
87#
88echo "rm $name $name.cpp"
89rm $name $name.cpp
90#
91svn revert $forward
92svn revert $reverse
Note: See TracBrowser for help on using the repository browser.