{"push_id":2791312480,"size":1,"distinct_size":1,"ref":"refs/heads/forward-mode-store-intermediate","head":"e2dc98e27cd9534a22a01e69fbf5242727f51476","before":"812d32e7a4cb2e5b2d6197ccdce2b2d5c60c2b2c","commits":[{"sha":"e2dc98e27cd9534a22a01e69fbf5242727f51476","author":{"name":"efremale","email":"6e8844043e2d5ef60b94bfddcf19da05265af6d0@icloud.com"},"message":"Store reused expressions in intermediate variables instead of\nreevaluating them in forward mode. Remove unnecessary cloning in forward\nmode. Refactor DerivativeBuilder.cpp\n\nForward mode now supports storing expression results in intermediate\nvariables. This allows to avoid reevaluation if derived expressions are\nused on several places. For example, for:\n```\ndouble t = std::sin(x) * std::cos(x);\n```\nWe now produce:\n```\ndouble _t0 = std::sin(x);\ndouble _t1 = std::cos(x);\ndouble _d_t = sin_darg0(x) * (_d_x) * _t1 + _t0 * cos_darg0(x) * (_d_x);\ndouble t = _t0 * _t1;\n```\nInstead of:\n```\ndouble _d_t = sin_darg0(x) * (_d_x) * cos(x) + sin(x) * cos_darg0(x) * (_d_x);\ndouble t = sin(x) * cos(x);\n```\nwhich allows us to avoid reevaluation of sin and cos.\n\nThis commit solves the issue #47 in case of forward mode.\nFor example, when deriving BinaryOperator, instead of cloning its whole\ntree and visiting it (potentially cloning the subtrees again), e.g.\n```\nauto ClonedBO = Clone(BO); // both LHS and RHS are cloned\nauto LHS = ClonedBO->getLHS();\nauto LHSDiff = Visit(LHS) // LHS will be cloned inside again\nauto RHS = ClonedBO->getRHS();\nauto RHSDiff = Visit(RHS);\nauto BODiff = ...// Build BODiff from LHSDiff and RHSDiff\n```\nwe first visit the whole tree and rebuild the original operation from\nthe results of subtrees, e.g.\n```\nauto [LHS, LHSDiff] = Visit(BO->getLHS());\nauto [RHS, RHSDiff] = Visit(BO->getRHS());\nauto ClonedBO = BuildOp(OpKind, LHS, RHS);\nauto BODiff = ...// Build BODiff from LHSDiff and RHSDiff.\n```\n\nSome refactoring was applied to DerivativeBuilder.cpp to support new way\nof visiting. Some functions of DerivativeBuilder and Visitors were moved\nto VisitorBase.","distinct":true,"url":"https://api.github.com/repos/efremale/clad/commits/e2dc98e27cd9534a22a01e69fbf5242727f51476"}]}
{"actor":{"display_login":"efremale"}}