gsl-random 0.4.3 → 0.4.4
raw patch · 5 files changed
+42/−34 lines, 5 filesdep ~vectorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: vector
API changes (from Hackage documentation)
Files
- NEWS +3/−0
- gsl-random.cabal +3/−3
- lib/GSL/Random/Dist.hs +1/−1
- lib/GSL/Random/Gen/Internal.hs +29/−26
- lib/GSL/Random/Quasi/Internal.hs +6/−4
NEWS view
@@ -1,3 +1,6 @@+Changes in 0.4.4+* Compile fixes for GHC 7.4.2+ Changes in 0.4.3 * Felipe Lessa added the multinomial distribution.
gsl-random.cabal view
@@ -1,5 +1,5 @@ name: gsl-random-version: 0.4.3+version: 0.4.4 homepage: http://github.com/patperry/hs-gsl-random synopsis: Bindings the the GSL random number generation facilities. description:@@ -16,7 +16,7 @@ maintainer: Patrick Perry <patperry@gmail.com> cabal-version: >= 1.8.0 build-type: Custom-tested-with: GHC == 6.12.3+tested-with: GHC == 7.4.2 extra-source-files: NEWS @@ -32,4 +32,4 @@ ghc-options: -Wall extensions: ForeignFunctionInterface build-depends: base >= 4 && < 5- , vector >= 0.7.0.1 && < 0.8+ , vector >= 0.7.0.1 && < 0.10
lib/GSL/Random/Dist.hs view
@@ -138,7 +138,7 @@ ) where import Control.Applicative ( (<$>) )-import Foreign.C.Types ( CUInt, CDouble, CSize )+import Foreign.C.Types ( CUInt(..), CDouble(..), CSize(..) ) import Foreign.ForeignPtr ( withForeignPtr, mallocForeignPtrArray ) import Foreign.Ptr ( Ptr ) import System.IO.Unsafe ( unsafePerformIO )
lib/GSL/Random/Gen/Internal.hs view
@@ -12,17 +12,17 @@ -- * Data types RNG(..), RNGType,- + -- * Initializing newRNG, setSeed,- + -- * Sampling getSample, getUniform, getUniformPos, getUniformInt,- + -- * Auxiliary functions getName, getMax,@@ -30,7 +30,7 @@ getSize, getState, setState,- + -- * Copying state copyRNG, cloneRNG,@@ -38,15 +38,18 @@ -- * Algorithms mt19937, rngType,- + ) where- -import Control.Monad-import Data.Maybe ( fromJust )-import Foreign-import Foreign.C.String-import Foreign.C.Types +import Control.Monad( liftM )+import Data.Maybe( fromJust )+import Foreign( ForeignPtr, FunPtr, Ptr, Word8, Word64, advancePtr, castPtr,+ peek, peekArray, pokeArray, newForeignPtr, nullPtr, withForeignPtr )+import Foreign.C.String( CString, peekCAString, withCAString )+import Foreign.C.Types( CDouble(..), CInt(..), CSize(..), CULong(..) )+import System.IO.Unsafe( unsafePerformIO )++ newtype RNG = MkRNG (ForeignPtr ()) newtype RNGType = MkRNGType (Ptr ()) @@ -75,8 +78,8 @@ foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_set :: Ptr () -> CULong -> IO ()- + --------------------------- Sampling ---------------------------------------- -- | Returns a value uniform in [rngMin, rngMax]@@ -84,7 +87,7 @@ getSample (MkRNG fptr) = withForeignPtr fptr $ \ptr -> gsl_rng_get ptr >>= return . fromInteger . toInteger- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_get :: Ptr () -> IO CULong @@ -93,7 +96,7 @@ getUniform (MkRNG fptr) = withForeignPtr fptr $ \ptr -> gsl_rng_uniform ptr >>= return . realToFrac- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_uniform :: Ptr () -> IO CDouble @@ -108,16 +111,16 @@ -- | Returns an integer uniform on [0,n-1]. @n@ must be greater than @0@. getUniformInt :: RNG -> Int -> IO Int-getUniformInt (MkRNG fptr) n +getUniformInt (MkRNG fptr) n | n <= 0 =- ioError $ userError $ + ioError $ userError $ "rngUnifInt: expected \"n\" to be greater than 0" ++ " but got `" ++ show n ++ "' instead." | otherwise = let n' = (fromInteger . toInteger) n in withForeignPtr fptr $ \ptr -> gsl_rng_uniform_int ptr n' >>= return . fromInteger . toInteger- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_uniform_int :: Ptr () -> CULong -> IO CULong @@ -129,7 +132,7 @@ getName (MkRNG fptr) = withForeignPtr fptr $ \ptr -> peekCAString (gsl_rng_name ptr)- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_name :: Ptr () -> CString @@ -138,7 +141,7 @@ getMax (MkRNG fptr) = withForeignPtr fptr $ \ptr -> (return . fromInteger . toInteger) (gsl_rng_max ptr)- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_max :: Ptr () -> CULong @@ -147,7 +150,7 @@ getMin (MkRNG fptr) = withForeignPtr fptr $ \ptr -> (return . fromInteger . toInteger) (gsl_rng_min ptr)- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_min :: Ptr () -> CULong @@ -166,7 +169,7 @@ n <- liftM (fromInteger . toInteger) (getSize rng) withForeignPtr fptr $ \ptr -> peekArray n (gsl_rng_state ptr)- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_state :: Ptr () -> Ptr Word8 @@ -186,7 +189,7 @@ withForeignPtr fdst $ \dst -> withForeignPtr fsrc $ \src -> gsl_rng_memcpy dst src- + foreign import ccall unsafe "gsl/gsl_rng.h" gsl_rng_memcpy :: Ptr () -> Ptr () -> IO () @@ -220,18 +223,18 @@ go :: Ptr (Ptr ()) -> IO (Maybe RNGType) go types = do t <- peek types- if t == nullPtr + if t == nullPtr then return Nothing- + else do name' <- peek (castPtr t) cmp <- c_strcmp name name'- + if cmp == 0 then return $ Just (MkRNGType t) else go $ types `advancePtr` 1- + foreign import ccall unsafe "string.h strcmp" c_strcmp :: CString -> CString -> IO CInt
lib/GSL/Random/Quasi/Internal.hs view
@@ -41,10 +41,12 @@ ) where -import Control.Monad-import Foreign-import Foreign.C.String-import Foreign.C.Types+import Control.Monad( liftM )+import Foreign( ForeignPtr, FunPtr, Ptr, Word8, Word64, allocaArray,+ newForeignPtr, peekArray, pokeArray, withForeignPtr )+import Foreign.C.String( CString, peekCAString )+import Foreign.C.Types( CInt(..), CSize(..), CUInt(..) )+import System.IO.Unsafe( unsafePerformIO ) newtype QRNG = MkQRNG (ForeignPtr QRNG) newtype QRNGType = MkQRNGType (Ptr QRNGType)