CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
record_vv.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_LOCAL_OPTIMIZE_RECORD_VV_HPP
2 # define CPPAD_LOCAL_OPTIMIZE_RECORD_VV_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_vv.hpp
15 Record an operation of the form (variable op variable).
16 */
17 // BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
18 namespace CppAD { namespace local { namespace optimize {
19 /*!
20 Record an operation of the form (variable op variable).
21 
22 \param play
23 player object corresponding to the old recroding.
24 
25 \param old2new
26 mapping from old operator index to information about the new recording.
27 
28 \param i_op
29 is the index in the old operation sequence for this operator.
30 the must be one of the following:
31 AddvvOp, DivvvOp, MulvvOp, PowvvOp, SubvvOp, ZmulvvOp.
32 
33 \param rec
34 is the object that will record the new operations.
35 
36 \return
37 is the operator and variable indices in the new operation sequence.
38 */
39 template <class Base>
41  const player<Base>* play ,
43  size_t i_op ,
44  recorder<Base>* rec )
45 {
46  // get_op_info
47  OpCode op;
48  const addr_t* arg;
49  size_t i_var;
50  play->get_op_info(i_op, op, arg, i_var);
51  //
52 # ifndef NDEBUG
53  switch(op)
54  { case AddvvOp:
55  case DivvvOp:
56  case MulvvOp:
57  case PowvvOp:
58  case SubvvOp:
59  case ZmulvvOp:
60  break;
61 
62  default:
63  CPPAD_ASSERT_UNKNOWN(false);
64  }
65 # endif
66  CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0 );
67  CPPAD_ASSERT_UNKNOWN( size_t(arg[0]) < i_var ); // DAG condition
68  CPPAD_ASSERT_UNKNOWN( size_t(arg[1]) < i_var ); // DAG condition
69  //
70  addr_t new_arg[2];
71  new_arg[0] = old2new[ play->var2op(arg[0]) ].new_var;
72  new_arg[1] = old2new[ play->var2op(arg[1]) ].new_var;
73  rec->PutArg( new_arg[0], new_arg[1] );
74  //
75  struct_size_pair ret;
76  ret.i_op = rec->num_op_rec();
77  ret.i_var = rec->PutOp(op);
78  CPPAD_ASSERT_UNKNOWN( 0 < new_arg[0] && size_t(new_arg[0]) < ret.i_var );
79  CPPAD_ASSERT_UNKNOWN( 0 < new_arg[1] && size_t(new_arg[1]) < ret.i_var );
80  return ret;
81 }
82 
83 } } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
84 
85 
86 # endif
addr_t PutOp(OpCode op)
Put next operator in the operation sequence.
Definition: recorder.hpp:185
The CppAD Simple Vector template class.
Definition: vector.hpp:338
CPPAD_TAPE_ADDR_TYPE addr_t
Definition: declare_ad.hpp:44
struct_size_pair record_vv(const player< Base > *play, const CppAD::vector< struct struct_old2new > &old2new, size_t i_op, recorder< Base > *rec)
Record an operation of the form (variable op variable).
Definition: record_vv.hpp:40
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
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