summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r--lib/Data/Packed/Internal/Common.hs58
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs19
-rw-r--r--lib/Data/Packed/Internal/Signatures.hs54
-rw-r--r--lib/Data/Packed/Internal/Vector.hs19
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
17module Data.Packed.Internal.Common where 17module Data.Packed.Internal.Common(
18 Adapt,
19 app1, app2, app3, app4,
20 (//), check,
21 partit, common,
22 fi
23) where
18 24
19import Foreign 25import Foreign
20import Complex
21import Control.Monad(when) 26import Control.Monad(when)
22import Debug.Trace
23import Foreign.C.String(peekCString) 27import Foreign.C.String(peekCString)
24import Foreign.C.Types 28import Foreign.C.Types
25import Foreign.Storable.Complex() 29import Foreign.Storable.Complex()
26 30
27
28-- | @debug x = trace (show x) x@
29debug :: (Show a) => a -> a
30debug x = trace (show x) x
31
32-- | useful for expressions like @sortBy (compare \`on\` length)@
33on :: (a -> a -> b) -> (t -> a) -> t -> t -> b
34on 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]]@
37partit :: Int -> [a] -> [[a]] 32partit :: Int -> [a] -> [[a]]
38partit _ [] = [] 33partit _ [] = []
@@ -139,42 +134,3 @@ check msg f = do
139 134
140-- | description of GSL error codes 135-- | description of GSL error codes
141foreign import ccall "auxi.h gsl_strerror" gsl_strerror :: CInt -> IO (Ptr CChar) 136foreign import ccall "auxi.h gsl_strerror" gsl_strerror :: CInt -> IO (Ptr CChar)
142
143---------------------------------------------------
144---------- signatures of the C functions ---------
145--------------------------------------------------
146type PD = Ptr Double --
147type PC = Ptr (Complex Double) --
148type TV = CInt -> PD -> IO CInt --
149type TVV = CInt -> PD -> TV --
150type TVVV = CInt -> PD -> TVV --
151type TM = CInt -> CInt -> PD -> IO CInt --
152type TMM = CInt -> CInt -> PD -> TM --
153type TVMM = CInt -> PD -> TMM --
154type TMVMM = CInt -> CInt -> PD -> TVMM --
155type TMMM = CInt -> CInt -> PD -> TMM --
156type TVM = CInt -> PD -> TM --
157type TVVM = CInt -> PD -> TVM --
158type TMV = CInt -> CInt -> PD -> TV --
159type TMMV = CInt -> CInt -> PD -> TMV --
160type TMVM = CInt -> CInt -> PD -> TVM --
161type TMMVM = CInt -> CInt -> PD -> TMVM --
162type TCM = CInt -> CInt -> PC -> IO CInt --
163type TCVCM = CInt -> PC -> TCM --
164type TCMCVCM = CInt -> CInt -> PC -> TCVCM --
165type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM --
166type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM --
167type TCMCM = CInt -> CInt -> PC -> TCM --
168type TVCM = CInt -> PD -> TCM --
169type TCMVCM = CInt -> CInt -> PC -> TVCM --
170type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM --
171type TCMCMCM = CInt -> CInt -> PC -> TCMCM --
172type TCV = CInt -> PC -> IO CInt --
173type TCVCV = CInt -> PC -> TCV --
174type TCVCVCV = CInt -> PC -> TCVCV --
175type TCMCV = CInt -> CInt -> PC -> TCV --
176type TVCV = CInt -> PD -> TCV --
177type TCVM = CInt -> PC -> TM --
178type TMCVM = CInt -> CInt -> PD -> TCVM --
179type 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
18module Data.Packed.Internal.Matrix where 18module 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
20import Data.Packed.Internal.Common 36import Data.Packed.Internal.Common
37import Data.Packed.Internal.Signatures
21import Data.Packed.Internal.Vector 38import Data.Packed.Internal.Vector
22 39
23import Foreign hiding (xor) 40import 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
15module Data.Packed.Internal.Signatures where
16
17import Foreign
18import Complex
19import Foreign.C.Types
20
21type PD = Ptr Double --
22type PC = Ptr (Complex Double) --
23type TV = CInt -> PD -> IO CInt --
24type TVV = CInt -> PD -> TV --
25type TVVV = CInt -> PD -> TVV --
26type TM = CInt -> CInt -> PD -> IO CInt --
27type TMM = CInt -> CInt -> PD -> TM --
28type TVMM = CInt -> PD -> TMM --
29type TMVMM = CInt -> CInt -> PD -> TVMM --
30type TMMM = CInt -> CInt -> PD -> TMM --
31type TVM = CInt -> PD -> TM --
32type TVVM = CInt -> PD -> TVM --
33type TMV = CInt -> CInt -> PD -> TV --
34type TMMV = CInt -> CInt -> PD -> TMV --
35type TMVM = CInt -> CInt -> PD -> TVM --
36type TMMVM = CInt -> CInt -> PD -> TMVM --
37type TCM = CInt -> CInt -> PC -> IO CInt --
38type TCVCM = CInt -> PC -> TCM --
39type TCMCVCM = CInt -> CInt -> PC -> TCVCM --
40type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM --
41type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM --
42type TCMCM = CInt -> CInt -> PC -> TCM --
43type TVCM = CInt -> PD -> TCM --
44type TCMVCM = CInt -> CInt -> PC -> TVCM --
45type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM --
46type TCMCMCM = CInt -> CInt -> PC -> TCMCM --
47type TCV = CInt -> PC -> IO CInt --
48type TCVCV = CInt -> PC -> TCV --
49type TCVCVCV = CInt -> PC -> TCVCV --
50type TCMCV = CInt -> CInt -> PC -> TCV --
51type TVCV = CInt -> PD -> TCV --
52type TCVM = CInt -> PC -> TM --
53type TMCVM = CInt -> CInt -> PD -> TCVM --
54type 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
17module Data.Packed.Internal.Vector where 17module 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
19import Data.Packed.Internal.Common 29import Data.Packed.Internal.Common
30import Data.Packed.Internal.Signatures
20import Foreign 31import Foreign
21import Foreign.C.String 32import Foreign.C.String
22import Foreign.C.Types(CInt,CChar) 33import 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
197liftVector f x = mapVector f x
198
199liftVector2 f u v = zipVector f u v
200
201-----------------------------------------------------------------
202
203cloneVector :: Storable t => Vector t -> IO (Vector t) 208cloneVector :: Storable t => Vector t -> IO (Vector t)
204cloneVector (v@V {dim=n}) = do 209cloneVector (v@V {dim=n}) = do
205 r <- createVector n 210 r <- createVector n