module Data.Array.Repa.Arbitrary
(
arbitraryUShaped
, forAllUShaped
, forAll2UShaped
, forAll3UShaped
, forAll4UShaped
, forAll5UShaped
, arbitraryVShaped
, forAllVShaped
, forAll2VShaped
, forAll3VShaped
, forAll4VShaped
, forAll5VShaped)
where
import Data.Array.Repa.Base
import Data.Array.Repa.Repr.Unboxed
import Data.Array.Repa.Shape
import Data.Array.Repa.Index
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Gen
import Test.QuickCheck.Property (forAll)
import Control.Monad
import qualified Data.Array.Repa.Repr.Vector as V
import qualified Data.Vector.Unboxed as U
instance Arbitrary Z where
arbitrary = return Z
instance Arbitrary a
=> Arbitrary (a :. Int) where
arbitrary
= sized (\n -> do
b <- choose (1, n)
let dimLimit :: Int = ceiling (fromIntegral n / fromIntegral b :: Double)
a <- resize dimLimit arbitrary
return $ a :. b)
arbitraryUShaped sh = fromListUnboxed sh `fmap` vector (size sh)
arbitraryVShaped sh = V.fromListVector sh `fmap` vector (size sh)
instance (Arbitrary sh, Arbitrary a, U.Unbox a, Shape sh)
=> Arbitrary (Array U sh a) where
arbitrary = arbitrary >>= arbitraryUShaped
instance (Arbitrary sh, Arbitrary a, Shape sh)
=> Arbitrary (Array V.V sh a) where
arbitrary = arbitrary >>= arbitraryVShaped
instance CoArbitrary Z where
coarbitrary _ = id
instance (CoArbitrary a)
=> CoArbitrary (a :. Int) where
coarbitrary (a :. b) = coarbitrary a . coarbitrary b
instance (CoArbitrary sh, CoArbitrary a, Source r a, Shape sh)
=> CoArbitrary (Array r sh a) where
coarbitrary arr
= (coarbitrary . extent $ arr) . (coarbitrary . toList $ arr)
forAll2 arbf = forAll $ liftM2 (,) arbf arbf
forAll3 arbf = forAll $ liftM3 (,,) arbf arbf arbf
forAll4 arbf = forAll $ liftM4 (,,,) arbf arbf arbf arbf
forAll5 arbf = forAll $ liftM5 (,,,,) arbf arbf arbf arbf arbf
forAllUShaped sh = forAll $ arbitraryUShaped sh
forAll2UShaped sh = forAll2 $ arbitraryUShaped sh
forAll3UShaped sh = forAll3 $ arbitraryUShaped sh
forAll4UShaped sh = forAll4 $ arbitraryUShaped sh
forAll5UShaped sh = forAll5 $ arbitraryUShaped sh
forAllVShaped sh = forAll $ arbitraryVShaped sh
forAll2VShaped sh = forAll2 $ arbitraryVShaped sh
forAll3VShaped sh = forAll3 $ arbitraryVShaped sh
forAll4VShaped sh = forAll4 $ arbitraryVShaped sh
forAll5VShaped sh = forAll5 $ arbitraryVShaped sh