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

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

Implement and test first order forward mode.

cache.sh: Erase taylor coefficient when create cache.
forward1sweep.hpp: copy more information from forward0sweep.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#! /bin/bash -e
2# $Id: cache.sh 3344 2014-09-20 09:45:43Z 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        size_t n = 2;
42        size_t m = 2;
43        vector< AD<double> > ax(n), ay(m);
44
45        ax[0] = 0.0;
46        ax[1] = 0.0;
47        CppAD::Independent(ax);
48
49        ay[0] = 5 * (ax[0] + ax[1]);
50        ay[1] = ay[0] + 5 * (ax[0] - ax[1]);
51
52        ADFun<double> f;
53        f.Dependent(ax, ay);
54
55        // zero order forward, no cache
56        vector<double> x(n), y(m);
57        x[0] = 1.0;
58        x[1] = 2.0;
59        y = f.Forward(0, x);
60
61        // first order forward, no cache
62        vector<double> dx(n), dy(m);
63        dx[0] = 3.0;
64        dx[1] = 4.0;
65        dy = f.Forward(1, dx);
66
67        // create cache
68        f.cache();
69
70        // zero order forward, with cache
71        vector<double> y_cache(m);
72        y_cache = f.Forward(0, x);
73        ok &= y[0] == y_cache[0];
74        ok &= y[1] == y_cache[1];
75        // std::cout << "y       = " << y       << std::endl;
76        // std::cout << "y_cache = " << y_cache << std::endl;
77
78
79        // first order forward, with cache
80        vector<double> dy_cache(m);
81        dy_cache = f.Forward(1, dx);
82        ok &= dy[0] == dy_cache[0];
83        ok &= dy[1] == dy_cache[1];
84        // std::cout << "dy       = " << dy       << std::endl;
85        // std::cout << "dy_cache = " << dy_cache << std::endl;
86
87        return ok;
88}
89int main(void)
90{       bool ok = test_cache();
91        std::cout << "OK = " << ok << std::endl;
92        return int(! ok);
93}
94EOF
95echo "g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name"
96g++ -g $name.cpp -I../.. -fopenmp -std=c++11 -o $name
97#
98echo "./$name"
99./$name
Note: See TracBrowser for help on using the repository browser.