Skip to content

Commit

Permalink
Add reproducer for sum of {2,3} x 1 x (3 mod 4) issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsmeding committed Sep 4, 2023
1 parent 5a417b0 commit b283f88
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
-- |
-- Module : Data.Array.Accelerate.Test.NoFib.Prelude.Map
-- Copyright : [2022] The Accelerate Team
Expand Down Expand Up @@ -40,6 +41,7 @@ test_unit tc =
testGroup "unit"
[ testProperty "sum_generate_2" $ prop_sum_generate_2 tc
, testProperty "generate_2" $ prop_generate_2 tc
, tree_sum3mod4 tc
]

prop_sum_generate_2 :: TestContext -> Property
Expand Down Expand Up @@ -68,3 +70,46 @@ prop_generate_2 tc = property $ do
xs2 <- forAll (array ForInput sh f32)
let f a b = A.generate (A.constant sh) (\i -> a ! i + b ! i)
tpuTestCase tc f (P.zipWith (\a b -> a :-> b :-> Result sh) dat1 dat2) xs1 xs2

tree_sum3mod4 :: TestContext -> TestTree
tree_sum3mod4 tc =
localOption (HedgehogTestLimit (Just 1)) $
testGroup "sum3mod4" $
concat [[testDim3 2 2 2]
,[testDim3 1 1 n | n <- [1..20]]
,[testDim3 2 1 n | n <- [1..20]]
,[testDim3 3 1 n | n <- [1..20]]
,[testDim3 4 1 n | n <- [1..20]]
,[testDim3 5 1 n | n <- [1..20]]
,[testDim3 3 2 n | n <- [1..20]]
,[testDim3 1 1 n | n <- [1..20]]
,[testDim3 1 2 n | n <- [1..20]]
,[testDim3 1 3 n | n <- [1..20]]
,[testDim2 1 n | n <- [1..20]]
,[testDim2 2 n | n <- [1..20]]
,[testDim2 3 n | n <- [1..20]]
]
where
testDim2 :: Int -> Int -> TestTree
testDim2 a b =
testProperty (show a P.++ " " P.++ show b) $
prop_sum (return (Z :. a :. b)) f32

testDim3 :: Int -> Int -> Int -> TestTree
testDim3 a b c =
testProperty (show a P.++ " " P.++ show b P.++ " " P.++ show c) $
prop_sum (return (Z :. a :. b :. c)) f32

prop_sum
:: (P.Eq sh, Show sh, Shape sh, A.Num e, Show e, Similar e)
=> Gen (sh :. Int)
-> (WhichData -> Gen e)
-> Property
prop_sum dim e =
property $ do
sh@(shtail :. _) <- forAll dim
ndat <- forAll (Gen.int (Range.linear 10 16))
dat <- forAll (do arrs <- Gen.list (Range.singleton ndat) (array ForSample sh e)
return [arr :-> Result shtail | arr <- arrs])
xs <- forAll (array ForInput sh e)
tpuTestCase tc A.sum dat xs

0 comments on commit b283f88

Please sign in to comment.