1 #ifndef CPPAD_CG_EVALUATOR_SOLVE_INCLUDED 2 #define CPPAD_CG_EVALUATOR_SOLVE_INCLUDED 26 template<
class Scalar>
44 const std::vector<const SourceCodePath*>* paths_;
49 const std::vector<const std::vector<CG<Scalar>*>*>* replaceOnPath_;
58 const std::map<const PathNodeEdges<Scalar>*,
CG<Scalar>>* replaceOnGraph_;
62 const std::set<const OperationNode<Scalar>*>* clone_;
66 const std::map<const OperationPathNode<Scalar>,
CG<Scalar>>* replaceArgument_;
79 const std::vector<const SourceCodePath*>& paths,
80 const std::vector<
const std::vector<
CG<Scalar>*>*>& replaceOnPath) :
83 replaceOnPath_(&replaceOnPath),
85 replaceOnGraph_(nullptr),
87 replaceArgument_(nullptr) {
88 CPPADCG_ASSERT_UNKNOWN(paths_->size() == replaceOnPath_->size());
90 for (
size_t i = 0; i < paths.size(); ++i) {
91 CPPADCG_ASSERT_UNKNOWN(paths[i]->size() == replaceOnPath[i]->size());
108 replaceOnPath_(nullptr),
109 pathGraph_(&pathGraph),
110 replaceOnGraph_(&replaceOnGraph),
112 replaceArgument_(nullptr) {
127 replaceOnPath_(nullptr),
129 replaceOnGraph_(nullptr),
131 replaceArgument_(&replaceArgument) {
141 CPPADCG_ASSERT_UNKNOWN(this->depth_ > 0);
143 if(paths_ !=
nullptr) {
144 const auto& paths = *paths_;
145 for (
size_t i = 0; i < paths.size(); ++i) {
146 size_t d = this->depth_ - 1;
147 if (isOnPath(*paths[i])) {
150 auto* r = (*(*replaceOnPath_)[i])[d];
160 if(pathGraph_ !=
nullptr) {
162 if (egdes !=
nullptr) {
163 auto it = replaceOnGraph_->find(egdes);
164 if (it != replaceOnGraph_->end()) {
172 if (clone_ !=
nullptr) {
173 if (clone_->find(&node) != clone_->end()) {
178 if (replaceArgument_ !=
nullptr) {
179 size_t d = this->depth_ - 1;
181 auto it = replaceArgument_->find(this->path_[d - 1]);
182 if (it != replaceArgument_->end()) {
192 inline bool isOnPath(
const SourceCodePath& path)
const {
193 size_t d = this->depth_ - 1;
195 if (d >= path.size())
198 if (this->path_[d].node != path[d].node)
202 for (
size_t j = 0; j < d; ++j) {
203 if (this->path_[j] != path[j]) {
ActiveOut evalOperation(OperationNode< ScalarIn > &node)
EvaluatorCloneSolve(CodeHandler< Scalar > &handler, const std::set< const OperationNode< Scalar > *> &clone, const std::map< const OperationPathNode< Scalar >, CG< Scalar >> &replaceArgument)
ActiveOut evalOperation(OperationNode< Scalar > &node)
EvaluatorCloneSolve(CodeHandler< Scalar > &handler, const BidirGraph< Scalar > &pathGraph, const std::map< const PathNodeEdges< Scalar > *, CG< Scalar > > &replaceOnGraph)
EvaluatorCloneSolve(CodeHandler< Scalar > &handler, const std::vector< const SourceCodePath *> &paths, const std::vector< const std::vector< CG< Scalar > *> *> &replaceOnPath)