packages feed

gsl-random 0.2.3 → 0.3

raw patch · 3 files changed

+64/−14 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ GSL.Random.Dist: getLevy :: RNG -> Double -> Double -> IO (Double)
+ GSL.Random.Dist: getLevySkew :: RNG -> Double -> Double -> Double -> IO (Double)
+ GSL.Random.Gen: rngType :: String -> Maybe RNGType

Files

gsl-random.cabal view
@@ -1,5 +1,5 @@ name:            gsl-random-version:         0.2.3+version:         0.3 homepage:        http://github.com/patperry/gsl-random synopsis:        Bindings the the GSL random number generation facilities. description:
lib/GSL/Random/Dist.hs view
@@ -45,6 +45,10 @@     flatQInv,          getFlat,++    -- * The Levy alpha-Stable Distributions+    getLevy,+    getLevySkew,          -- * The Poisson Distribution     poissonPdf,@@ -253,6 +257,29 @@          foreign import ccall unsafe "gsl/gsl_randist.h"     gsl_ran_flat :: Ptr () -> CDouble -> CDouble -> IO CDouble++-- | @getLevy r c alpha@ gets a variate from the Levy symmetric stable+-- distribution with scale @c@ and exponent @alpha@.  The algorithm only+-- works for @0 <= alpha <= 2@.+getLevy :: RNG -> Double -> Double -> IO (Double)+getLevy (MkRNG f) c alpha =+    withForeignPtr f $ \p ->+        realToFrac `fmap` gsl_ran_levy p (realToFrac c) (realToFrac alpha)+        +foreign import ccall unsafe "gsl/gsl_randist.h"+    gsl_ran_levy :: Ptr () -> CDouble -> CDouble -> IO CDouble++-- | @getLevySkew r c alpha beta@ gets a variate from the Levy skew stable+-- distribution with scale @c@, exponent @alpha@, and skewness parameter+-- @beta@.  The skewness parameter must lie in the range @[-1,1]@.  The+-- algorithm only works for @0 <= alpha <= 2@.+getLevySkew :: RNG -> Double -> Double -> Double -> IO (Double)+getLevySkew (MkRNG f) c alpha beta =+    withForeignPtr f $ \p ->+        realToFrac `fmap` gsl_ran_levy_skew p (realToFrac c) (realToFrac alpha) (realToFrac beta)+        +foreign import ccall unsafe "gsl/gsl_randist.h"+    gsl_ran_levy_skew :: Ptr () -> CDouble -> CDouble -> CDouble -> IO CDouble  -- | @poissonPdf k mu@ evaluates the probability density @p(k)@ at @k@ for  -- a Poisson distribution with mean @mu@.
lib/GSL/Random/Gen/Internal.hs view
@@ -37,18 +37,15 @@      -- * Algorithms     mt19937,+    rngType,          ) where        -import Control.Monad         ( liftM )-import Data.Word             ( Word8, Word64 )-import Foreign.C.Types       ( CULong, CSize, CDouble )-import Foreign.C.String      ( CString, peekCAString )-import Foreign.ForeignPtr    ( ForeignPtr, newForeignPtr, withForeignPtr )-import Foreign.Marshal.Array ( peekArray, pokeArray )-import Foreign.Ptr           ( Ptr, FunPtr )-import Foreign.Storable      ( peek )-import System.IO.Unsafe      ( unsafePerformIO )+import Control.Monad+import Data.Maybe ( fromJust )+import Foreign+import Foreign.C.String+import Foreign.C.Types  newtype RNG     = MkRNG (ForeignPtr ()) newtype RNGType = MkRNGType (Ptr ())@@ -208,9 +205,35 @@  --------------------------- Algorithms -------------------------------------- - mt19937 :: RNGType-mt19937 = (MkRNGType . unsafePerformIO . peek) p_gsl_rng_mt19937+mt19937 = fromJust $ rngType "mt19937" -foreign import ccall unsafe "gsl/gsl_rng.h &gsl_rng_mt19937" -    p_gsl_rng_mt19937 :: Ptr (Ptr ())+rngType :: String -> Maybe RNGType+rngType str = unsafePerformIO $+    withCAString str $ \name ->+        getRngType name++getRngType :: CString -> IO (Maybe RNGType)+getRngType name =+    go gsl_rng_types_setup+    where+        go :: Ptr (Ptr ()) -> IO (Maybe RNGType)+        go types = do+            t <- peek types+            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++foreign import ccall unsafe "gsl/gsl_randist.h"+    gsl_rng_types_setup :: Ptr (Ptr ())