diff options
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r-- | lib/Data/Packed/Internal/Common.hs | 58 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 19 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Signatures.hs | 54 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 19 |
4 files changed, 91 insertions, 59 deletions
diff --git a/lib/Data/Packed/Internal/Common.hs b/lib/Data/Packed/Internal/Common.hs index 879dade..629016d 100644 --- a/lib/Data/Packed/Internal/Common.hs +++ b/lib/Data/Packed/Internal/Common.hs | |||
@@ -14,25 +14,20 @@ | |||
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | -- #hide | 15 | -- #hide |
16 | 16 | ||
17 | module Data.Packed.Internal.Common where | 17 | module Data.Packed.Internal.Common( |
18 | Adapt, | ||
19 | app1, app2, app3, app4, | ||
20 | (//), check, | ||
21 | partit, common, | ||
22 | fi | ||
23 | ) where | ||
18 | 24 | ||
19 | import Foreign | 25 | import Foreign |
20 | import Complex | ||
21 | import Control.Monad(when) | 26 | import Control.Monad(when) |
22 | import Debug.Trace | ||
23 | import Foreign.C.String(peekCString) | 27 | import Foreign.C.String(peekCString) |
24 | import Foreign.C.Types | 28 | import Foreign.C.Types |
25 | import Foreign.Storable.Complex() | 29 | import Foreign.Storable.Complex() |
26 | 30 | ||
27 | |||
28 | -- | @debug x = trace (show x) x@ | ||
29 | debug :: (Show a) => a -> a | ||
30 | debug x = trace (show x) x | ||
31 | |||
32 | -- | useful for expressions like @sortBy (compare \`on\` length)@ | ||
33 | on :: (a -> a -> b) -> (t -> a) -> t -> t -> b | ||
34 | on f g = \x y -> f (g x) (g y) | ||
35 | |||
36 | -- | @partit 3 [1..9] == [[1,2,3],[4,5,6],[7,8,9]]@ | 31 | -- | @partit 3 [1..9] == [[1,2,3],[4,5,6],[7,8,9]]@ |
37 | partit :: Int -> [a] -> [[a]] | 32 | partit :: Int -> [a] -> [[a]] |
38 | partit _ [] = [] | 33 | partit _ [] = [] |
@@ -139,42 +134,3 @@ check msg f = do | |||
139 | 134 | ||
140 | -- | description of GSL error codes | 135 | -- | description of GSL error codes |
141 | foreign import ccall "auxi.h gsl_strerror" gsl_strerror :: CInt -> IO (Ptr CChar) | 136 | foreign import ccall "auxi.h gsl_strerror" gsl_strerror :: CInt -> IO (Ptr CChar) |
142 | |||
143 | --------------------------------------------------- | ||
144 | ---------- signatures of the C functions --------- | ||
145 | -------------------------------------------------- | ||
146 | type PD = Ptr Double -- | ||
147 | type PC = Ptr (Complex Double) -- | ||
148 | type TV = CInt -> PD -> IO CInt -- | ||
149 | type TVV = CInt -> PD -> TV -- | ||
150 | type TVVV = CInt -> PD -> TVV -- | ||
151 | type TM = CInt -> CInt -> PD -> IO CInt -- | ||
152 | type TMM = CInt -> CInt -> PD -> TM -- | ||
153 | type TVMM = CInt -> PD -> TMM -- | ||
154 | type TMVMM = CInt -> CInt -> PD -> TVMM -- | ||
155 | type TMMM = CInt -> CInt -> PD -> TMM -- | ||
156 | type TVM = CInt -> PD -> TM -- | ||
157 | type TVVM = CInt -> PD -> TVM -- | ||
158 | type TMV = CInt -> CInt -> PD -> TV -- | ||
159 | type TMMV = CInt -> CInt -> PD -> TMV -- | ||
160 | type TMVM = CInt -> CInt -> PD -> TVM -- | ||
161 | type TMMVM = CInt -> CInt -> PD -> TMVM -- | ||
162 | type TCM = CInt -> CInt -> PC -> IO CInt -- | ||
163 | type TCVCM = CInt -> PC -> TCM -- | ||
164 | type TCMCVCM = CInt -> CInt -> PC -> TCVCM -- | ||
165 | type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM -- | ||
166 | type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM -- | ||
167 | type TCMCM = CInt -> CInt -> PC -> TCM -- | ||
168 | type TVCM = CInt -> PD -> TCM -- | ||
169 | type TCMVCM = CInt -> CInt -> PC -> TVCM -- | ||
170 | type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM -- | ||
171 | type TCMCMCM = CInt -> CInt -> PC -> TCMCM -- | ||
172 | type TCV = CInt -> PC -> IO CInt -- | ||
173 | type TCVCV = CInt -> PC -> TCV -- | ||
174 | type TCVCVCV = CInt -> PC -> TCVCV -- | ||
175 | type TCMCV = CInt -> CInt -> PC -> TCV -- | ||
176 | type TVCV = CInt -> PD -> TCV -- | ||
177 | type TCVM = CInt -> PC -> TM -- | ||
178 | type TMCVM = CInt -> CInt -> PD -> TCVM -- | ||
179 | type TMMCVM = CInt -> CInt -> PD -> TMCVM -- | ||
180 | -------------------------------------------------- | ||
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 9dc90af..a220f1a 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -15,9 +15,26 @@ | |||
15 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
16 | -- #hide | 16 | -- #hide |
17 | 17 | ||
18 | module Data.Packed.Internal.Matrix where | 18 | module Data.Packed.Internal.Matrix( |
19 | Matrix(..), | ||
20 | MatrixOrder(..), orderOf, | ||
21 | createMatrix, withMatrix, mat, | ||
22 | cmat, fmat, | ||
23 | toLists, flatten, reshape, | ||
24 | Element(..), | ||
25 | trans, | ||
26 | fromRows, toRows, fromColumns, toColumns, | ||
27 | matrixFromVector, | ||
28 | subMatrix, | ||
29 | liftMatrix, liftMatrix2, | ||
30 | (@@>), | ||
31 | saveMatrix, | ||
32 | fromComplex, toComplex, conj, | ||
33 | singleton | ||
34 | ) where | ||
19 | 35 | ||
20 | import Data.Packed.Internal.Common | 36 | import Data.Packed.Internal.Common |
37 | import Data.Packed.Internal.Signatures | ||
21 | import Data.Packed.Internal.Vector | 38 | import Data.Packed.Internal.Vector |
22 | 39 | ||
23 | import Foreign hiding (xor) | 40 | import Foreign hiding (xor) |
diff --git a/lib/Data/Packed/Internal/Signatures.hs b/lib/Data/Packed/Internal/Signatures.hs new file mode 100644 index 0000000..67d2bfc --- /dev/null +++ b/lib/Data/Packed/Internal/Signatures.hs | |||
@@ -0,0 +1,54 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- | | ||
3 | -- Module : Data.Packed.Internal.Signatures | ||
4 | -- Copyright : (c) Alberto Ruiz 2009 | ||
5 | -- License : GPL-style | ||
6 | -- | ||
7 | -- Maintainer : Alberto Ruiz <aruiz@um.es> | ||
8 | -- Stability : provisional | ||
9 | -- Portability : portable (uses FFI) | ||
10 | -- | ||
11 | -- Signatures of the C functions. | ||
12 | -- | ||
13 | ----------------------------------------------------------------------------- | ||
14 | |||
15 | module Data.Packed.Internal.Signatures where | ||
16 | |||
17 | import Foreign | ||
18 | import Complex | ||
19 | import Foreign.C.Types | ||
20 | |||
21 | type PD = Ptr Double -- | ||
22 | type PC = Ptr (Complex Double) -- | ||
23 | type TV = CInt -> PD -> IO CInt -- | ||
24 | type TVV = CInt -> PD -> TV -- | ||
25 | type TVVV = CInt -> PD -> TVV -- | ||
26 | type TM = CInt -> CInt -> PD -> IO CInt -- | ||
27 | type TMM = CInt -> CInt -> PD -> TM -- | ||
28 | type TVMM = CInt -> PD -> TMM -- | ||
29 | type TMVMM = CInt -> CInt -> PD -> TVMM -- | ||
30 | type TMMM = CInt -> CInt -> PD -> TMM -- | ||
31 | type TVM = CInt -> PD -> TM -- | ||
32 | type TVVM = CInt -> PD -> TVM -- | ||
33 | type TMV = CInt -> CInt -> PD -> TV -- | ||
34 | type TMMV = CInt -> CInt -> PD -> TMV -- | ||
35 | type TMVM = CInt -> CInt -> PD -> TVM -- | ||
36 | type TMMVM = CInt -> CInt -> PD -> TMVM -- | ||
37 | type TCM = CInt -> CInt -> PC -> IO CInt -- | ||
38 | type TCVCM = CInt -> PC -> TCM -- | ||
39 | type TCMCVCM = CInt -> CInt -> PC -> TCVCM -- | ||
40 | type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM -- | ||
41 | type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM -- | ||
42 | type TCMCM = CInt -> CInt -> PC -> TCM -- | ||
43 | type TVCM = CInt -> PD -> TCM -- | ||
44 | type TCMVCM = CInt -> CInt -> PC -> TVCM -- | ||
45 | type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM -- | ||
46 | type TCMCMCM = CInt -> CInt -> PC -> TCMCM -- | ||
47 | type TCV = CInt -> PC -> IO CInt -- | ||
48 | type TCVCV = CInt -> PC -> TCV -- | ||
49 | type TCVCVCV = CInt -> PC -> TCVCV -- | ||
50 | type TCMCV = CInt -> CInt -> PC -> TCV -- | ||
51 | type TVCV = CInt -> PD -> TCV -- | ||
52 | type TCVM = CInt -> PC -> TM -- | ||
53 | type TMCVM = CInt -> CInt -> PD -> TCVM -- | ||
54 | type TMMCVM = CInt -> CInt -> PD -> TMCVM -- | ||
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index ac0f176..009297a 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -14,9 +14,20 @@ | |||
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | -- #hide | 15 | -- #hide |
16 | 16 | ||
17 | module Data.Packed.Internal.Vector where | 17 | module Data.Packed.Internal.Vector ( |
18 | Vector(..), | ||
19 | fromList, toList, (|>), | ||
20 | join, (@>), safe, at, at', subVector, | ||
21 | mapVector, zipVector, | ||
22 | foldVector, foldVectorG, foldLoop, | ||
23 | createVector, withVector, vec, | ||
24 | asComplex, asReal, | ||
25 | fwriteVector, freadVector, fprintfVector, fscanfVector, | ||
26 | cloneVector | ||
27 | ) where | ||
18 | 28 | ||
19 | import Data.Packed.Internal.Common | 29 | import Data.Packed.Internal.Common |
30 | import Data.Packed.Internal.Signatures | ||
20 | import Foreign | 31 | import Foreign |
21 | import Foreign.C.String | 32 | import Foreign.C.String |
22 | import Foreign.C.Types(CInt,CChar) | 33 | import Foreign.C.Types(CInt,CChar) |
@@ -194,12 +205,6 @@ asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v) } | |||
194 | 205 | ||
195 | ---------------------------------------------------------------- | 206 | ---------------------------------------------------------------- |
196 | 207 | ||
197 | liftVector f x = mapVector f x | ||
198 | |||
199 | liftVector2 f u v = zipVector f u v | ||
200 | |||
201 | ----------------------------------------------------------------- | ||
202 | |||
203 | cloneVector :: Storable t => Vector t -> IO (Vector t) | 208 | cloneVector :: Storable t => Vector t -> IO (Vector t) |
204 | cloneVector (v@V {dim=n}) = do | 209 | cloneVector (v@V {dim=n}) = do |
205 | r <- createVector n | 210 | r <- createVector n |