CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
local/independent.hpp
Go to the documentation of this file.
1 // $Id: independent.hpp 3845 2016-11-19 01:50:47Z bradbell $
2 # ifndef CPPAD_LOCAL_INDEPENDENT_HPP
3 # define CPPAD_LOCAL_INDEPENDENT_HPP
4 
5 /* --------------------------------------------------------------------------
6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
7 
8 CppAD is distributed under multiple licenses. This distribution is under
9 the terms of the
10  Eclipse Public License Version 1.0.
11 
12 A copy of this license is included in the COPYING file of this distribution.
13 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14 -------------------------------------------------------------------------- */
15 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
16 /*
17 \file local/independent.hpp
18 Implement the declaration of the independent variables
19 */
20 
21 /*!
22 Implementation of the declaration of independent variables (in local namespace).
23 
24 \tparam VectorAD
25 This is simple vector type with elements of type AD<Base>.
26 
27 \param x
28 Vector of the independent variablerd.
29 
30 \param abort_op_index
31 operator index at which execution will be aborted (during the recording
32 of operations). The value zero corresponds to not aborting (will not match).
33 */
34 template <typename Base>
35 template <typename VectorAD>
36 void ADTape<Base>::Independent(VectorAD &x, size_t abort_op_index)
37 {
38  // check VectorAD is Simple Vector class with AD<Base> elements
39  CheckSimpleVector< AD<Base>, VectorAD>();
40 
41  // dimension of the domain space
42  size_t n = x.size();
44  n > 0,
45  "Indepdendent: the argument vector x has zero size"
46  );
47  CPPAD_ASSERT_UNKNOWN( Rec_.num_var_rec() == 0 );
48 
49  // set the abort index before doing anything else
50  Rec_.set_abort_op_index(abort_op_index);
51 
52  // mark the beginning of the tape and skip the first variable index
53  // (zero) because parameters use taddr zero
55  Rec_.PutOp(BeginOp);
56  Rec_.PutArg(0);
57 
58  // place each of the independent variables in the tape
60  size_t j;
61  for(j = 0; j < n; j++)
62  { // tape address for this independent variable
63  x[j].taddr_ = Rec_.PutOp(InvOp);
64  x[j].tape_id_ = id_;
65  CPPAD_ASSERT_UNKNOWN( size_t(x[j].taddr_) == j+1 );
67  }
68 
69  // done specifying all of the independent variables
70  size_independent_ = n;
71 }
72 } } // END_CPPAD_LOCAL_NAMESPACE
73 
74 # endif
#define CPPAD_ASSERT_KNOWN(exp, msg)
Check that exp is true, if not print msg and terminate execution.
void Independent(VectorADBase &u)
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION bool Variable(const AD< Base > &x)
Definition: par_var.hpp:99
#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.