From b1664532eaebdf0409ab6d93fc0ba2ef8dfbf372 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 27 Apr 2025 23:34:59 +0200 Subject: WIP revamp accumulators again: explicit monoid types No more D2 in accumulators! Paving the way for configurable sparsity of products and arrays. The idea is to make separate monoid types for a "product cotangent" and an "array cotangent" that can be lowered to either a sparse monoid or a non-sparse monoid. Downsides of this approach: lots of API duplication. --- src/AST/Count.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/AST/Count.hs') diff --git a/src/AST/Count.hs b/src/AST/Count.hs index dc8ec72..feaaa1e 100644 --- a/src/AST/Count.hs +++ b/src/AST/Count.hs @@ -113,6 +113,10 @@ occCountGeneral onehot unpush alter many = go WId ENothing _ _ -> mempty EJust _ e -> re e EMaybe _ a b e -> re a <> re1 b <> re e + ELNil _ _ _ -> mempty + ELInl _ _ e -> re e + ELInr _ _ e -> re e + ELCase _ e a b c -> re e <> (re a `alter` re1 b `alter` re1 c) EConstArr{} -> mempty EBuild _ _ a b -> re a <> many (re1 b) EFold1Inner _ _ a b c -> many (unpush (unpush (go (WSink .> WSink .> w) a))) <> re b <> re c @@ -130,7 +134,7 @@ occCountGeneral onehot unpush alter many = go WId ECustom _ _ _ _ _ _ _ a b -> re a <> re b EWith _ _ a b -> re a <> re1 b EAccum _ _ _ a b e -> re a <> re b <> re e - EZero _ _ -> mempty + EZero _ _ e -> re e EPlus _ _ a b -> re a <> re b EOneHot _ _ _ a b -> re a <> re b EError{} -> mempty -- cgit v1.2.3-70-g09d2