From 1adad63b14aa8d13295fb0d68fbdc8ab988775b2 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 23 Oct 2025 23:43:54 +0200 Subject: Add uniform-tree test and benchmark We need an optimisation that detects replicate-like behaviour and turns it into actual replicates, which should then be fused away. The problem is exhibited by this function exUniformFree. --- src/Example.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Example.hs') diff --git a/src/Example.hs b/src/Example.hs index 1784a48..bccc8de 100644 --- a/src/Example.hs +++ b/src/Example.hs @@ -167,3 +167,14 @@ neuralGo = (Value dinput_2 `SCons` Value dlay3_2 `SCons` Value dlay2_2 `SCons` Value dlay1_2 `SCons` SNil) = drevByFwdInterp knownEnv neural argument 1.0 in trace (ppExpr knownEnv revderiv) $ (primal, (dlay1_1, dlay2_1, dlay3_1, dinput_1), (dlay1_2, dlay2_2, dlay3_2, dinput_2)) + +-- The build body uses free variables in a non-linear way, so their primal +-- values are required in the dual of the build. Thus, compositionally, they +-- are stored in the tape from each individual lambda invocation. This results +-- in n copies of y and z, where only one copy would have sufficed. +exUniformFree :: Ex '[R, I64] R +exUniformFree = fromNamed $ lambda #n $ lambda #x $ body $ + let_ #y (#x * 2) $ + let_ #z (#x * 3) $ + idx0 $ sum1i $ + build1 #n $ #i :-> #y * #z + toFloat_ #i -- cgit v1.2.3-70-g09d2