diff options
author | Tom Smeding <tom@tomsmeding.com> | 2025-03-26 15:11:48 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2025-03-26 15:11:48 +0100 |
commit | a00234388d1b4e14481067d030bf90031258b756 (patch) | |
tree | 501b6778fc5779ce220aba1e22f56ae60f68d970 /src/AST/UnMonoid.hs | |
parent | 7971f6dff12bc7b66a5d4ae91a6791ac08872c31 (diff) |
D2[Array] now has a Maybe instead of zero-size for zero
Remaining problem: 'add' in Compile doesn't use the D2 stuff
Diffstat (limited to 'src/AST/UnMonoid.hs')
-rw-r--r-- | src/AST/UnMonoid.hs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/AST/UnMonoid.hs b/src/AST/UnMonoid.hs index b30f7a0..0da1afc 100644 --- a/src/AST/UnMonoid.hs +++ b/src/AST/UnMonoid.hs @@ -51,8 +51,8 @@ zero STNil = ENil ext zero (STPair t1 t2) = ENothing ext (STPair (d2 t1) (d2 t2)) zero (STEither t1 t2) = ENothing ext (STEither (d2 t1) (d2 t2)) zero (STMaybe t) = ENothing ext (d2 t) -zero (STArr SZ t) = EUnit ext (zero t) -zero (STArr n t) = EBuild ext n (eTup (sreplicate n (EConst ext STI64 0))) (EError ext (d2 t) "empty") +zero (STArr SZ t) = ENothing ext (STArr SZ (d2 t)) +zero (STArr n t) = ENothing ext (STArr n (d2 t)) zero (STScal t) = case t of STI32 -> ENil ext STI64 -> ENil ext @@ -84,8 +84,7 @@ plus (STMaybe t) a b = plusSparse (d2 t) a b $ plus t (EVar ext (d2 t) (IS IZ)) (EVar ext (d2 t) IZ) plus (STArr n t) a b = - ELet ext a $ - ELet ext (weakenExpr WSink b) $ + plusSparse (STArr n (d2 t)) a b $ eif (eshapeEmpty n (EShape ext (EVar ext (STArr n (d2 t)) (IS IZ)))) (EVar ext (STArr n (d2 t)) IZ) (eif (eshapeEmpty n (EShape ext (EVar ext (STArr n (d2 t)) IZ))) @@ -131,7 +130,8 @@ onehot typ topprj idx arg = case (typ, topprj) of (STArr n t1, SAPArrIdx prj _) -> let tidx = tTup (sreplicate n tIx) in ELet ext idx $ - EBuild ext n (ESnd ext (EFst ext (EVar ext (typeOf idx) IZ))) $ - eif (eidxEq n (EVar ext tidx IZ) (EFst ext (EFst ext (EVar ext (typeOf idx) (IS IZ))))) - (onehot t1 prj (ESnd ext (EVar ext (typeOf idx) (IS IZ))) (weakenExpr (WSink .> WSink) arg)) - (zero t1) + EJust ext $ + EBuild ext n (ESnd ext (EFst ext (EVar ext (typeOf idx) IZ))) $ + eif (eidxEq n (EVar ext tidx IZ) (EFst ext (EFst ext (EVar ext (typeOf idx) (IS IZ))))) + (onehot t1 prj (ESnd ext (EVar ext (typeOf idx) (IS IZ))) (weakenExpr (WSink .> WSink) arg)) + (zero t1) |