/usr/include/cppad/local/independent.hpp is in cppad 2014.00.00.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | /* $Id: independent.hpp 2991 2013-10-22 16:25:15Z bradbell $ */
# ifndef CPPAD_INDEPENDENT_INCLUDED
# define CPPAD_INDEPENDENT_INCLUDED
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
CppAD is distributed under multiple licenses. This distribution is under
the terms of the
GNU General Public License Version 3.
A copy of this license is included in the COPYING file of this distribution.
Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
-------------------------------------------------------------------------- */
/*
---------------------------------------------------------------------------
$begin Independent$$
$spell
alloc
num
Cpp
bool
const
var
typename
$$
$index Independent$$
$index start, recording$$
$index recording, start$$
$index variable, independent$$
$section Declare Independent Variables and Start Recording$$
$head Syntax$$
$codei%Independent(%x%)%$$
$head Purpose$$
Start recording
$cref/AD of Base/glossary/AD of Base/$$ operations
with $icode x$$ as the independent variable vector.
Once the
$cref/operation sequence/glossary/Operation/Sequence/$$ is completed,
it must be transferred to a function object; see below.
$head Start Recording$$
An operation sequence recording is started by the command
$codei%
Independent(%x%)
%$$
$head Stop Recording$$
The recording is stopped,
and the operation sequence is transferred to the AD function object $icode f$$,
using either the $cref/function constructor/FunConstruct/$$
$codei%
ADFun<%Base%> %f%( %x%, %y%)
%$$
or the $cref/dependent variable specifier/Dependent/$$
$codei%
%f%.Dependent( %x%, %y%)
%$$
The only other way to stop a recording is using
$cref abort_recording$$.
Between when the recording is started and when it stopped,
we refer to the elements of $icode x$$,
and the values that depend on the elements of $icode x$$,
as $codei%AD<%Base%>%$$ variables.
$head x$$
The vector $icode x$$ has prototype
$codei%
%VectorAD% &%x%
%$$
(see $icode VectorAD$$ below).
The size of the vector $icode x$$, must be greater than zero,
and is the number of independent variables for this
AD operation sequence.
$head VectorAD$$
The type $icode VectorAD$$ must be a $cref SimpleVector$$ class with
$cref/elements of type/SimpleVector/Elements of Specified Type/$$
$codei%AD<%Base%>%$$.
The routine $cref CheckSimpleVector$$ will generate an error message
if this is not the case.
$head Parallel Mode$$
$index parallel, Independent$$
$index Independent, parallel$$
The call to $code Independent$$,
and the corresponding call to
$codei%
ADFun<%Base%> %f%( %x%, %y%)
%$$
or
$codei%
%f%.Dependent( %x%, %y%)
%$$
or $cref abort_recording$$,
must be preformed by the same thread; i.e.,
$cref/thread_alloc::thread_num/ta_thread_num/$$ must be the same.
$head Example$$
$children%
example/independent.cpp
%$$
The file
$cref independent.cpp$$
contains an example and test of this operation.
It returns true if it succeeds and false otherwise.
$end
-----------------------------------------------------------------------------
*/
// BEGIN CppAD namespace
namespace CppAD {
// ---------------------------------------------------------------------------
template <typename Base>
template <typename VectorAD>
void ADTape<Base>::Independent(VectorAD &x)
{
// check VectorAD is Simple Vector class with AD<Base> elements
CheckSimpleVector< AD<Base>, VectorAD>();
// dimension of the domain space
size_t n = x.size();
CPPAD_ASSERT_KNOWN(
n > 0,
"Indepdendent: the argument vector x has zero size"
);
CPPAD_ASSERT_UNKNOWN( Rec_.num_rec_var() == 0 );
// mark the beginning of the tape and skip the first variable index
// (zero) because parameters use taddr zero
CPPAD_ASSERT_NARG_NRES(BeginOp, 1, 1);
Rec_.PutOp(BeginOp);
Rec_.PutArg(0);
// place each of the independent variables in the tape
CPPAD_ASSERT_NARG_NRES(InvOp, 0, 1);
size_t j;
for(j = 0; j < n; j++)
{ // tape address for this independent variable
x[j].taddr_ = Rec_.PutOp(InvOp);
x[j].tape_id_ = id_;
CPPAD_ASSERT_UNKNOWN( size_t(x[j].taddr_) == j+1 );
CPPAD_ASSERT_UNKNOWN( Variable(x[j] ) );
}
// done specifying all of the independent variables
size_independent_ = n;
}
template <typename VectorAD>
inline void Independent(VectorAD &x)
{ typedef typename VectorAD::value_type ADBase;
typedef typename ADBase::value_type Base;
CPPAD_ASSERT_KNOWN(
ADBase::tape_ptr() == CPPAD_NULL,
"Independent: cannot create a new tape because\n"
"a previous tape is still active (for this thread).\n"
"AD<Base>::abort_recording() would abort this previous recording."
);
ADTape<Base>* tape = ADBase::tape_manage(tape_manage_new);
tape->Independent(x);
}
}
// END CppAD namespace
# endif
|