From ade38c607a8d0dc8dc1d701084ed88df2fa89df9 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 26 Nov 2024 23:05:30 +0100 Subject: Working argument accum mode (...) The derivative of 'neural' in full accum mode is pretty atrocious now; I think this is because when you have code like this: \(a :: Arr 1 R) -> let b = a in let c = b in sum d then because the argument, as well as both let bindings, bind a value of array type, each will introduce an accumulator, hence resulting in three (!) nested `with` clauses that each just contribute their result back to their parent. This is pointless, and we should fix this. --- test/Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/Main.hs b/test/Main.hs index d18884e..b6f9f2b 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -62,11 +62,11 @@ gradientByCHAD' = \simplIters env term input -> second (second (toTanE env input toTan typ primal der = case typ of STNil -> der STPair t1 t2 -> case der of - Left () -> bimap (zeroTan t1) (zeroTan t2) primal - Right (d₁, d₂) -> bimap (\p1 -> toTan t1 p1 d₁) (\p2 -> toTan t2 p2 d₂) primal + Nothing -> bimap (zeroTan t1) (zeroTan t2) primal + Just (d₁, d₂) -> bimap (\p1 -> toTan t1 p1 d₁) (\p2 -> toTan t2 p2 d₂) primal STEither t1 t2 -> case der of - Left () -> bimap (zeroTan t1) (zeroTan t2) primal - Right d -> case (primal, d) of + Nothing -> bimap (zeroTan t1) (zeroTan t2) primal + Just d -> case (primal, d) of (Left p, Left d') -> Left (toTan t1 p d') (Right p, Right d') -> Right (toTan t2 p d') _ -> error "Primal and cotangent disagree on Either alternative" -- cgit v1.2.3-70-g09d2