source: trunk/cppad/local/ad_tape.hpp @ 3845

Last change on this file since 3845 was 3845, checked in by bradbell, 3 years ago

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: 6b0d372ce8350b57b0c4fb3ad6e815316aa28b31
end hash code: 60923b98407ffc46249875d39ac667a2a5bdb8c9

commit 60923b98407ffc46249875d39ac667a2a5bdb8c9
Author: Brad Bell <bradbell@…>
Date: Fri Nov 18 18:33:53 2016 -0700

Advance to cppad-20161118.

commit 9dbc363f75937f64686b315320e1884bd39e89f3
Author: Brad Bell <bradbell@…>
Date: Fri Nov 18 09:02:02 2016 -0700

local branch:
declare_ad.hpp: remove some unecessary declarations.

commit bb55f01c0a486b9577a4a5c71c35a5a16b096c4c
Author: Brad Bell <bradbell@…>
Date: Fri Nov 18 08:05:45 2016 -0700

local branch:
Split hash_code and independent into core and local parts.

commit cade0ae629a5035b8a435a0d8f1d8534ae3c1293
Author: Brad Bell <bradbell@…>
Date: Fri Nov 18 07:01:47 2016 -0700

local branch:
Move op_code.hpp identifiers into local namespace.

commit 67ddec52a43933fb19e3fb85907056fb8493d5e0
Author: Brad Bell <bradbell@…>
Date: Fri Nov 18 04:45:24 2016 -0700

local branch:

  1. Move tape_link from local to core directory.
  2. Put following routines in local namespace: one_element_std_set, two_element_std_set, set_get_in_parallel.


check_makefile.sh: use ls_files.sh to restrict to source code makefile.am files.

commit 8da16c2145003e0fb8f133f64764d597296e486c
Author: Brad Bell <bradbell@…>
Date: Fri Nov 18 03:44:26 2016 -0700

local branch:
Move pod_vector, sparse_list, sparse_pack into local namespace.

commit fecacda7359cd23fda184a64b6afccb0785bc5fa
Author: Brad Bell <bradbell@…>
Date: Thu Nov 17 18:00:25 2016 -0700

local branch:
Move some more files from local to core.

commit 12866a5cf24f1b0a08c2be6d4afdf24b913c0796
Author: Brad Bell <bradbell@…>
Date: Thu Nov 17 07:02:54 2016 -0700

local branch:
Move add.hpp and add_eq.hpp out of local namespace directory.

commit ea43f73fcaa657a1ab6fe55f6ee473ffb6480837
Author: Brad Bell <bradbell@…>
Date: Thu Nov 17 06:52:07 2016 -0700

local branch:
Move remaining files that do not contain local namespace routines from local to core.

commit 9793adb3baf44b975a79d00d0e1265a9ed9a3393
Author: Brad Bell <bradbell@…>
Date: Thu Nov 17 05:43:14 2016 -0700

local branch:
Move more routines that are not in local namespace from local to core.

commit 324694ff288e38861cead02f785c7e736aa0d322
Author: Brad Bell <bradbell@…>
Date: Thu Nov 17 04:45:02 2016 -0700

local branch:
Move more routines not in local namespace from local to core.

commit c25e66d13a4f49456e1ed65fd7ad0b6b1d88c825
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 21:13:09 2016 -0700

local branch:
Move some more functions that are not in local namespace out of local directory.

commit 9245dd1e8621c31290f13bb01f7f52c1dab1bc7f
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 13:49:01 2016 -0700

local branch:
Move local/ad*.hpp files that declare functions in CppAD namespace to core.

commit 9dd0f3a4f4d584e3df6ae0c7b7a0352a4eabb6eb
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 13:06:05 2016 -0700

local branch:
Move all the tape operators into the local namespace.

commit 93858e16ae715f8d870192ed94dc46948c992837
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 12:53:36 2016 -0700

local branch:
Move all the sweep functions into local namespace.

commit 3e3025bd7a747252354fd49e0768e27ec59c081b
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 11:34:42 2016 -0700

local branch:
Move coloring routines into local namespace.

commit ca06cfe07cfed44b66f7a5abd47236fbb2db2e72
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 09:51:09 2016 -0700

