CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
record_pv.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_LOCAL_OPTIMIZE_RECORD_PV_HPP
2 # define CPPAD_LOCAL_OPTIMIZE_RECORD_PV_HPP
3 /* --------------------------------------------------------------------------
4 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 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 /*!
14 \file record_pv.hpp
15 Record an operation of the form (parameter op variable).
16 */
17 // BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
18 namespace CppAD { namespace local { namespace optimize {
19 
20 /*!
21 Record an operation of the form (parameter op variable).
22 
23 \param play
24 player object corresponding to the old recroding.
25 
26 \param old2new
27 mapping from old operator index to information about the new recording.
28 
29 \param i_op
30 is the index in the old operation sequence for this operator.
31 The operator must be one of the following:
32 AddpvOp, DivpvOp, MulpvOp, PowpvOp, SubpvOp, ZmulpvOp.
33 
34 \param rec
35 is the object that will record the new operations.
36 
37 \return
38 is the operator and variable indices in the new operation sequence.
39 */
40 template <class Base>
42  const player<Base>* play ,
44  size_t i_op ,
45  recorder<Base>* rec )
46 {
47  // get_op_info
48  OpCode op;
49  const addr_t* arg;
50  size_t i_var;
51  play->get_op_info(i_op, op, arg, i_var);
52  //
53 # ifndef NDEBUG
54  switch(op)
55  { case AddpvOp:
56  case DivpvOp:
57  case MulpvOp:
58  case PowpvOp:
59  case SubpvOp:
60  case ZmulpvOp:
61  break;
62 
63  default:
64  CPPAD_ASSERT_UNKNOWN(false);
65  }
66  // number of parameters corresponding to the old operation sequence.
67  size_t npar = play->num_par_rec();
68 # endif
69  //
70  // vector of length npar containing the parameters the old operation
71  // sequence; i.e., given a parameter index i < npar, the corresponding
72  // parameter value is par[i].
73  const Base* par = play->GetPar();
74  //
75  CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 );
76  CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < npar );
77  CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_var ); // DAG condition
78  //
79  addr_t new_arg[2];
80  new_arg[0] = rec->PutPar( par[arg[0]] );
81  new_arg[1] = old2new[ play->var2op(arg[1]) ].new_var;
82  rec->PutArg( new_arg[0], new_arg[1] );
83  //
84  struct_size_pair ret;
85  ret.i_op = rec->num_op_rec();
86  ret.i_var = rec->PutOp(op);
87  CPPAD_ASSERT_UNKNOWN( 0 < new_arg[1] && size_t(new_arg[1]) < ret.i_var );
88  return ret;
89 }
90 
91 } } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
92 
93 
94 # endif
addr_t PutOp(OpCode op)
Put next operator in the operation sequence.
Definition: recorder.hpp:185
size_t num_par_rec(void) const
Fetch number of parameters in the recording.
Definition: player.hpp:638
The CppAD Simple Vector template class.
Definition: vector.hpp:338
CPPAD_TAPE_ADDR_TYPE addr_t
Definition: declare_ad.hpp:44
Class used to store and play back an operation sequence recording.
Definition: declare_ad.hpp:27
void PutArg(addr_t arg0)
Put one operation argument index in the recording.
Definition: recorder.hpp:392
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
Definition: op_code.hpp:281
addr_t PutPar(const Base &par)
Find or add a parameter to the current vector of parameters.
Definition: recorder.hpp:314
OpCode
Type used to distinguish different AD&lt; Base &gt; atomic operations.
Definition: op_code.hpp:49
Class used to store an operation sequence while it is being recorded (the operation sequence is copie...
Definition: declare_ad.hpp:28
void get_op_info(size_t op_index, OpCode &op, const addr_t *&op_arg, size_t &var_index) const
fetch the information corresponding to an operator
Definition: player.hpp:485
size_t i_var
operator index for this variable
Definition: size_pair.hpp:27
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
size_t num_op_rec(void) const
Number of operators currently stored in the recording.
Definition: recorder.hpp:144
size_t var2op(size_t var_index) const
fetch the operator corresponding to a primary variable
Definition: player.hpp:461
Base GetPar(size_t i) const
Fetch a parameter from the recording.
Definition: player.hpp:584
struct_size_pair record_pv(const player< Base > *play, const CppAD::vector< struct struct_old2new > &old2new, size_t i_op, recorder< Base > *rec)
Record an operation of the form (parameter op variable).
Definition: record_pv.hpp:41