From 2542f5ef42452967fec1d2376927c1f36bf263f4 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 23 Oct 2025 23:53:37 +0200 Subject: WIP fold: Implement D[fold1i] Still need to handle the new primitives in the rest of the library --- src/CHAD/Accum.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/CHAD') diff --git a/src/CHAD/Accum.hs b/src/CHAD/Accum.hs index 7212232..a7bc53f 100644 --- a/src/CHAD/Accum.hs +++ b/src/CHAD/Accum.hs @@ -44,6 +44,11 @@ d2deepZeroInfo (STArr _ t) e = emap (d2deepZeroInfo t (EVar ext (d1 t) IZ)) e d2deepZeroInfo (STScal t) _ | Refl <- lemDeepZeroInfoScal t = ENil ext d2deepZeroInfo STAccum{} _ = error "accumulators not allowed in source program" +-- The weakening is necessary because we need to initialise the created +-- accumulators with zeros. Those zeros are deep and need full primals. This +-- means, in the end, that primals corresponding to environment entries +-- promoted to an accumulator with accumPromote in CHAD need to be stored for +-- the dual. makeAccumulators :: D1E envPro :> env -> SList STy envPro -> Ex (Append (D2AcE envPro) env) t -> Ex env (InvTup t (D2E envPro)) makeAccumulators _ SNil e = e makeAccumulators w (t `SCons` envpro) e = -- cgit v1.2.3-70-g09d2