summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Packed/Internal.hs2
-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
-rw-r--r--lib/Data/Packed/Vector.hs1
-rw-r--r--lib/Numeric/GSL/Minimization.hs2
-rw-r--r--lib/Numeric/GSL/Vector.hs1
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs10
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs2
10 files changed, 101 insertions, 67 deletions
diff --git a/lib/Data/Packed/Internal.hs b/lib/Data/Packed/Internal.hs
index 0bf9f8c..537e51e 100644
--- a/lib/Data/Packed/Internal.hs
+++ b/lib/Data/Packed/Internal.hs
@@ -15,10 +15,12 @@
15 15
16module Data.Packed.Internal ( 16module Data.Packed.Internal (
17 module Data.Packed.Internal.Common, 17 module Data.Packed.Internal.Common,
18 module Data.Packed.Internal.Signatures,
18 module Data.Packed.Internal.Vector, 19 module Data.Packed.Internal.Vector,
19 module Data.Packed.Internal.Matrix, 20 module Data.Packed.Internal.Matrix,
20) where 21) where
21 22
22import Data.Packed.Internal.Common 23import Data.Packed.Internal.Common
24import Data.Packed.Internal.Signatures
23import Data.Packed.Internal.Vector 25import Data.Packed.Internal.Vector
24import Data.Packed.Internal.Matrix 26import Data.Packed.Internal.Matrix
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
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index c657e10..21f51e5 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -21,7 +21,6 @@ module Data.Packed.Vector (
21 vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex, 21 vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex,
22 mapVector, zipVector, 22 mapVector, zipVector,
23 fscanfVector, fprintfVector, freadVector, fwriteVector, 23 fscanfVector, fprintfVector, freadVector, fwriteVector,
24 liftVector, liftVector2,
25 foldLoop, foldVector, foldVectorG 24 foldLoop, foldVector, foldVectorG
26) where 25) where
27 26
diff --git a/lib/Numeric/GSL/Minimization.hs b/lib/Numeric/GSL/Minimization.hs
index 930fe8a..a595da9 100644
--- a/lib/Numeric/GSL/Minimization.hs
+++ b/lib/Numeric/GSL/Minimization.hs
@@ -115,7 +115,7 @@ minimizeD method = minimizeDGen (fi (fromEnum method))
115 115
116------------------------------------------------------------------------- 116-------------------------------------------------------------------------
117 117
118 118ww2 w1 o1 w2 o2 f = w1 o1 $ \a1 -> w2 o2 $ \a2 -> f a1 a2
119 119
120minimizeGen method eps maxit sz f xi = unsafePerformIO $ do 120minimizeGen method eps maxit sz f xi = unsafePerformIO $ do
121 let xiv = fromList xi 121 let xiv = fromList xi
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs
index 92cda87..0366744 100644
--- a/lib/Numeric/GSL/Vector.hs
+++ b/lib/Numeric/GSL/Vector.hs
@@ -21,6 +21,7 @@ module Numeric.GSL.Vector (
21) where 21) where
22 22
23import Data.Packed.Internal.Common 23import Data.Packed.Internal.Common
24import Data.Packed.Internal.Signatures
24import Data.Packed.Internal.Vector 25import Data.Packed.Internal.Vector
25 26
26import Complex 27import Complex
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 110619a..f749cc1 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -310,8 +310,8 @@ pnormRV Infinity = vectorMax . vectorMapR Abs
310--pnormRV _ = error "pnormRV not yet defined" 310--pnormRV _ = error "pnormRV not yet defined"
311 311
312pnormCV PNorm2 = norm2 . asReal 312pnormCV PNorm2 = norm2 . asReal
313pnormCV PNorm1 = norm1 . liftVector magnitude 313pnormCV PNorm1 = norm1 . mapVector magnitude
314pnormCV Infinity = vectorMax . liftVector magnitude 314pnormCV Infinity = vectorMax . mapVector magnitude
315--pnormCV _ = error "pnormCV not yet defined" 315--pnormCV _ = error "pnormCV not yet defined"
316 316
317pnormRM PNorm2 m = head (toList s) where (_,s,_) = svdR m 317pnormRM PNorm2 m = head (toList s) where (_,s,_) = svdR m
@@ -320,8 +320,8 @@ pnormRM Infinity m = vectorMax $ liftMatrix (vectorMapR Abs) m `mXv` constant 1
320--pnormRM _ _ = error "p norm not yet defined" 320--pnormRM _ _ = error "p norm not yet defined"
321 321
322pnormCM PNorm2 m = head (toList s) where (_,s,_) = svdC m 322pnormCM PNorm2 m = head (toList s) where (_,s,_) = svdC m
323pnormCM PNorm1 m = vectorMax $ constant 1 (rows m) `vXm` liftMatrix (liftVector magnitude) m 323pnormCM PNorm1 m = vectorMax $ constant 1 (rows m) `vXm` liftMatrix (mapVector magnitude) m
324pnormCM Infinity m = vectorMax $ liftMatrix (liftVector magnitude) m `mXv` constant 1 (cols m) 324pnormCM Infinity m = vectorMax $ liftMatrix (mapVector magnitude) m `mXv` constant 1 (cols m)
325--pnormCM _ _ = error "p norm not yet defined" 325--pnormCM _ _ = error "p norm not yet defined"
326 326
327-- | Objects which have a p-norm. 327-- | Objects which have a p-norm.
@@ -489,7 +489,7 @@ diagonalize m = if rank v == n
489-- 489--
490matFunc :: Field t => (Complex Double -> Complex Double) -> Matrix t -> Matrix (Complex Double) 490matFunc :: Field t => (Complex Double -> Complex Double) -> Matrix t -> Matrix (Complex Double)
491matFunc f m = case diagonalize (complex m) of 491matFunc f m = case diagonalize (complex m) of
492 Just (l,v) -> v `mXm` diag (liftVector f l) `mXm` inv v 492 Just (l,v) -> v `mXm` diag (mapVector f l) `mXm` inv v
493 Nothing -> error "Sorry, matFunc requires a diagonalizable matrix" 493 Nothing -> error "Sorry, matFunc requires a diagonalizable matrix"
494 494
495-------------------------------------------------------------- 495--------------------------------------------------------------
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs
index 9bf60e2..0426bb7 100644
--- a/lib/Numeric/LinearAlgebra/Linear.hs
+++ b/lib/Numeric/LinearAlgebra/Linear.hs
@@ -55,7 +55,7 @@ instance Linear Vector (Complex Double) where
55 sub = vectorZipC Sub 55 sub = vectorZipC Sub
56 mul = vectorZipC Mul 56 mul = vectorZipC Mul
57 divide = vectorZipC Div 57 divide = vectorZipC Div
58 equal u v = dim u == dim v && vectorMax (liftVector magnitude (sub u v)) == 0.0 58 equal u v = dim u == dim v && vectorMax (mapVector magnitude (sub u v)) == 0.0
59 59
60instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where 60instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where
61 scale x = liftMatrix (scale x) 61 scale x = liftMatrix (scale x)