local branch:
Move CppAD::ADTape -> CppAD::local::ADTape.

commit d3c474afcd6f87cd7130d2487a6cb5171f0a7d31
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 07:26:09 2016 -0700

check_replace.sh: remove trailing white space.
optimize.hpp: move to CppAD::local::optimize namespace.

commit 27fdf442bd0bd76d705bcbb73240da7c909eb9f0
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 07:02:32 2016 -0700

local branch:
Move cppad/local/optimize.hpp -> cppad/local/optimize/optimize.hpp

commit bca9607442ea768a064853dd524e63b4d695b621
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 06:12:17 2016 -0700

local branch:
Move recorder to local namespace.

commit 66360e9a4d832296ceb610f354e389b1d954ea62
Author: Brad Bell <bradbell@…>
Date: Wed Nov 16 05:54:40 2016 -0700

local branch:
Move player to local namespace.

  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1// $Id: ad_tape.hpp 3845 2016-11-19 01:50:47Z bradbell $
2# ifndef CPPAD_LOCAL_AD_TAPE_HPP
3# define CPPAD_LOCAL_AD_TAPE_HPP
4
5/* --------------------------------------------------------------------------
6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
7
8CppAD is distributed under multiple licenses. This distribution is under
9the terms of the
10                    Eclipse Public License Version 1.0.
11
12A copy of this license is included in the COPYING file of this distribution.
13Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14-------------------------------------------------------------------------- */
15# include <cppad/core/define.hpp>
16
17namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL__NAMESPACE
18
19/*!
20Class used to hold tape that records AD<Base> operations.
21
22\tparam Base
23An <tt>AD<Base></tt> object is used to recording <tt>AD<Base></tt> operations.
24*/
25
26template <class Base>
27class ADTape {
28        // Friends =============================================================
29
30        // classes -------------------------------------------------------------
31        friend class AD<Base>;
32        friend class ADFun<Base>;
33        friend class atomic_base<Base>;
34        friend class discrete<Base>;
35        friend class VecAD<Base>;
36        friend class VecAD_reference<Base>;
37
38        // functions -----------------------------------------------------------
39        // PrintFor
40        friend void PrintFor <Base> (
41                const AD<Base>&    flag   ,
42                const char*        before ,
43                const AD<Base>&    var    ,
44                const char*        after
45        );
46        // CondExpOp
47        friend AD<Base> CondExpOp <Base> (
48                enum CompareOp  cop          ,
49                const AD<Base> &left         ,
50                const AD<Base> &right        ,
51                const AD<Base> &trueCase     ,
52                const AD<Base> &falseCase
53        );
54        // pow
55        friend AD<Base> pow <Base>
56                (const AD<Base> &x, const AD<Base> &y);
57        // azmul
58        friend AD<Base> azmul <Base>
59                (const AD<Base> &x, const AD<Base> &y);
60        // Parameter
61        friend bool Parameter     <Base>
62                (const AD<Base> &u);
63        // Variable
64        friend bool Variable      <Base>
65                (const AD<Base> &u);
66        // operators -----------------------------------------------------------
67        // arithematic binary operators
68        friend AD<Base> operator + <Base>
69                (const AD<Base> &left, const AD<Base> &right);
70        friend AD<Base> operator - <Base>
71                (const AD<Base> &left, const AD<Base> &right);
72        friend AD<Base> operator * <Base>
73                (const AD<Base> &left, const AD<Base> &right);
74        friend AD<Base> operator / <Base>
75                (const AD<Base> &left, const AD<Base> &right);
76
77        // comparison operators
78        friend bool operator < <Base>
79                (const AD<Base> &left, const AD<Base> &right);
80        friend bool operator <= <Base>
81                (const AD<Base> &left, const AD<Base> &right);
82        friend bool operator > <Base>
83                (const AD<Base> &left, const AD<Base> &right);
84        friend bool operator >= <Base>
85                (const AD<Base> &left, const AD<Base> &right);
86        friend bool operator == <Base>
87                (const AD<Base> &left, const AD<Base> &right);
88        friend bool operator != <Base>
89                (const AD<Base> &left, const AD<Base> &right);
90        // ======================================================================
91
92// --------------------------------------------------------------------------
93private:
94        // ----------------------------------------------------------------------
95        // private data
96        /*!
97        Unique identifier for this tape.  It is always greater than
98        CPPAD_MAX_NUM_THREADS, and different for every tape (even ones that have
99        been deleted). In addition, id_ % CPPAD_MAX_NUM_THREADS is the thread
100        number for this tape. Set by Independent and effectively const
101        */
102        tape_id_t                    id_;
103        /// Number of independent variables in this tapes reconding.
104        /// Set by Independent and effectively const
105        size_t         size_independent_;
106        /// This is where the information is recorded.
107        local::recorder<Base>              Rec_;
108        // ----------------------------------------------------------------------
109        // private functions
110        //
111        // add a parameter to the tape
112        size_t RecordParOp(const Base &x);
113
114        // see CondExp.h
115        void RecordCondExp(
116                enum CompareOp  cop           ,
117                AD<Base>       &returnValue   ,
118                const AD<Base> &left          ,
119                const AD<Base> &right         ,
120                const AD<Base> &trueCase      ,
121                const AD<Base> &falseCase
122        );
123
124        // place a VecAD object in the tape
125        size_t AddVec(
126                size_t                   length,
127                const pod_vector<Base>&  data
128        );
129
130public:
131        // default constructor and destructor
132
133        // public function only used by CppAD::Independent
134        template <typename VectorADBase>
135        void Independent(VectorADBase &u);
136        template <typename VectorADBase>
137        void Independent(VectorADBase &u, size_t abort_op_index);
138
139};
140// ---------------------------------------------------------------------------
141// Private functions
142//
143
144/*!
145Place a parameter in the tape.
146
147On rare occations it is necessary to place a parameter in the tape; e.g.,
148when it is one of the dependent variabes.
149
150\param z
151value of the parameter that we are placing in the tape.
152
153\return
154variable index (for this recording) correpsonding to the parameter.
155
156\par 2DO
157All these operates are preformed in \c Rec_, so we should
158move this routine from <tt>ADTape<Base></tt> to <tt>recorder<Base></tt>.
159*/
160template <class Base>
161size_t ADTape<Base>::RecordParOp(const Base &z)
162{       size_t z_taddr;
163        size_t ind;
164        CPPAD_ASSERT_UNKNOWN( NumRes(ParOp) == 1 );
165        CPPAD_ASSERT_UNKNOWN( NumArg(ParOp) == 1 );
166        z_taddr = Rec_.PutOp(ParOp);
167        ind     = Rec_.PutPar(z);
168        Rec_.PutArg(ind);
169
170        return z_taddr;
171}
172
173/*!
174Put initialization for a VecAD<Base> object in the tape.
175
176This routine should be called once for each VecAD object when just
177before it changes from a parameter to a variable.
178
179\param length
180size of the <tt>VecAD<Base></tt> object.
181
182\param data
183initial values for the <tt>VecAD<Base></tt> object
184(values before it becomes a variable).
185
186\return
187index of the start of this vector in the list of vector indices.
188The value for this vector index is the length of the vector.
189There are \c length indices following for this vector.
190The values for these vector indices are the corresponding
191parameter indices in the tape for the initial value of the corresponding
192vec_ad element.
193
194\par 2DO
195All these operates are preformed in \c Rec_, so we should
196move this routine from <tt>ADTape<Base></tt> to <tt>recorder<Base></tt>.
197*/
198template <class Base>
199size_t ADTape<Base>::AddVec(size_t length, const pod_vector<Base>& data)
200{       CPPAD_ASSERT_UNKNOWN( length > 0 );
201        size_t i;
202        size_t value_index;
203
204        // store the length in VecInd
205        size_t start = Rec_.PutVecInd(length);
206
207        // store indices of the values in VecInd
208        for(i = 0; i < length; i++)
209        {
210                value_index = Rec_.PutPar( data[i] );
211                Rec_.PutVecInd( value_index );
212        }
213
214        // return the taddr of the length (where the vector starts)
215        return start;
216}
217
218} } // END_CPPAD_LOCAL_NAMESPACE
219
220# endif
Note: See TracBrowser for help on using the repository browser.