diff options
Diffstat (limited to 'packages/hmatrix/src/Numeric/GSL/Vector.hs')
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/Vector.hs | 162 |
1 files changed, 0 insertions, 162 deletions
diff --git a/packages/hmatrix/src/Numeric/GSL/Vector.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs deleted file mode 100644 index bca074f..0000000 --- a/packages/hmatrix/src/Numeric/GSL/Vector.hs +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- | | ||
3 | -- Module : Numeric.GSL.Vector | ||
4 | -- Copyright : (c) Alberto Ruiz 2007 | ||
5 | -- License : GPL | ||
6 | -- Maintainer : Alberto Ruiz | ||
7 | -- Stability : provisional | ||
8 | -- | ||
9 | -- Low level interface to vector operations. | ||
10 | -- | ||
11 | ----------------------------------------------------------------------------- | ||
12 | |||
13 | module Numeric.GSL.Vector ( | ||
14 | RandDist(..), randomVector, | ||
15 | saveMatrix, | ||
16 | fwriteVector, freadVector, fprintfVector, fscanfVector | ||
17 | ) where | ||
18 | |||
19 | import Data.Packed | ||
20 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | ||
21 | |||
22 | import Data.Complex | ||
23 | import Foreign.Marshal.Alloc(free) | ||
24 | import Foreign.Ptr(Ptr) | ||
25 | import Foreign.C.Types | ||
26 | import Foreign.C.String(newCString) | ||
27 | import System.IO.Unsafe(unsafePerformIO) | ||
28 | |||
29 | fromei x = fromIntegral (fromEnum x) :: CInt | ||
30 | |||
31 | ----------------------------------------------------------------------- | ||
32 | |||
33 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | ||
34 | | Gaussian -- ^ normal distribution with mean zero and standard deviation one | ||
35 | deriving Enum | ||
36 | |||
37 | -- | Obtains a vector of pseudorandom elements from the the mt19937 generator in GSL, with a given seed. Use randomIO to get a random seed. | ||
38 | randomVector :: Int -- ^ seed | ||
39 | -> RandDist -- ^ distribution | ||
40 | -> Int -- ^ vector size | ||
41 | -> Vector Double | ||
42 | randomVector seed dist n = unsafePerformIO $ do | ||
43 | r <- createVector n | ||
44 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" | ||
45 | return r | ||
46 | |||
47 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV | ||
48 | |||
49 | -------------------------------------------------------------------------------- | ||
50 | |||
51 | -- | Saves a matrix as 2D ASCII table. | ||
52 | saveMatrix :: FilePath | ||
53 | -> String -- ^ format (%f, %g, %e) | ||
54 | -> Matrix Double | ||
55 | -> IO () | ||
56 | saveMatrix filename fmt m = do | ||
57 | charname <- newCString filename | ||
58 | charfmt <- newCString fmt | ||
59 | let o = if orderOf m == RowMajor then 1 else 0 | ||
60 | app1 (matrix_fprintf charname charfmt o) mat m "matrix_fprintf" | ||
61 | free charname | ||
62 | free charfmt | ||
63 | |||
64 | foreign import ccall unsafe "matrix_fprintf" matrix_fprintf :: Ptr CChar -> Ptr CChar -> CInt -> TM | ||
65 | |||
66 | -------------------------------------------------------------------------------- | ||
67 | |||
68 | -- | Loads a vector from an ASCII file (the number of elements must be known in advance). | ||
69 | fscanfVector :: FilePath -> Int -> IO (Vector Double) | ||
70 | fscanfVector filename n = do | ||
71 | charname <- newCString filename | ||
72 | res <- createVector n | ||
73 | app1 (gsl_vector_fscanf charname) vec res "gsl_vector_fscanf" | ||
74 | free charname | ||
75 | return res | ||
76 | |||
77 | foreign import ccall unsafe "vector_fscanf" gsl_vector_fscanf:: Ptr CChar -> TV | ||
78 | |||
79 | -- | Saves the elements of a vector, with a given format (%f, %e, %g), to an ASCII file. | ||
80 | fprintfVector :: FilePath -> String -> Vector Double -> IO () | ||
81 | fprintfVector filename fmt v = do | ||
82 | charname <- newCString filename | ||
83 | charfmt <- newCString fmt | ||
84 | app1 (gsl_vector_fprintf charname charfmt) vec v "gsl_vector_fprintf" | ||
85 | free charname | ||
86 | free charfmt | ||
87 | |||
88 | foreign import ccall unsafe "vector_fprintf" gsl_vector_fprintf :: Ptr CChar -> Ptr CChar -> TV | ||
89 | |||
90 | -- | Loads a vector from a binary file (the number of elements must be known in advance). | ||
91 | freadVector :: FilePath -> Int -> IO (Vector Double) | ||
92 | freadVector filename n = do | ||
93 | charname <- newCString filename | ||
94 | res <- createVector n | ||
95 | app1 (gsl_vector_fread charname) vec res "gsl_vector_fread" | ||
96 | free charname | ||
97 | return res | ||
98 | |||
99 | foreign import ccall unsafe "vector_fread" gsl_vector_fread:: Ptr CChar -> TV | ||
100 | |||
101 | -- | Saves the elements of a vector to a binary file. | ||
102 | fwriteVector :: FilePath -> Vector Double -> IO () | ||
103 | fwriteVector filename v = do | ||
104 | charname <- newCString filename | ||
105 | app1 (gsl_vector_fwrite charname) vec v "gsl_vector_fwrite" | ||
106 | free charname | ||
107 | |||
108 | foreign import ccall unsafe "vector_fwrite" gsl_vector_fwrite :: Ptr CChar -> TV | ||
109 | |||
110 | type PF = Ptr Float -- | ||
111 | type PD = Ptr Double -- | ||
112 | type PQ = Ptr (Complex Float) -- | ||
113 | type PC = Ptr (Complex Double) -- | ||
114 | type TF = CInt -> PF -> IO CInt -- | ||
115 | type TFF = CInt -> PF -> TF -- | ||
116 | type TFV = CInt -> PF -> TV -- | ||
117 | type TVF = CInt -> PD -> TF -- | ||
118 | type TFFF = CInt -> PF -> TFF -- | ||
119 | type TV = CInt -> PD -> IO CInt -- | ||
120 | type TVV = CInt -> PD -> TV -- | ||
121 | type TVVV = CInt -> PD -> TVV -- | ||
122 | type TFM = CInt -> CInt -> PF -> IO CInt -- | ||
123 | type TFMFM = CInt -> CInt -> PF -> TFM -- | ||
124 | type TFMFMFM = CInt -> CInt -> PF -> TFMFM -- | ||
125 | type TM = CInt -> CInt -> PD -> IO CInt -- | ||
126 | type TMM = CInt -> CInt -> PD -> TM -- | ||
127 | type TVMM = CInt -> PD -> TMM -- | ||
128 | type TMVMM = CInt -> CInt -> PD -> TVMM -- | ||
129 | type TMMM = CInt -> CInt -> PD -> TMM -- | ||
130 | type TVM = CInt -> PD -> TM -- | ||
131 | type TVVM = CInt -> PD -> TVM -- | ||
132 | type TMV = CInt -> CInt -> PD -> TV -- | ||
133 | type TMMV = CInt -> CInt -> PD -> TMV -- | ||
134 | type TMVM = CInt -> CInt -> PD -> TVM -- | ||
135 | type TMMVM = CInt -> CInt -> PD -> TMVM -- | ||
136 | type TCM = CInt -> CInt -> PC -> IO CInt -- | ||
137 | type TCVCM = CInt -> PC -> TCM -- | ||
138 | type TCMCVCM = CInt -> CInt -> PC -> TCVCM -- | ||
139 | type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM -- | ||
140 | type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM -- | ||
141 | type TCMCM = CInt -> CInt -> PC -> TCM -- | ||
142 | type TVCM = CInt -> PD -> TCM -- | ||
143 | type TCMVCM = CInt -> CInt -> PC -> TVCM -- | ||
144 | type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM -- | ||
145 | type TCMCMCM = CInt -> CInt -> PC -> TCMCM -- | ||
146 | type TCV = CInt -> PC -> IO CInt -- | ||
147 | type TCVCV = CInt -> PC -> TCV -- | ||
148 | type TCVCVCV = CInt -> PC -> TCVCV -- | ||
149 | type TCVV = CInt -> PC -> TV -- | ||
150 | type TQV = CInt -> PQ -> IO CInt -- | ||
151 | type TQVQV = CInt -> PQ -> TQV -- | ||
152 | type TQVQVQV = CInt -> PQ -> TQVQV -- | ||
153 | type TQVF = CInt -> PQ -> TF -- | ||
154 | type TQM = CInt -> CInt -> PQ -> IO CInt -- | ||
155 | type TQMQM = CInt -> CInt -> PQ -> TQM -- | ||
156 | type TQMQMQM = CInt -> CInt -> PQ -> TQMQM -- | ||
157 | type TCMCV = CInt -> CInt -> PC -> TCV -- | ||
158 | type TVCV = CInt -> PD -> TCV -- | ||
159 | type TCVM = CInt -> PC -> TM -- | ||
160 | type TMCVM = CInt -> CInt -> PD -> TCVM -- | ||
161 | type TMMCVM = CInt -> CInt -> PD -> TMCVM -- | ||
162 | |||