summaryrefslogtreecommitdiff
path: root/src/ForwardAD.hs
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2024-10-07 14:34:27 +0200
committerTom Smeding <t.j.smeding@uu.nl>2024-10-07 14:34:27 +0200
commit72eddb67bb6f048fc2076184be3a32169026a832 (patch)
tree2f5ca7511a798d7329b12d499f4dea7239b39c50 /src/ForwardAD.hs
parent948cae3ca7279040627db393e4372a668f8a22f7 (diff)
Towards a test suite
Diffstat (limited to 'src/ForwardAD.hs')
-rw-r--r--src/ForwardAD.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ForwardAD.hs b/src/ForwardAD.hs
index 63244a8..6d53b48 100644
--- a/src/ForwardAD.hs
+++ b/src/ForwardAD.hs
@@ -52,6 +52,21 @@ tanty (STScal t) = case t of
STBool -> STNil
tanty STAccum{} = error "Accumulators not allowed in input program"
+zeroTan :: STy t -> Rep t -> Rep (Tan t)
+zeroTan STNil () = ()
+zeroTan (STPair a b) (x, y) = (zeroTan a x, zeroTan b y)
+zeroTan (STEither a _) (Left x) = Left (zeroTan a x)
+zeroTan (STEither _ b) (Right y) = Right (zeroTan b y)
+zeroTan (STMaybe _) Nothing = Nothing
+zeroTan (STMaybe t) (Just x) = Just (zeroTan t x)
+zeroTan (STArr _ t) x = fmap (zeroTan t) x
+zeroTan (STScal STI32) _ = ()
+zeroTan (STScal STI64) _ = ()
+zeroTan (STScal STF32) _ = 0.0
+zeroTan (STScal STF64) _ = 0.0
+zeroTan (STScal STBool) _ = ()
+zeroTan STAccum{} _ = error "Accumulators not allowed in input program"
+
unzipDN :: STy t -> Rep (DN t) -> (Rep t, Rep (Tan t))
unzipDN STNil _ = ((), ())
unzipDN (STPair a b) (d1, d2) =