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

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

Change assert_arg_before_result so will be easier to add cache.

  • 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 3340 2014-09-19 10:49:12Z 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        vector<double> y_cache(2);
64        y = f.Forward(0, x);
65       
66        std::cout << "y       = " << y       << std::endl;
67        std::cout << "y_cache = " << y_cache << std::endl;
68        */
69
70        return ok;
71}
72int main(void)
73{       bool ok = test_cache();
74        std::cout << "OK = " << ok << std::endl;
75        return int(! ok);
76}
77EOF
78# Turn on tracing
79forward='../../cppad/local/forward0sweep.hpp'
80sed \
81        -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 0|\1 1|' \
82        -i $forward
83reverse='../../cppad/local/reverse_sweep.hpp'
84sed \
85        -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 0|\1 1|' \
86        -i $reverse
87#
88echo "g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name"
89g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name
90#
91echo "./$name"
92./$name
93#
94echo "rm $name $name.cpp"
95rm $name $name.cpp
96#
97sed \
98        -e 's|^\(# define CPPAD_FORWARD0SWEEP_TRACE\) 1|\1 0|' \
99        -i $forward
100#
101sed \
102        -e 's|^\(# define CPPAD_REVERSE_SWEEP_TRACE\) 1|\1 0|' \
103        -i $reverse
Note: See TracBrowser for help on using the repository browser.