diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Data/Packed/Internal.hs | 2 | ||||
-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 | ||||
-rw-r--r-- | lib/Data/Packed/Vector.hs | 1 | ||||
-rw-r--r-- | lib/Numeric/GSL/Minimization.hs | 2 | ||||
-rw-r--r-- | lib/Numeric/GSL/Vector.hs | 1 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 10 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 2 |
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 | ||
16 | module Data.Packed.Internal ( | 16 | module 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 | ||
22 | import Data.Packed.Internal.Common | 23 | import Data.Packed.Internal.Common |
24 | import Data.Packed.Internal.Signatures | ||
23 | import Data.Packed.Internal.Vector | 25 | import Data.Packed.Internal.Vector |
24 | import Data.Packed.Internal.Matrix | 26 | import 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 | ||
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 |
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 | 118 | ww2 w1 o1 w2 o2 f = w1 o1 $ \a1 -> w2 o2 $ \a2 -> f a1 a2 | |
119 | 119 | ||
120 | minimizeGen method eps maxit sz f xi = unsafePerformIO $ do | 120 | minimizeGen 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 | ||
23 | import Data.Packed.Internal.Common | 23 | import Data.Packed.Internal.Common |
24 | import Data.Packed.Internal.Signatures | ||
24 | import Data.Packed.Internal.Vector | 25 | import Data.Packed.Internal.Vector |
25 | 26 | ||
26 | import Complex | 27 | import 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 | ||
312 | pnormCV PNorm2 = norm2 . asReal | 312 | pnormCV PNorm2 = norm2 . asReal |
313 | pnormCV PNorm1 = norm1 . liftVector magnitude | 313 | pnormCV PNorm1 = norm1 . mapVector magnitude |
314 | pnormCV Infinity = vectorMax . liftVector magnitude | 314 | pnormCV Infinity = vectorMax . mapVector magnitude |
315 | --pnormCV _ = error "pnormCV not yet defined" | 315 | --pnormCV _ = error "pnormCV not yet defined" |
316 | 316 | ||
317 | pnormRM PNorm2 m = head (toList s) where (_,s,_) = svdR m | 317 | pnormRM 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 | ||
322 | pnormCM PNorm2 m = head (toList s) where (_,s,_) = svdC m | 322 | pnormCM PNorm2 m = head (toList s) where (_,s,_) = svdC m |
323 | pnormCM PNorm1 m = vectorMax $ constant 1 (rows m) `vXm` liftMatrix (liftVector magnitude) m | 323 | pnormCM PNorm1 m = vectorMax $ constant 1 (rows m) `vXm` liftMatrix (mapVector magnitude) m |
324 | pnormCM Infinity m = vectorMax $ liftMatrix (liftVector magnitude) m `mXv` constant 1 (cols m) | 324 | pnormCM 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 | -- |
490 | matFunc :: Field t => (Complex Double -> Complex Double) -> Matrix t -> Matrix (Complex Double) | 490 | matFunc :: Field t => (Complex Double -> Complex Double) -> Matrix t -> Matrix (Complex Double) |
491 | matFunc f m = case diagonalize (complex m) of | 491 | matFunc 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 | ||
60 | instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where | 60 | instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where |
61 | scale x = liftMatrix (scale x) | 61 | scale x = liftMatrix (scale x) |