27#include <ql/shared_ptr.hpp>
33 const std::vector<std::function<T(
const std::vector<const T*>&)>>& ops,
34 std::function<
void(T&)> deleter = {},
bool keepValuesForDerivatives =
true,
35 const std::vector<std::function<std::pair<std::vector<bool>,
bool>(
const std::size_t)>>&
36 opRequiresNodesForDerivatives = {},
37 const std::vector<bool>& keepNodes = {},
const std::size_t startNode = 0,
40 std::vector<bool> keepNodesDerivatives;
41 if (deleter && keepValuesForDerivatives)
42 keepNodesDerivatives = std::vector<bool>(g.
size(),
false);
55 for (std::size_t arg = 0; arg < g.
predecessors(node).size(); ++arg) {
58 values[node] = ops[g.
opId(node)](args);
60 QL_REQUIRE(values[node].initialised(),
"forwardEvaluation(): value at active node "
61 << node <<
" is not initialized, opId = " << g.
opId(node));
66 for (std::size_t arg = 0; arg < g.
predecessors(node).size(); ++arg) {
69 if (!keepNodesDerivatives.empty()) {
73 if (opRequiresNodesForDerivatives[g.
opId(p)](args.size()).second ||
74 opRequiresNodesForDerivatives[g.
opId(node)](args.size()).first[arg])
75 keepNodesDerivatives[p] =
true;
85 if ((!keepNodes.empty() && keepNodes[p]) ||
86 (!keepNodesDerivatives.empty() && keepNodesDerivatives[p] &&
87 (g.
redBlockId(p) == 0 || redBlockReconstruction)))
const std::vector< std::size_t > & predecessors(const std::size_t node) const
std::size_t maxNodeRequiringArg(const std::size_t node) const
std::size_t redBlockId(const std::size_t node) const
std::size_t opId(const std::size_t node) const
void forwardEvaluation(const ComputationGraph &g, std::vector< T > &values, const std::vector< std::function< T(const std::vector< const T * > &)> > &ops, std::function< void(T &)> deleter={}, bool keepValuesForDerivatives=true, const std::vector< std::function< std::pair< std::vector< bool >, bool >(const std::size_t)> > &opRequiresNodesForDerivatives={}, const std::vector< bool > &keepNodes={}, const std::size_t startNode=0, const std::size_t endNode=ComputationGraph::nan, const bool redBlockReconstruction=false)