Created
December 23, 2019 00:12
-
-
Save corba777/050f2418a4a9a064f3d033b6b0e1cc0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TraceOp = | |
| // Scalar-valued operations | |
| | Add_D_D of D * D | |
| | Add_D_DCons of D | |
| ... | |
| | VarCirq_DV of DV * (DV->DV) | |
| let rec resetRec (ds:dobj list) = | |
| match ds with | |
| | [] -> () | |
| | d :: t -> | |
| match d with | |
| | :? D as d -> | |
| match d with | |
| | DR(_, o, _, uniq) -> | |
| let fanout = incrementFanout fanouts uniq | |
| if fanout = 1u then | |
| adjoints.SetD(uniq,D.Zero) | |
| match o with | |
| | Add_D_D(a, b) -> resetRec (bxd a :: bxd b :: t) | |
| | Add_D_DCons(a) -> resetRec (bxd a :: t) | |
| ... | |
| | VarCirq_DV(a,_) -> resetRec (bxd a :: t) | |
| let rec pushRec (ds:(delta*dobj) list) = | |
| match ds with | |
| | [] -> () | |
| | (v, d) :: t -> | |
| match v, d with | |
| | (:? Delta as delta), (:? D as d) -> | |
| match d with | |
| | DR(_, o, _, uniq) -> | |
| let dA = adjoints.ApplyDelta(uniq, delta) | |
| let fanout = fanouts.[uniq] - 1u | |
| fanouts.[uniq] <- fanout | |
| // If all incoming parts of the adjoint have been received, then proceed to the parent | |
| if fanout = 0u then | |
| match o with | |
| | Add_D_D(a, b) -> pushRec ((bx dA a) :: (bx dA b) :: t) | |
| | Add_D_DCons(a) -> pushRec ((bx dA a) :: t) | |
| ... | |
| | VarCirq_DV(a,f)->pushRec ((bxv (dA*f(a.P)) a) :: t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment