CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
arg_variable.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_LOCAL_SUBGRAPH_ARG_VARIABLE_HPP
2 # define CPPAD_LOCAL_SUBGRAPH_ARG_VARIABLE_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 
15 
16 // BEGIN_CPPAD_LOCAL_SUBGRAPH_NAMESPACE
17 namespace CppAD { namespace local { namespace subgraph {
18 /*!
19 \file arg_variable.hpp
20 Determine arguments that are variables.
21 */
22 
23 /*!
24 Determine the set of arguments, for an operator, that are variables.
25 
26 \param play
27 is the player for this operation sequence.
28 
29 \param i_op
30 is the operator index. If this operator is part of a user function call,
31 it must be the first UserOp in the call. (There is a UserOp at the
32 beginning and end of each call.)
33 
34 \param variable
35 is the set of argument variables corresponding to this operator.
36 If the operator is a UserOp, the arguments are the variables
37 that are passed into the function call.
38 
39 \param work
40 this is work space used by arg_variable to make subsequent calls
41 faster. It should not be used by the calling routine. In addition,
42 it is better if work does not drop out of scope between calls.
43 */
44 template <typename Base>
46  const player<Base>* play ,
47  size_t i_op ,
48  pod_vector<size_t>& variable ,
49  pod_vector<bool>& work )
50 {
51  // reset to size zero, but keep allocated memory
52  variable.resize(0);
53  //
54  // operator corresponding to i_op
55  OpCode op;
56  const addr_t* op_arg;
57  size_t i_var;
58  play->get_op_info(i_op, op, op_arg, i_var);
59  //
60  // partial check of assumptions on user function calls
62  op != UsrapOp && op != UsravOp && op != UsrrpOp && op != UsrrvOp
63  );
64  //
65  // we assume this is the first UserOp of the call
66  if( op == UserOp )
67  { play->get_op_info(++i_op, op, op_arg, i_var);
68  while( op != UserOp )
69  { switch(op)
70  {
71  case UsravOp:
72  { CPPAD_ASSERT_NARG_NRES(op, 1, 0);
73  size_t j_var = op_arg[0];
74  variable.push_back(j_var);
75  }
76  break;
77 
78  case UsrrvOp:
79  case UsrrpOp:
80  case UsrapOp:
81  break;
82 
83  default:
84  // cannot find second UserOp in this call
85  CPPAD_ASSERT_UNKNOWN(false);
86  break;
87  }
88  play->get_op_info(++i_op, op, op_arg, i_var);
89  }
90  CPPAD_ASSERT_UNKNOWN( variable.size() > 0 );
91  return;
92  }
93  // is_varialbe is a reference to work with a better name
94  pod_vector<bool>& is_variable(work);
95  size_t num_arg = arg_is_variable(op, op_arg, is_variable);
96  for(size_t j = 0; j < num_arg; ++j)
97  { if( is_variable[j] )
98  { size_t j_var = op_arg[j];
99  variable.push_back(j_var);
100  }
101  }
102  return;
103 }
104 
105 } } } // END_CPPAD_LOCAL_SUBGRAPH_NAMESPACE
106 
107 # endif
void resize(size_t n)
resize the vector (existing elements preserved when n &lt;= capacity_).
Definition: pod_vector.hpp:180
size_t arg_is_variable(OpCode op, const addr_t *arg, pod_vector< bool > &is_variable)
Determines which arguments are variaibles for an operator.
Definition: op_code.hpp:911
void push_back(const Type &e)
Add an element to theh back of this vector.
Definition: pod_vector.hpp:312
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
File used to define pod_vector class.
void get_argument_variable(const player< Base > *play, size_t i_op, pod_vector< size_t > &variable, pod_vector< bool > &work)
Determine the set of arguments, for an operator, that are variables.
OpCode
Type used to distinguish different AD&lt; Base &gt; atomic operations.
Definition: op_code.hpp:49
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 size(void) const
current number of elements in this vector.
Definition: pod_vector.hpp:79
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
#define CPPAD_ASSERT_NARG_NRES(op, n_arg, n_res)
Check that operator op has the specified number of of arguments and results.