diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2025-04-21 22:00:40 +0200 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2025-04-21 22:00:40 +0200 |
commit | b015466e7a3a18dd6708614d09e1502970305c6c (patch) | |
tree | 627c1dc947a4ef03ff55846aa5ab5fa8d4681171 /test | |
parent | 0d7319107be2d52ffbaca83ee954a43d7f923eb4 (diff) |
test: A test for new accumMap logic
Diffstat (limited to 'test')
-rw-r--r-- | test/Main.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/Main.hs b/test/Main.hs index 9dad35e..0cad9c9 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -425,6 +425,27 @@ term_mulmatvec = fromNamed $ lambda #mat $ lambda #vec $ body $ idx0 (sum1i (build1 #wid $ #j :-> #mat ! pair (pair nil #i) #j * #vec ! pair nil #j)) +term_arr_rebind :: Ex '[I64, TVec R] R +term_arr_rebind = fromNamed $ lambda #a $ lambda #k $ body $ + let_ #n (if_ (#k .< length_ #a) #k (length_ #a)) $ + let_ #b (build1 #n (#i :-> #a ! pair nil #i)) $ + let_ #p (if_ (#n `mod_` 2 .== 1) + (pair #a #b) + (pair (map_ (#x :-> #x + 1) #a) #b)) $ + if_ (#n `mod_` 3 .== 1) + (idx0 (sum1i (snd_ #p))) + (let_ #b' (snd_ #p) $ + idx0 (sum1i #b') * idx0 (sum1i (map_ (#x :-> 2 * #x) #b'))) + +-- This simplifies away to a pointless test, but is helpful for debugging what +-- term_arr_rebind is supposed to test in a REPL +term_arr_rebind_simple :: Ex '[TVec R] R +term_arr_rebind_simple = fromNamed $ lambda #a $ body $ + let_ #b (build1 (length_ #a) (#i :-> 5 * (#a ! pair nil #i))) $ + let_ #c #b $ + let_ #d #c $ + idx0 (sum1i #d) + tests_Compile :: TestTree tests_Compile = testGroup "Compile" [compileTest "accum f64" $ fromNamed $ lambda #b $ lambda #x $ body $ @@ -517,6 +538,8 @@ tests_AD = testGroup "AD" #L ! pair (pair nil 0) 0 * #L ! pair (pair nil 0) 0)))) 42 + ,adTest "arr-rebind" term_arr_rebind + ,adTestGen "neural" Example.neural gen_neural ,adTestGen "neural-unMonoid" (unMonoid (simplifyFix Example.neural)) gen_neural |