{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeFamilies #-} module Data.Array.Accelerate.Test ( randDist , the ) where import qualified Data.Array.Accelerate as A import qualified Data.Array.Accelerate.KullbackLiebler as KL import Data.Array.Accelerate.System.Random.MWC (Variate, randomArray, uniformR) -- | Doesn't actually check the list has one element the :: A.Elt e => A.Scalar e -> e the = head . A.toList -- | Make a distribution of a given size randDist :: (A.Shape sh, Fractional e, Variate e, A.Floating e, sh ~ A.DIM1) => sh -> IO (A.Acc (A.Vector e)) randDist = fmap (KL.scale . A.use) . randomArray (uniformR (0.0, 1.0))