summaryrefslogtreecommitdiff
path: root/packages/hmatrix/src/Numeric/GSL
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-20 19:32:19 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-20 19:32:19 +0200
commit9412ef25f2a9d6f6ca233ef123a01c3f4145ffa4 (patch)
treeb5c7ecd0534d0dc34242e53a3e66b87fc2ec0b0f /packages/hmatrix/src/Numeric/GSL
parentd0fc6c7192badfa6f03baf0e02e0cf2a73c3906b (diff)
random numbers in base
Diffstat (limited to 'packages/hmatrix/src/Numeric/GSL')
-rw-r--r--packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs61
-rw-r--r--packages/hmatrix/src/Numeric/GSL/gsl-aux.c4
2 files changed, 6 insertions, 59 deletions
diff --git a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs
index 43e46c5..8bd0cc2 100644
--- a/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs
+++ b/packages/hmatrix/src/Numeric/GSL/LinearAlgebra.hs
@@ -9,15 +9,15 @@
9----------------------------------------------------------------------------- 9-----------------------------------------------------------------------------
10 10
11module Numeric.GSL.LinearAlgebra ( 11module Numeric.GSL.LinearAlgebra (
12 RandDist(..), randomVector, 12 randomVector,
13 saveMatrix, 13 saveMatrix,
14 fwriteVector, freadVector, fprintfVector, fscanfVector 14 fwriteVector, freadVector, fprintfVector, fscanfVector
15) where 15) where
16 16
17import Data.Packed 17import Data.Packed
18import Numeric.LinearAlgebra.Base(RandDist(..))
18import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) 19import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM)
19 20
20import Data.Complex
21import Foreign.Marshal.Alloc(free) 21import Foreign.Marshal.Alloc(free)
22import Foreign.Ptr(Ptr) 22import Foreign.Ptr(Ptr)
23import Foreign.C.Types 23import Foreign.C.Types
@@ -28,10 +28,6 @@ fromei x = fromIntegral (fromEnum x) :: CInt
28 28
29----------------------------------------------------------------------- 29-----------------------------------------------------------------------
30 30
31data RandDist = Uniform -- ^ uniform distribution in [0,1)
32 | Gaussian -- ^ normal distribution with mean zero and standard deviation one
33 deriving Enum
34
35-- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. 31-- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed.
36randomVector :: Int -- ^ seed 32randomVector :: Int -- ^ seed
37 -> RandDist -- ^ distribution 33 -> RandDist -- ^ distribution
@@ -39,10 +35,10 @@ randomVector :: Int -- ^ seed
39 -> Vector Double 35 -> Vector Double
40randomVector seed dist n = unsafePerformIO $ do 36randomVector seed dist n = unsafePerformIO $ do
41 r <- createVector n 37 r <- createVector n
42 app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" 38 app1 (c_random_vector_GSL (fi seed) ((fi.fromEnum) dist)) vec r "randomVectorGSL"
43 return r 39 return r
44 40
45foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV 41foreign import ccall unsafe "random_vector_GSL" c_random_vector_GSL :: CInt -> CInt -> TV
46 42
47-------------------------------------------------------------------------------- 43--------------------------------------------------------------------------------
48 44
@@ -105,56 +101,7 @@ fwriteVector filename v = do
105 101
106foreign import ccall unsafe "vector_fwrite" gsl_vector_fwrite :: Ptr CChar -> TV 102foreign import ccall unsafe "vector_fwrite" gsl_vector_fwrite :: Ptr CChar -> TV
107 103
108type PF = Ptr Float --
109type PD = Ptr Double -- 104type PD = Ptr Double --
110type PQ = Ptr (Complex Float) --
111type PC = Ptr (Complex Double) --
112type TF = CInt -> PF -> IO CInt --
113type TFF = CInt -> PF -> TF --
114type TFV = CInt -> PF -> TV --
115type TVF = CInt -> PD -> TF --
116type TFFF = CInt -> PF -> TFF --
117type TV = CInt -> PD -> IO CInt -- 105type TV = CInt -> PD -> IO CInt --
118type TVV = CInt -> PD -> TV --
119type TVVV = CInt -> PD -> TVV --
120type TFM = CInt -> CInt -> PF -> IO CInt --
121type TFMFM = CInt -> CInt -> PF -> TFM --
122type TFMFMFM = CInt -> CInt -> PF -> TFMFM --
123type TM = CInt -> CInt -> PD -> IO CInt -- 106type TM = CInt -> CInt -> PD -> IO CInt --
124type TMM = CInt -> CInt -> PD -> TM --
125type TVMM = CInt -> PD -> TMM --
126type TMVMM = CInt -> CInt -> PD -> TVMM --
127type TMMM = CInt -> CInt -> PD -> TMM --
128type TVM = CInt -> PD -> TM --
129type TVVM = CInt -> PD -> TVM --
130type TMV = CInt -> CInt -> PD -> TV --
131type TMMV = CInt -> CInt -> PD -> TMV --
132type TMVM = CInt -> CInt -> PD -> TVM --
133type TMMVM = CInt -> CInt -> PD -> TMVM --
134type TCM = CInt -> CInt -> PC -> IO CInt --
135type TCVCM = CInt -> PC -> TCM --
136type TCMCVCM = CInt -> CInt -> PC -> TCVCM --
137type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM --
138type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM --
139type TCMCM = CInt -> CInt -> PC -> TCM --
140type TVCM = CInt -> PD -> TCM --
141type TCMVCM = CInt -> CInt -> PC -> TVCM --
142type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM --
143type TCMCMCM = CInt -> CInt -> PC -> TCMCM --
144type TCV = CInt -> PC -> IO CInt --
145type TCVCV = CInt -> PC -> TCV --
146type TCVCVCV = CInt -> PC -> TCVCV --
147type TCVV = CInt -> PC -> TV --
148type TQV = CInt -> PQ -> IO CInt --
149type TQVQV = CInt -> PQ -> TQV --
150type TQVQVQV = CInt -> PQ -> TQVQV --
151type TQVF = CInt -> PQ -> TF --
152type TQM = CInt -> CInt -> PQ -> IO CInt --
153type TQMQM = CInt -> CInt -> PQ -> TQM --
154type TQMQMQM = CInt -> CInt -> PQ -> TQMQM --
155type TCMCV = CInt -> CInt -> PC -> TCV --
156type TVCV = CInt -> PD -> TCV --
157type TCVM = CInt -> PC -> TM --
158type TMCVM = CInt -> CInt -> PD -> TCVM --
159type TMMCVM = CInt -> CInt -> PD -> TMCVM --
160 107
diff --git a/packages/hmatrix/src/Numeric/GSL/gsl-aux.c b/packages/hmatrix/src/Numeric/GSL/gsl-aux.c
index 5da94ca..ffc5c20 100644
--- a/packages/hmatrix/src/Numeric/GSL/gsl-aux.c
+++ b/packages/hmatrix/src/Numeric/GSL/gsl-aux.c
@@ -924,8 +924,8 @@ int nlfit(int method, int f(int, double*, int, double*),
924 924
925#define RAN(C,F) case C: { for(k=0;k<rn;k++) { rp[k]= F(gen); }; OK } 925#define RAN(C,F) case C: { for(k=0;k<rn;k++) { rp[k]= F(gen); }; OK }
926 926
927int random_vector(int seed, int code, RVEC(r)) { 927int random_vector_GSL(int seed, int code, RVEC(r)) {
928 DEBUGMSG("random_vector") 928 DEBUGMSG("random_vector_GSL")
929 static gsl_rng * gen = NULL; 929 static gsl_rng * gen = NULL;
930 if (!gen) { gen = gsl_rng_alloc (gsl_rng_mt19937);} 930 if (!gen) { gen = gsl_rng_alloc (gsl_rng_mt19937);}
931 gsl_rng_set (gen, seed); 931 gsl_rng_set (gen, seed);