1 # ifndef CPPAD_CORE_SUBGRAPH_REVERSE_HPP
2 # define CPPAD_CORE_SUBGRAPH_REVERSE_HPP
173 template <
typename Base>
174 template <
typename VectorBool>
179 dep_taddr_.size() == subgraph_info_.n_dep()
182 size_t( select_domain.size() ) == subgraph_info_.n_ind()
186 if( subgraph_info_.map_user_op().size() == 0 )
187 subgraph_info_.set_map_user_op(&play_);
192 subgraph_info_.map_user_op().size() == play_.num_op_rec()
196 subgraph_info_.init_rev(&play_, select_domain);
198 subgraph_info_.in_subgraph().size() == play_.num_op_rec()
257 template <
typename Base>
258 template <
typename VectorBase,
typename SizeVector>
267 CheckSimpleVector<Base, VectorBase>();
270 "The second argument to Reverse must be greater than zero."
273 num_order_taylor_ >= q,
274 "Less than q Taylor coefficients are currently stored"
275 " in this ADFun object."
278 num_direction_taylor_ == 1,
279 "reverse mode for Forward(q, r, xq) with more than one direction"
280 "\n(r > 1) is not yet supported."
283 ell < dep_taddr_.size(),
284 "dependent variable index in to large for this function"
287 subgraph_info_.process_range()[ell] ==
false,
288 "This dependent variable index has already been processed\n"
289 "after the previous subgraph_reverse(select_domain)."
293 pod_vector<addr_t> subgraph;
294 subgraph_info_.get_rev(
295 &play_, dep_taddr_,
addr_t(ell), subgraph
303 std::sort( subgraph.data(), subgraph.data() + subgraph.size() );
318 subgraph_partial_.resize(num_var_tape_ * q);
319 for(
size_t k = 0; k < subgraph.size(); ++k)
321 size_t i_op = size_t( subgraph[k] );
325 play_.get_op_info(i_op, op, arg, i_var);
336 size_t j_var = i_var + 1 -
NumRes(op);
337 for(
size_t i = j_var; i <= i_var; ++i)
338 {
for(
size_t j = 0; j < q; ++j)
339 subgraph_partial_[i * q + j] = zero;
345 subgraph_partial_[ dep_taddr_[ell] * q + q - 1] = Base(1);
359 subgraph_partial_.data(),
367 size_t subgraph_index = 0;
368 while( subgraph_index < subgraph.size() )
370 if( subgraph[subgraph_index] >
addr_t(n) )
371 subgraph_index = subgraph.size();
377 col.resize(col_size);
381 for(
size_t c = 0; c < col_size; ++c)
382 {
size_t i_op = subgraph[c];
390 for(
size_t k = 0; k < q; k++)
391 dw[j * q + k ] = subgraph_partial_[ind_taddr_[j] * q + k];
395 "f.subgraph_reverse(dw, q, ell): dw has a nan,\n"
396 "but none of f's Taylor coefficents are nan."
#define CPPAD_ASSERT_KNOWN(exp, msg)
Check that exp is true, if not print msg and terminate execution.
CPPAD_TAPE_ADDR_TYPE addr_t
A vector class with Type element that does not use element constructors or destructors when Type is P...
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
void entire_call(const player< Base > *play, pod_vector< addr_t > &subgraph)
Convert from just firt UserOp to entire atomic function call in a subgraph.
OpCode
Type used to distinguish different AD< Base > atomic operations.
bool hasnan(const Vector &v)
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
void reverse_sweep(size_t d, size_t n, size_t numvar, const local::player< Base > *play, size_t J, const Base *Taylor, size_t K, Base *Partial, bool *cskip_op, const pod_vector< addr_t > &var_by_load_op, const pod_vector< addr_t > &subgraph)
Compute derivative of arbitrary order forward mode Taylor coefficients.
void subgraph_reverse(const VectorBool &select_domain)
Initialize reverse mode derivative computation on subgraphs.