! * \brief initialize for given output vars * \param dest_vars vars in fwd graph needed to give grad */
| 391 | * \param dest_vars vars in fwd graph needed to give grad |
| 392 | */ |
| 393 | void init(const VarNodeArray& dest_vars) { |
| 394 | mgb_assert(m_var_fwd2grad.empty() && !dest_vars.empty()); |
| 395 | SubgraphDepIter iter; |
| 396 | for (auto i : dest_vars) |
| 397 | iter.add(i); |
| 398 | |
| 399 | for (auto i : iter.oprs()) { |
| 400 | process_opr(i); |
| 401 | } |
| 402 | |
| 403 | for (auto i : iter.input_makers()) { |
| 404 | process_input_maker(i); |
| 405 | } |
| 406 | |
| 407 | for (auto&& i : m_var_fwd2grad) { |
| 408 | mgb_assert(i.second->owner_graph() == m_grad_desc->sub_graph()); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | //! get var in grad graph corresponding to given var in fwd graph |
| 413 | VarNode* map_var(VarNode* fwd_var) const { return m_var_fwd2grad.at(fwd_var); } |
no test coverage detected