mwc-random-accelerate (empty) → 0.1.0.0
raw patch · 4 files changed
+177/−0 lines, 4 filesdep +acceleratedep +basedep +mwc-randomsetup-changed
Dependencies added: accelerate, base, mwc-random
Files
- Data/Array/Accelerate/System/Random/MWC.hs +103/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- mwc-random-accelerate.cabal +42/−0
+ Data/Array/Accelerate/System/Random/MWC.hs view
@@ -0,0 +1,103 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE TypeOperators #-}+-- |+-- Module: : Data.Array.Accelerate.System.Random.MWC+-- Copyright : [2014..2015] Trevor L. McDonell+-- License : BSD3+--+-- Maintainer : Trevor L. McDonell <tmcdonell@cse.unsw.edu.au>+-- Stability : experimental+-- Portability : non-portable (GHC extensions)+--+-- Random number generation backed by MWC.+--++module Data.Array.Accelerate.System.Random.MWC (++ -- * Generating random arrays+ (:~>),+ uniform, uniformR,+ randomArray, randomArrayWith,++ -- * Re-export MWC-Random+ module System.Random.MWC,++) where++import Prelude as P+import System.Random.MWC hiding ( uniform, uniformR )+import qualified System.Random.MWC as R++import Data.Array.Accelerate as A+import Data.Array.Accelerate.Array.Data as A+import Data.Array.Accelerate.Array.Sugar as Sugar+++-- | A PRNG from indices to variates+--+type sh :~> e = sh -> GenIO -> IO e+++-- | Uniformly distributed random variates.+--+{-# INLINE uniform #-}+uniform :: (Shape sh, Elt e, Variate e) => sh :~> e+uniform _ = R.uniform++-- | Uniformly distributed random variates in a given range.+--+{-# INLINE uniformR #-}+uniformR :: (Shape sh, Elt e, Variate e) => (e, e) -> sh :~> e+uniformR bounds _ = R.uniformR bounds+++-- | Generate an array of random values. The generator for variates is+-- seeded from the system's fast source of pseudo-random numbers (see:+-- 'R.createSystemRandom')+--+{-# INLINE randomArray #-}+randomArray :: (Shape sh, Elt e) => sh :~> e -> sh -> IO (Array sh e)+randomArray f sh+ = do+ gen <- createSystemRandom+ randomArrayWith gen f sh+++-- | Generate an array of random values using the supplied generator.+--+{-# INLINE randomArrayWith #-}+randomArrayWith+ :: (Shape sh, Elt e)+ => GenIO+ -> sh :~> e+ -> sh+ -> IO (Array sh e)+randomArrayWith gen f sh+ = do+ adata <- runRandomArray f sh gen+ return $! Array (fromElt sh) adata+++-- Create a mutable array and fill it with random values+--+{-# INLINE runRandomArray #-}+runRandomArray+ :: (Shape sh, Elt e)+ => sh :~> e+ -> sh+ -> GenIO+ -> IO (MutableArrayData (EltRepr e))+runRandomArray f sh gen+ = do+ arr <- newArrayData $! Sugar.size sh+ let !n = Sugar.size sh+ write !i+ | i P.>= n = return ()+ | otherwise = do+ unsafeWriteArrayData arr i . fromElt =<< f (Sugar.fromIndex sh i) gen+ write (i+1)+ --+ write 0+ return arr+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Trevor L. McDonell++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Trevor L. McDonell nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ mwc-random-accelerate.cabal view
@@ -0,0 +1,42 @@+name: mwc-random-accelerate+version: 0.1.0.0+synopsis: Generate Accelerate arrays filled with high quality pseudorandom numbers+description:+ Generate /Accelerate/ arrays filled with high-quality pseudorandom numbers.+ .+ Refer to the main /Accelerate/ package for more information:+ <http://hackage.haskell.org/package/accelerate>+ .+tested-with: GHC >= 7.8++license: BSD3+license-file: LICENSE+author: Trevor L. McDonell+maintainer: Trevor L. McDonell <tmcdonell@cse.unsw.edu.au>+-- copyright:+category: Data+build-type: Simple+-- extra-source-files:+cabal-version: >=1.10++library+ default-language: Haskell2010+ exposed-modules:+ Data.Array.Accelerate.System.Random.MWC++ build-depends:+ base >= 4.7 && < 4.10+ , accelerate >= 0.15+ , mwc-random >= 0.8++ ghc-options: -O2 -Wall++Source-repository head+ Type: git+ Location: git://github.com/tmcdonell/mwc-random-accelerate.git++Source-repository this+ Type: git+ Tag: 0.1.0.0+ Location: git://github.com/tmcdonell/mwc-random-accelerate.git+