packages feed

mwc-random 0.8.0.5 → 0.9.0.0

raw patch · 2 files changed

+18/−27 lines, 2 filesdep ~vectorPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: vector

API changes (from Hackage documentation)

- System.Random.MWC: initialize :: PrimMonad m => Vector Word32 -> m (Gen (PrimState m))
+ System.Random.MWC: initialize :: (PrimMonad m, Vector v Word32) => v Word32 -> m (Gen (PrimState m))
- System.Random.MWC: uniformVector :: (PrimMonad m, Variate a) => Gen (PrimState m) -> Int -> m (Vector a)
+ System.Random.MWC: uniformVector :: (PrimMonad m, Variate a, Vector v a) => Gen (PrimState m) -> Int -> m (v a)

Files

System/Random/MWC.hs view
@@ -48,7 +48,7 @@ import Control.Monad           (ap, liftM, unless) import Control.Monad.Primitive (PrimMonad, PrimState, unsafePrimToIO) import Control.Monad.ST        (ST)-import Data.Bits               ((.&.), (.|.), xor)+import Data.Bits               (Bits, (.&.), (.|.), shiftL, shiftR, xor) import Data.Int                (Int8, Int16, Int32, Int64) import Data.IORef              (atomicModifyIORef, newIORef) import Data.Ratio              ((%), numerator)@@ -58,8 +58,6 @@ import Data.Word               (Word, Word8, Word16, Word32, Word64) import Foreign.Marshal.Alloc   (allocaBytes) import Foreign.Marshal.Array   (peekArray)-import GHC.Base       (Int(I#))-import GHC.Word       (Word64(W64#), uncheckedShiftL64#, uncheckedShiftRL64#) import Prelude hiding (catch) import qualified Data.Vector.Generic         as G import qualified Data.Vector.Generic.Mutable as GM@@ -231,9 +229,9 @@     {-# INLINE uniform  #-}     {-# INLINE uniformR #-} -wordsTo64Bit :: Integral a => Word32 -> Word32 -> a+wordsTo64Bit :: (Integral a) => Word32 -> Word32 -> a wordsTo64Bit x y =-    fromIntegral ((fromIntegral x `shiftL` 32) .|. fromIntegral y)+    fromIntegral ((fromIntegral x `shiftL` 32) .|. fromIntegral y :: Word64) {-# INLINE wordsTo64Bit #-}  wordToBool :: Word32 -> Bool@@ -282,14 +280,15 @@ -- -- Examples: ----- > initialize (singletonU 42)+-- > initialize (singleton 42) ----- > initialize (toU [4, 8, 15, 16, 23, 42])+-- > initialize (toList [4, 8, 15, 16, 23, 42]) -- -- If a seed contains fewer than 256 elements, it is first used -- verbatim, then its elements are 'xor'ed against elements of the -- default seed until 256 elements are reached.-initialize :: PrimMonad m => I.Vector Word32 -> m (Gen (PrimState m))+initialize :: (PrimMonad m, Vector v Word32) =>+              v Word32 -> m (Gen (PrimState m)) initialize seed = do     q <- M.unsafeNew 258     fill q@@ -300,11 +299,11 @@           go i | i == 256  = return ()                | otherwise = M.unsafeWrite q i s >> go (i+1)             where s | i >= fini = if fini == 0-                                  then I.unsafeIndex defaultSeed i-                                  else I.unsafeIndex defaultSeed i `xor`-                                       I.unsafeIndex seed (i `mod` fini)-                    | otherwise = I.unsafeIndex seed i-        fini = I.length seed+                                  then G.unsafeIndex defaultSeed i+                                  else G.unsafeIndex defaultSeed i `xor`+                                       G.unsafeIndex seed (i `mod` fini)+                    | otherwise = G.unsafeIndex seed i+        fini = G.length seed {-# INLINE initialize #-}                                 -- | An immutable snapshot of the state of a 'Gen'.@@ -373,14 +372,6 @@         warned = unsafePerformIO $ newIORef False         {-# NOINLINE warned #-} --- | Unchecked 64-bit left shift.-shiftL :: Word64 -> Int -> Word64-shiftL (W64# x#) (I# i#) = W64# (x# `uncheckedShiftL64#` i#)---- | Unchecked 64-bit right shift.-shiftR :: Word64 -> Int -> Word64-shiftR (W64# x#) (I# i#) = W64# (x# `uncheckedShiftRL64#` i#)- -- | Compute the next index into the state pool.  This is simply -- addition modulo 256. nextIndex :: Integral a => a -> Int@@ -489,11 +480,11 @@ -- | Generate a vector of pseudo-random variates.  This is not -- necessarily faster than invoking 'uniform' repeatedly in a loop, -- but it may be more convenient to use in some situations.-uniformVector :: (PrimMonad m, Variate a)-             => Gen (PrimState m) -> Int -> m (I.Vector a)+uniformVector :: (PrimMonad m, Variate a, Vector v a)+             => Gen (PrimState m) -> Int -> m (v a) uniformVector gen n = do-  mu <- M.unsafeNew n-  let go !i | i < n     = uniform gen >>= M.unsafeWrite mu i >> go (i+1)+  mu <- GM.unsafeNew n+  let go !i | i < n     = uniform gen >>= GM.unsafeWrite mu i >> go (i+1)             | otherwise = unsafeFreeze mu   go 0 {-# INLINE uniformVector #-}
mwc-random.cabal view
@@ -1,5 +1,5 @@ name:           mwc-random-version:        0.8.0.5+version:        0.9.0.0 synopsis:       Fast, high quality pseudo random number generation description:   This package contains code for generating high quality random@@ -37,7 +37,7 @@     base < 5,     primitive,     time,-    vector >= 0.5+    vector >= 0.6.0.2   if impl(ghc >= 6.10)     build-depends:       base >= 4