diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-08 13:43:07 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-08 13:43:07 +0200 |
commit | 551cf7498c33bc0948bb4cb8444ae6f8af7278ea (patch) | |
tree | ec86ff73151746f5e13b83549ea5c60ed442764d /packages | |
parent | 561a6c0e21bb77c21114ccbbd86d3af5ddb5a3f1 (diff) |
separation ok
Diffstat (limited to 'packages')
24 files changed, 272 insertions, 146 deletions
diff --git a/packages/base/hmatrix-base.cabal b/packages/base/hmatrix-base.cabal index 0413d4a..bd356df 100644 --- a/packages/base/hmatrix-base.cabal +++ b/packages/base/hmatrix-base.cabal | |||
@@ -7,7 +7,8 @@ Maintainer: Alberto Ruiz | |||
7 | Stability: provisional | 7 | Stability: provisional |
8 | Homepage: https://github.com/albertoruiz/hmatrix | 8 | Homepage: https://github.com/albertoruiz/hmatrix |
9 | Synopsis: Numeric Linear Algebra | 9 | Synopsis: Numeric Linear Algebra |
10 | Description: Numeric Linear Algebra | 10 | Description: Basic support for dense linear algebra |
11 | internally implemented using BLAS and LAPACK. | ||
11 | Category: Math | 12 | Category: Math |
12 | tested-with: GHC==7.8 | 13 | tested-with: GHC==7.8 |
13 | 14 | ||
@@ -35,7 +36,7 @@ library | |||
35 | Data.Packed.ST, | 36 | Data.Packed.ST, |
36 | Data.Packed.Development, | 37 | Data.Packed.Development, |
37 | Numeric.Conversion | 38 | Numeric.Conversion |
38 | Numeric.LAPACK | 39 | Numeric.LinearAlgebra.LAPACK |
39 | 40 | ||
40 | other-modules: Data.Packed.Internal, | 41 | other-modules: Data.Packed.Internal, |
41 | Data.Packed.Internal.Common, | 42 | Data.Packed.Internal.Common, |
@@ -52,7 +53,6 @@ library | |||
52 | ghc-options: -Wall | 53 | ghc-options: -Wall |
53 | -fno-warn-missing-signatures | 54 | -fno-warn-missing-signatures |
54 | -fno-warn-orphans | 55 | -fno-warn-orphans |
55 | -- -fno-warn-unused-binds | ||
56 | 56 | ||
57 | cc-options: -O4 -msse2 -Wall | 57 | cc-options: -O4 -msse2 -Wall |
58 | 58 | ||
diff --git a/packages/base/src/Data/Packed/Development.hs b/packages/base/src/Data/Packed/Development.hs index 9350acb..6dfd551 100644 --- a/packages/base/src/Data/Packed/Development.hs +++ b/packages/base/src/Data/Packed/Development.hs | |||
@@ -24,7 +24,8 @@ module Data.Packed.Development ( | |||
24 | unsafeFromForeignPtr, | 24 | unsafeFromForeignPtr, |
25 | unsafeToForeignPtr, | 25 | unsafeToForeignPtr, |
26 | check, (//), | 26 | check, (//), |
27 | at', atM', fi, table | 27 | at', atM', fi, table, |
28 | conformMs, conformVs, shSize, splitEvery | ||
28 | ) where | 29 | ) where |
29 | 30 | ||
30 | import Data.Packed.Internal | 31 | import Data.Packed.Internal |
diff --git a/packages/base/src/Data/Packed/Vector.hs b/packages/base/src/Data/Packed/Vector.hs index 653a257..a8f6bb1 100644 --- a/packages/base/src/Data/Packed/Vector.hs +++ b/packages/base/src/Data/Packed/Vector.hs | |||
@@ -23,7 +23,8 @@ module Data.Packed.Vector ( | |||
23 | subVector, takesV, vjoin, join, | 23 | subVector, takesV, vjoin, join, |
24 | mapVector, mapVectorWithIndex, zipVector, zipVectorWith, unzipVector, unzipVectorWith, | 24 | mapVector, mapVectorWithIndex, zipVector, zipVectorWith, unzipVector, unzipVectorWith, |
25 | mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, | 25 | mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, |
26 | foldLoop, foldVector, foldVectorG, foldVectorWithIndex | 26 | foldLoop, foldVector, foldVectorG, foldVectorWithIndex, |
27 | stepD, stepF, condD, condF, conjugateC, conjugateQ | ||
27 | ) where | 28 | ) where |
28 | 29 | ||
29 | import Data.Packed.Internal.Vector | 30 | import Data.Packed.Internal.Vector |
diff --git a/packages/base/src/Numeric/LAPACK.hs b/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs index 08cd759..af0c744 100644 --- a/packages/base/src/Numeric/LAPACK.hs +++ b/packages/base/src/Numeric/LinearAlgebra/LAPACK.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.LAPACK | 3 | -- Module : Numeric.LinearAlgebra.LAPACK |
4 | -- Copyright : (c) Alberto Ruiz 2006-14 | 4 | -- Copyright : (c) Alberto Ruiz 2006-14 |
5 | -- License : BSD3 | 5 | -- License : BSD3 |
6 | -- | 6 | -- |
@@ -11,7 +11,7 @@ | |||
11 | -- | 11 | -- |
12 | ----------------------------------------------------------------------------- | 12 | ----------------------------------------------------------------------------- |
13 | 13 | ||
14 | module Numeric.LAPACK ( | 14 | module Numeric.LinearAlgebra.LAPACK ( |
15 | -- * Matrix product | 15 | -- * Matrix product |
16 | multiplyR, multiplyC, multiplyF, multiplyQ, | 16 | multiplyR, multiplyC, multiplyF, multiplyQ, |
17 | -- * Linear systems | 17 | -- * Linear systems |
diff --git a/packages/glpk/hmatrix-glpk.cabal b/packages/glpk/hmatrix-glpk.cabal index b770cfa..96f53eb 100644 --- a/packages/glpk/hmatrix-glpk.cabal +++ b/packages/glpk/hmatrix-glpk.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix-glpk | 1 | Name: hmatrix-glpk |
2 | Version: 0.3.1 | 2 | Version: 0.4.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -22,7 +22,7 @@ extra-source-files: examples/simplex1.hs | |||
22 | examples/simplex4.hs | 22 | examples/simplex4.hs |
23 | 23 | ||
24 | library | 24 | library |
25 | Build-Depends: base >= 3 && < 5, hmatrix >= 0.8.3 | 25 | Build-Depends: base, hmatrix-base |
26 | 26 | ||
27 | hs-source-dirs: lib | 27 | hs-source-dirs: lib |
28 | 28 | ||
diff --git a/packages/glpk/lib/Numeric/LinearProgramming.hs b/packages/glpk/lib/Numeric/LinearProgramming.hs index 6a3e186..25cdab2 100644 --- a/packages/glpk/lib/Numeric/LinearProgramming.hs +++ b/packages/glpk/lib/Numeric/LinearProgramming.hs | |||
@@ -5,7 +5,7 @@ Module : Numeric.LinearProgramming | |||
5 | Copyright : (c) Alberto Ruiz 2010 | 5 | Copyright : (c) Alberto Ruiz 2010 |
6 | License : GPL | 6 | License : GPL |
7 | 7 | ||
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 8 | Maintainer : Alberto Ruiz |
9 | Stability : provisional | 9 | Stability : provisional |
10 | 10 | ||
11 | This module provides an interface to the standard simplex algorithm. | 11 | This module provides an interface to the standard simplex algorithm. |
@@ -67,7 +67,7 @@ module Numeric.LinearProgramming( | |||
67 | Solution(..) | 67 | Solution(..) |
68 | ) where | 68 | ) where |
69 | 69 | ||
70 | import Numeric.LinearAlgebra hiding (i) | 70 | import Data.Packed |
71 | import Data.Packed.Development | 71 | import Data.Packed.Development |
72 | import Foreign(Ptr) | 72 | import Foreign(Ptr) |
73 | import System.IO.Unsafe(unsafePerformIO) | 73 | import System.IO.Unsafe(unsafePerformIO) |
@@ -224,7 +224,6 @@ foreign import ccall unsafe "c_simplex_sparse" c_simplex_sparse | |||
224 | simplexSparse :: Int -> Int -> Matrix Double -> Matrix Double -> Vector Double | 224 | simplexSparse :: Int -> Int -> Matrix Double -> Matrix Double -> Vector Double |
225 | simplexSparse m n c b = unsafePerformIO $ do | 225 | simplexSparse m n c b = unsafePerformIO $ do |
226 | s <- createVector (2+n) | 226 | s <- createVector (2+n) |
227 | let fi = fromIntegral | ||
228 | app3 (c_simplex_sparse (fi m) (fi n)) mat (cmat c) mat (cmat b) vec s "c_simplex_sparse" | 227 | app3 (c_simplex_sparse (fi m) (fi n)) mat (cmat c) mat (cmat b) vec s "c_simplex_sparse" |
229 | return s | 228 | return s |
230 | 229 | ||
diff --git a/packages/hmatrix/hmatrix.cabal b/packages/hmatrix/hmatrix.cabal index afd678f..8496663 100644 --- a/packages/hmatrix/hmatrix.cabal +++ b/packages/hmatrix/hmatrix.cabal | |||
@@ -6,11 +6,11 @@ Author: Alberto Ruiz | |||
6 | Maintainer: Alberto Ruiz <aruiz@um.es> | 6 | Maintainer: Alberto Ruiz <aruiz@um.es> |
7 | Stability: provisional | 7 | Stability: provisional |
8 | Homepage: https://github.com/albertoruiz/hmatrix | 8 | Homepage: https://github.com/albertoruiz/hmatrix |
9 | Synopsis: Linear algebra and numerical computation | 9 | Synopsis: Numerical computation |
10 | Description: Purely functional interface to basic linear algebra | 10 | Description: Purely functional interface to basic linear algebra |
11 | and other numerical computations, internally implemented using | 11 | and other numerical computations, internally implemented using |
12 | GSL, BLAS and LAPACK. | 12 | GSL, BLAS and LAPACK. |
13 | 13 | ||
14 | Category: Math | 14 | Category: Math |
15 | tested-with: GHC ==7.8 | 15 | tested-with: GHC ==7.8 |
16 | 16 | ||
@@ -45,8 +45,7 @@ extra-source-files: examples/deriv.hs | |||
45 | examples/bool.hs | 45 | examples/bool.hs |
46 | examples/multiply.hs | 46 | examples/multiply.hs |
47 | 47 | ||
48 | extra-source-files: src/Numeric/LinearAlgebra/LAPACK/lapack-aux.h, | 48 | extra-source-files: src/Numeric/GSL/gsl-ode.c |
49 | src/Numeric/GSL/gsl-ode.c | ||
50 | 49 | ||
51 | flag dd | 50 | flag dd |
52 | description: svd = zgesdd | 51 | description: svd = zgesdd |
@@ -74,23 +73,15 @@ flag debugnan | |||
74 | 73 | ||
75 | library | 74 | library |
76 | 75 | ||
77 | Build-Depends: base, hmatrix-base, | 76 | Build-Depends: base, hmatrix-base, array, vector, |
78 | array, | 77 | process, random |
79 | storable-complex, | 78 | |
80 | process, random, | ||
81 | vector >= 0.8, | ||
82 | binary, | ||
83 | deepseq | ||
84 | 79 | ||
85 | Extensions: ForeignFunctionInterface, | 80 | Extensions: ForeignFunctionInterface, |
86 | CPP | 81 | CPP |
87 | 82 | ||
88 | hs-source-dirs: src | 83 | hs-source-dirs: src |
89 | Exposed-modules: Data.Packed, | 84 | Exposed-modules: Numeric.GSL.Differentiation, |
90 | Data.Packed.Vector, | ||
91 | Data.Packed.Matrix, | ||
92 | Data.Packed.Foreign, | ||
93 | Numeric.GSL.Differentiation, | ||
94 | Numeric.GSL.Integration, | 85 | Numeric.GSL.Integration, |
95 | Numeric.GSL.Fourier, | 86 | Numeric.GSL.Fourier, |
96 | Numeric.GSL.Polynomials, | 87 | Numeric.GSL.Polynomials, |
@@ -101,24 +92,15 @@ library | |||
101 | Numeric.GSL, | 92 | Numeric.GSL, |
102 | Numeric.Container, | 93 | Numeric.Container, |
103 | Numeric.LinearAlgebra, | 94 | Numeric.LinearAlgebra, |
104 | Numeric.LinearAlgebra.LAPACK, | ||
105 | Numeric.LinearAlgebra.Algorithms, | 95 | Numeric.LinearAlgebra.Algorithms, |
106 | Numeric.LinearAlgebra.Util, | 96 | Numeric.LinearAlgebra.Util, |
107 | Data.Packed.ST, | ||
108 | Data.Packed.Development | ||
109 | Graphics.Plot, | 97 | Graphics.Plot, |
110 | Numeric.HMatrix, | 98 | Numeric.HMatrix, |
111 | Numeric.HMatrix.Data, | 99 | Numeric.HMatrix.Data, |
112 | Numeric.HMatrix.Devel | 100 | Numeric.HMatrix.Devel |
113 | other-modules: Data.Packed.Internal, | 101 | other-modules: Numeric.Random, |
114 | Data.Packed.Internal.Common, | ||
115 | Data.Packed.Internal.Signatures, | ||
116 | Data.Packed.Internal.Vector, | ||
117 | Data.Packed.Internal.Matrix, | ||
118 | Numeric.Random, | ||
119 | Numeric.GSL.Internal, | 102 | Numeric.GSL.Internal, |
120 | Numeric.GSL.Vector, | 103 | Numeric.GSL.Vector, |
121 | Numeric.Conversion, | ||
122 | Numeric.ContainerBoot, | 104 | Numeric.ContainerBoot, |
123 | Numeric.IO, | 105 | Numeric.IO, |
124 | Numeric.Chain, | 106 | Numeric.Chain, |
@@ -127,8 +109,7 @@ library | |||
127 | Numeric.LinearAlgebra.Util.Convolution | 109 | Numeric.LinearAlgebra.Util.Convolution |
128 | 110 | ||
129 | 111 | ||
130 | C-sources: src/Numeric/LinearAlgebra/LAPACK/lapack-aux.c, | 112 | C-sources: src/Numeric/GSL/gsl-aux.c |
131 | src/Numeric/GSL/gsl-aux.c | ||
132 | 113 | ||
133 | cc-options: -O4 -msse2 -Wall | 114 | cc-options: -O4 -msse2 -Wall |
134 | 115 | ||
diff --git a/packages/hmatrix/src/Numeric/Container.hs b/packages/hmatrix/src/Numeric/Container.hs index ff649b7..3a8dd94 100644 --- a/packages/hmatrix/src/Numeric/Container.hs +++ b/packages/hmatrix/src/Numeric/Container.hs | |||
@@ -30,7 +30,7 @@ module Numeric.Container ( | |||
30 | -- * Basic functions | 30 | -- * Basic functions |
31 | module Data.Packed, | 31 | module Data.Packed, |
32 | konst, build, | 32 | konst, build, |
33 | constant, linspace, | 33 | linspace, |
34 | diag, ident, | 34 | diag, ident, |
35 | ctrans, | 35 | ctrans, |
36 | -- * Generic operations | 36 | -- * Generic operations |
@@ -64,8 +64,7 @@ module Numeric.Container ( | |||
64 | fscanfVector, fprintfVector, freadVector, fwriteVector, | 64 | fscanfVector, fprintfVector, freadVector, fwriteVector, |
65 | ) where | 65 | ) where |
66 | 66 | ||
67 | import Data.Packed | 67 | import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) |
68 | import Data.Packed.Internal(constantD) | ||
69 | import Numeric.ContainerBoot | 68 | import Numeric.ContainerBoot |
70 | import Numeric.Chain | 69 | import Numeric.Chain |
71 | import Numeric.IO | 70 | import Numeric.IO |
@@ -75,15 +74,6 @@ import Numeric.Random | |||
75 | 74 | ||
76 | ------------------------------------------------------------------ | 75 | ------------------------------------------------------------------ |
77 | 76 | ||
78 | {- | creates a vector with a given number of equal components: | ||
79 | |||
80 | @> constant 2 7 | ||
81 | 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ | ||
82 | -} | ||
83 | constant :: Element a => a -> Int -> Vector a | ||
84 | -- constant x n = runSTVector (newVector x n) | ||
85 | constant = constantD-- about 2x faster | ||
86 | |||
87 | {- | Creates a real vector containing a range of values: | 77 | {- | Creates a real vector containing a range of values: |
88 | 78 | ||
89 | >>> linspace 5 (-3,7::Double) | 79 | >>> linspace 5 (-3,7::Double) |
diff --git a/packages/hmatrix/src/Numeric/ContainerBoot.hs b/packages/hmatrix/src/Numeric/ContainerBoot.hs index ea4262c..ef21763 100644 --- a/packages/hmatrix/src/Numeric/ContainerBoot.hs +++ b/packages/hmatrix/src/Numeric/ContainerBoot.hs | |||
@@ -42,7 +42,7 @@ module Numeric.ContainerBoot ( | |||
42 | import Data.Packed | 42 | import Data.Packed |
43 | import Data.Packed.ST as ST | 43 | import Data.Packed.ST as ST |
44 | import Numeric.Conversion | 44 | import Numeric.Conversion |
45 | import Data.Packed.Internal | 45 | import Data.Packed.Development |
46 | import Numeric.GSL.Vector | 46 | import Numeric.GSL.Vector |
47 | import Data.Complex | 47 | import Data.Complex |
48 | import Control.Applicative((<*>)) | 48 | import Control.Applicative((<*>)) |
@@ -201,7 +201,7 @@ instance Container Vector Float where | |||
201 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 | 201 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 |
202 | arctan2 = vectorZipF ATan2 | 202 | arctan2 = vectorZipF ATan2 |
203 | scalar x = fromList [x] | 203 | scalar x = fromList [x] |
204 | konst' = constantD | 204 | konst' = constant |
205 | build' = buildV | 205 | build' = buildV |
206 | conj = id | 206 | conj = id |
207 | cmap = mapVector | 207 | cmap = mapVector |
@@ -229,7 +229,7 @@ instance Container Vector Double where | |||
229 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 | 229 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 |
230 | arctan2 = vectorZipR ATan2 | 230 | arctan2 = vectorZipR ATan2 |
231 | scalar x = fromList [x] | 231 | scalar x = fromList [x] |
232 | konst' = constantD | 232 | konst' = constant |
233 | build' = buildV | 233 | build' = buildV |
234 | conj = id | 234 | conj = id |
235 | cmap = mapVector | 235 | cmap = mapVector |
@@ -257,7 +257,7 @@ instance Container Vector (Complex Double) where | |||
257 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 257 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
258 | arctan2 = vectorZipC ATan2 | 258 | arctan2 = vectorZipC ATan2 |
259 | scalar x = fromList [x] | 259 | scalar x = fromList [x] |
260 | konst' = constantD | 260 | konst' = constant |
261 | build' = buildV | 261 | build' = buildV |
262 | conj = conjugateC | 262 | conj = conjugateC |
263 | cmap = mapVector | 263 | cmap = mapVector |
@@ -285,7 +285,7 @@ instance Container Vector (Complex Float) where | |||
285 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 285 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
286 | arctan2 = vectorZipQ ATan2 | 286 | arctan2 = vectorZipQ ATan2 |
287 | scalar x = fromList [x] | 287 | scalar x = fromList [x] |
288 | konst' = constantD | 288 | konst' = constant |
289 | build' = buildV | 289 | build' = buildV |
290 | conj = conjugateQ | 290 | conj = conjugateQ |
291 | cmap = mapVector | 291 | cmap = mapVector |
@@ -569,7 +569,7 @@ diag v = diagRect 0 v n n where n = dim v | |||
569 | 569 | ||
570 | -- | creates the identity matrix of given dimension | 570 | -- | creates the identity matrix of given dimension |
571 | ident :: (Num a, Element a) => Int -> Matrix a | 571 | ident :: (Num a, Element a) => Int -> Matrix a |
572 | ident n = diag (constantD 1 n) | 572 | ident n = diag (constant 1 n) |
573 | 573 | ||
574 | -------------------------------------------------------- | 574 | -------------------------------------------------------- |
575 | 575 | ||
diff --git a/packages/hmatrix/src/Numeric/GSL.hs b/packages/hmatrix/src/Numeric/GSL.hs index 5f39a3e..61b8d7b 100644 --- a/packages/hmatrix/src/Numeric/GSL.hs +++ b/packages/hmatrix/src/Numeric/GSL.hs | |||
@@ -1,12 +1,11 @@ | |||
1 | {- | | 1 | {- | |
2 | 2 | ||
3 | Module : Numeric.GSL | 3 | Module : Numeric.GSL |
4 | Copyright : (c) Alberto Ruiz 2006-7 | 4 | Copyright : (c) Alberto Ruiz 2006-14 |
5 | License : GPL-style | 5 | License : GPL |
6 | 6 | ||
7 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 7 | Maintainer : Alberto Ruiz |
8 | Stability : provisional | 8 | Stability : provisional |
9 | Portability : uses -fffi and -fglasgow-exts | ||
10 | 9 | ||
11 | This module reexports all available GSL functions. | 10 | This module reexports all available GSL functions. |
12 | 11 | ||
@@ -41,3 +40,4 @@ import Data.Complex | |||
41 | -- | This action removes the GSL default error handler (which aborts the program), so that | 40 | -- | This action removes the GSL default error handler (which aborts the program), so that |
42 | -- GSL errors can be handled by Haskell (using Control.Exception) and ghci doesn't abort. | 41 | -- GSL errors can be handled by Haskell (using Control.Exception) and ghci doesn't abort. |
43 | foreign import ccall unsafe "GSL/gsl-aux.h no_abort_on_error" setErrorHandlerOff :: IO () | 42 | foreign import ccall unsafe "GSL/gsl-aux.h no_abort_on_error" setErrorHandlerOff :: IO () |
43 | |||
diff --git a/packages/hmatrix/src/Numeric/GSL/Differentiation.hs b/packages/hmatrix/src/Numeric/GSL/Differentiation.hs index 93c5007..0fb58ef 100644 --- a/packages/hmatrix/src/Numeric/GSL/Differentiation.hs +++ b/packages/hmatrix/src/Numeric/GSL/Differentiation.hs | |||
@@ -1,13 +1,10 @@ | |||
1 | {-# OPTIONS #-} | ||
2 | ----------------------------------------------------------------------------- | ||
3 | {- | | 1 | {- | |
4 | Module : Numeric.GSL.Differentiation | 2 | Module : Numeric.GSL.Differentiation |
5 | Copyright : (c) Alberto Ruiz 2006 | 3 | Copyright : (c) Alberto Ruiz 2006 |
6 | License : GPL-style | 4 | License : GPL |
7 | 5 | ||
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 6 | Maintainer : Alberto Ruiz |
9 | Stability : provisional | 7 | Stability : provisional |
10 | Portability : uses ffi | ||
11 | 8 | ||
12 | Numerical differentiation. | 9 | Numerical differentiation. |
13 | 10 | ||
@@ -15,7 +12,8 @@ Numerical differentiation. | |||
15 | 12 | ||
16 | From the GSL manual: \"The functions described in this chapter compute numerical derivatives by finite differencing. An adaptive algorithm is used to find the best choice of finite difference and to estimate the error in the derivative.\" | 13 | From the GSL manual: \"The functions described in this chapter compute numerical derivatives by finite differencing. An adaptive algorithm is used to find the best choice of finite difference and to estimate the error in the derivative.\" |
17 | -} | 14 | -} |
18 | ----------------------------------------------------------------------------- | 15 | |
16 | |||
19 | module Numeric.GSL.Differentiation ( | 17 | module Numeric.GSL.Differentiation ( |
20 | derivCentral, | 18 | derivCentral, |
21 | derivForward, | 19 | derivForward, |
@@ -26,7 +24,7 @@ import Foreign.C.Types | |||
26 | import Foreign.Marshal.Alloc(malloc, free) | 24 | import Foreign.Marshal.Alloc(malloc, free) |
27 | import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) | 25 | import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) |
28 | import Foreign.Storable(peek) | 26 | import Foreign.Storable(peek) |
29 | import Data.Packed.Internal(check,(//)) | 27 | import Numeric.GSL.Internal |
30 | import System.IO.Unsafe(unsafePerformIO) | 28 | import System.IO.Unsafe(unsafePerformIO) |
31 | 29 | ||
32 | derivGen :: | 30 | derivGen :: |
diff --git a/packages/hmatrix/src/Numeric/GSL/Fitting.hs b/packages/hmatrix/src/Numeric/GSL/Fitting.hs index c4f3a91..0a92373 100644 --- a/packages/hmatrix/src/Numeric/GSL/Fitting.hs +++ b/packages/hmatrix/src/Numeric/GSL/Fitting.hs | |||
@@ -3,9 +3,8 @@ Module : Numeric.GSL.Fitting | |||
3 | Copyright : (c) Alberto Ruiz 2010 | 3 | Copyright : (c) Alberto Ruiz 2010 |
4 | License : GPL | 4 | License : GPL |
5 | 5 | ||
6 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 6 | Maintainer : Alberto Ruiz |
7 | Stability : provisional | 7 | Stability : provisional |
8 | Portability : uses ffi | ||
9 | 8 | ||
10 | Nonlinear Least-Squares Fitting | 9 | Nonlinear Least-Squares Fitting |
11 | 10 | ||
@@ -42,7 +41,7 @@ expModelDer [a,lambda,b] [t] = [[exp (-lambda * t), -t * a * exp(-lambda*t) , 1] | |||
42 | (1.0192487112786812,3.782067731353722e-2)] | 41 | (1.0192487112786812,3.782067731353722e-2)] |
43 | 42 | ||
44 | -} | 43 | -} |
45 | ----------------------------------------------------------------------------- | 44 | |
46 | 45 | ||
47 | module Numeric.GSL.Fitting ( | 46 | module Numeric.GSL.Fitting ( |
48 | -- * Levenberg-Marquardt | 47 | -- * Levenberg-Marquardt |
@@ -51,7 +50,6 @@ module Numeric.GSL.Fitting ( | |||
51 | fitModelScaled, fitModel | 50 | fitModelScaled, fitModel |
52 | ) where | 51 | ) where |
53 | 52 | ||
54 | import Data.Packed.Internal | ||
55 | import Numeric.LinearAlgebra | 53 | import Numeric.LinearAlgebra |
56 | import Numeric.GSL.Internal | 54 | import Numeric.GSL.Internal |
57 | 55 | ||
@@ -61,6 +59,9 @@ import System.IO.Unsafe(unsafePerformIO) | |||
61 | 59 | ||
62 | ------------------------------------------------------------------------- | 60 | ------------------------------------------------------------------------- |
63 | 61 | ||
62 | type TVV = TV (TV Res) | ||
63 | type TVM = TV (TM Res) | ||
64 | |||
64 | data FittingMethod = LevenbergMarquardtScaled -- ^ Interface to gsl_multifit_fdfsolver_lmsder. This is a robust and efficient version of the Levenberg-Marquardt algorithm as implemented in the scaled lmder routine in minpack. Minpack was written by Jorge J. More, Burton S. Garbow and Kenneth E. Hillstrom. | 65 | data FittingMethod = LevenbergMarquardtScaled -- ^ Interface to gsl_multifit_fdfsolver_lmsder. This is a robust and efficient version of the Levenberg-Marquardt algorithm as implemented in the scaled lmder routine in minpack. Minpack was written by Jorge J. More, Burton S. Garbow and Kenneth E. Hillstrom. |
65 | | LevenbergMarquardt -- ^ This is an unscaled version of the lmder algorithm. The elements of the diagonal scaling matrix D are set to 1. This algorithm may be useful in circumstances where the scaled version of lmder converges too slowly, or the function is already scaled appropriately. | 66 | | LevenbergMarquardt -- ^ This is an unscaled version of the lmder algorithm. The elements of the diagonal scaling matrix D are set to 1. This algorithm may be useful in circumstances where the scaled version of lmder converges too slowly, or the function is already scaled appropriately. |
66 | deriving (Enum,Eq,Show,Bounded) | 67 | deriving (Enum,Eq,Show,Bounded) |
diff --git a/packages/hmatrix/src/Numeric/GSL/Fourier.hs b/packages/hmatrix/src/Numeric/GSL/Fourier.hs index 86aedd6..734325b 100644 --- a/packages/hmatrix/src/Numeric/GSL/Fourier.hs +++ b/packages/hmatrix/src/Numeric/GSL/Fourier.hs | |||
@@ -1,26 +1,23 @@ | |||
1 | {-# LANGUAGE ForeignFunctionInterface #-} | ||
2 | ----------------------------------------------------------------------------- | ||
3 | {- | | 1 | {- | |
4 | Module : Numeric.GSL.Fourier | 2 | Module : Numeric.GSL.Fourier |
5 | Copyright : (c) Alberto Ruiz 2006 | 3 | Copyright : (c) Alberto Ruiz 2006 |
6 | License : GPL-style | 4 | License : GPL |
7 | 5 | Maintainer : Alberto Ruiz | |
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
9 | Stability : provisional | 6 | Stability : provisional |
10 | Portability : uses ffi | ||
11 | 7 | ||
12 | Fourier Transform. | 8 | Fourier Transform. |
13 | 9 | ||
14 | <http://www.gnu.org/software/gsl/manual/html_node/Fast-Fourier-Transforms.html#Fast-Fourier-Transforms> | 10 | <http://www.gnu.org/software/gsl/manual/html_node/Fast-Fourier-Transforms.html#Fast-Fourier-Transforms> |
15 | 11 | ||
16 | -} | 12 | -} |
17 | ----------------------------------------------------------------------------- | 13 | |
18 | module Numeric.GSL.Fourier ( | 14 | module Numeric.GSL.Fourier ( |
19 | fft, | 15 | fft, |
20 | ifft | 16 | ifft |
21 | ) where | 17 | ) where |
22 | 18 | ||
23 | import Data.Packed.Internal | 19 | import Data.Packed |
20 | import Numeric.GSL.Internal | ||
24 | import Data.Complex | 21 | import Data.Complex |
25 | import Foreign.C.Types | 22 | import Foreign.C.Types |
26 | import System.IO.Unsafe (unsafePerformIO) | 23 | import System.IO.Unsafe (unsafePerformIO) |
@@ -30,7 +27,7 @@ genfft code v = unsafePerformIO $ do | |||
30 | app2 (c_fft code) vec v vec r "fft" | 27 | app2 (c_fft code) vec v vec r "fft" |
31 | return r | 28 | return r |
32 | 29 | ||
33 | foreign import ccall unsafe "gsl-aux.h fft" c_fft :: CInt -> TCVCV | 30 | foreign import ccall unsafe "gsl-aux.h fft" c_fft :: CInt -> TCV (TCV Res) |
34 | 31 | ||
35 | 32 | ||
36 | {- | Fast 1D Fourier transform of a 'Vector' @(@'Complex' 'Double'@)@ using /gsl_fft_complex_forward/. It uses the same scaling conventions as GNU Octave. | 33 | {- | Fast 1D Fourier transform of a 'Vector' @(@'Complex' 'Double'@)@ using /gsl_fft_complex_forward/. It uses the same scaling conventions as GNU Octave. |
diff --git a/packages/hmatrix/src/Numeric/GSL/Integration.hs b/packages/hmatrix/src/Numeric/GSL/Integration.hs index 5f0a415..9c1d43a 100644 --- a/packages/hmatrix/src/Numeric/GSL/Integration.hs +++ b/packages/hmatrix/src/Numeric/GSL/Integration.hs | |||
@@ -1,19 +1,15 @@ | |||
1 | {-# OPTIONS #-} | ||
2 | ----------------------------------------------------------------------------- | ||
3 | {- | | 1 | {- | |
4 | Module : Numeric.GSL.Integration | 2 | Module : Numeric.GSL.Integration |
5 | Copyright : (c) Alberto Ruiz 2006 | 3 | Copyright : (c) Alberto Ruiz 2006 |
6 | License : GPL-style | 4 | License : GPL |
7 | 5 | Maintainer : Alberto Ruiz | |
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
9 | Stability : provisional | 6 | Stability : provisional |
10 | Portability : uses ffi | ||
11 | 7 | ||
12 | Numerical integration routines. | 8 | Numerical integration routines. |
13 | 9 | ||
14 | <http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html#Numerical-Integration> | 10 | <http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html#Numerical-Integration> |
15 | -} | 11 | -} |
16 | ----------------------------------------------------------------------------- | 12 | |
17 | 13 | ||
18 | module Numeric.GSL.Integration ( | 14 | module Numeric.GSL.Integration ( |
19 | integrateQNG, | 15 | integrateQNG, |
@@ -28,7 +24,7 @@ import Foreign.C.Types | |||
28 | import Foreign.Marshal.Alloc(malloc, free) | 24 | import Foreign.Marshal.Alloc(malloc, free) |
29 | import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) | 25 | import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) |
30 | import Foreign.Storable(peek) | 26 | import Foreign.Storable(peek) |
31 | import Data.Packed.Internal(check,(//)) | 27 | import Numeric.GSL.Internal |
32 | import System.IO.Unsafe(unsafePerformIO) | 28 | import System.IO.Unsafe(unsafePerformIO) |
33 | 29 | ||
34 | eps = 1e-12 | 30 | eps = 1e-12 |
diff --git a/packages/hmatrix/src/Numeric/GSL/Internal.hs b/packages/hmatrix/src/Numeric/GSL/Internal.hs index 69a9750..a1c4e0c 100644 --- a/packages/hmatrix/src/Numeric/GSL/Internal.hs +++ b/packages/hmatrix/src/Numeric/GSL/Internal.hs | |||
@@ -1,23 +1,43 @@ | |||
1 | -- | | ||
1 | -- Module : Numeric.GSL.Internal | 2 | -- Module : Numeric.GSL.Internal |
2 | -- Copyright : (c) Alberto Ruiz 2009 | 3 | -- Copyright : (c) Alberto Ruiz 2009 |
3 | -- License : GPL | 4 | -- License : GPL |
4 | -- | 5 | -- Maintainer : Alberto Ruiz |
5 | -- Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
6 | -- Stability : provisional | 6 | -- Stability : provisional |
7 | -- Portability : uses ffi | 7 | -- |
8 | -- | 8 | -- |
9 | -- Auxiliary functions. | 9 | -- Auxiliary functions. |
10 | -- | 10 | -- |
11 | -- #hide | ||
12 | 11 | ||
13 | module Numeric.GSL.Internal where | ||
14 | 12 | ||
15 | import Data.Packed.Internal | 13 | module Numeric.GSL.Internal( |
14 | iv, | ||
15 | mkVecfun, | ||
16 | mkVecVecfun, | ||
17 | mkDoubleVecVecfun, | ||
18 | mkDoublefun, | ||
19 | aux_vTov, | ||
20 | mkVecMatfun, | ||
21 | mkDoubleVecMatfun, | ||
22 | aux_vTom, | ||
23 | createV, | ||
24 | createMIO, | ||
25 | module Data.Packed.Development, | ||
26 | check, | ||
27 | Res,TV,TM,TCV,TCM | ||
28 | ) where | ||
29 | |||
30 | import Data.Packed | ||
31 | import Data.Packed.Development hiding (check) | ||
32 | import Data.Complex | ||
16 | 33 | ||
17 | import Foreign.Marshal.Array(copyArray) | 34 | import Foreign.Marshal.Array(copyArray) |
18 | import Foreign.Ptr(Ptr, FunPtr) | 35 | import Foreign.Ptr(Ptr, FunPtr) |
19 | import Foreign.C.Types | 36 | import Foreign.C.Types |
37 | import Foreign.C.String(peekCString) | ||
20 | import System.IO.Unsafe(unsafePerformIO) | 38 | import System.IO.Unsafe(unsafePerformIO) |
39 | import Data.Vector.Storable(unsafeWith) | ||
40 | import Control.Monad(when) | ||
21 | 41 | ||
22 | iv :: (Vector Double -> Double) -> (CInt -> Ptr Double -> Double) | 42 | iv :: (Vector Double -> Double) -> (CInt -> Ptr Double -> Double) |
23 | iv f n p = f (createV (fromIntegral n) copy "iv") where | 43 | iv f n p = f (createV (fromIntegral n) copy "iv") where |
@@ -74,3 +94,33 @@ createMIO r c fun msg = do | |||
74 | res <- createMatrix RowMajor r c | 94 | res <- createMatrix RowMajor r c |
75 | app1 fun mat res msg | 95 | app1 fun mat res msg |
76 | return res | 96 | return res |
97 | |||
98 | -------------------------------------------------------------------------------- | ||
99 | |||
100 | -- | check the error code | ||
101 | check :: String -> IO CInt -> IO () | ||
102 | check msg f = do | ||
103 | err <- f | ||
104 | when (err/=0) $ do | ||
105 | ps <- gsl_strerror err | ||
106 | s <- peekCString ps | ||
107 | error (msg++": "++s) | ||
108 | return () | ||
109 | |||
110 | -- | description of GSL error codes | ||
111 | foreign import ccall unsafe "gsl_strerror" gsl_strerror :: CInt -> IO (Ptr CChar) | ||
112 | |||
113 | type PF = Ptr Float | ||
114 | type PD = Ptr Double | ||
115 | type PQ = Ptr (Complex Float) | ||
116 | type PC = Ptr (Complex Double) | ||
117 | |||
118 | type Res = IO CInt | ||
119 | type TV x = CInt -> PD -> x | ||
120 | type TM x = CInt -> CInt -> PD -> x | ||
121 | type TCV x = CInt -> PC -> x | ||
122 | type TCM x = CInt -> CInt -> PC -> x | ||
123 | |||
124 | type TVV = TV (TV Res) | ||
125 | type TVM = TV (TM Res) | ||
126 | |||
diff --git a/packages/hmatrix/src/Numeric/GSL/Minimization.hs b/packages/hmatrix/src/Numeric/GSL/Minimization.hs index 1879dab..056d463 100644 --- a/packages/hmatrix/src/Numeric/GSL/Minimization.hs +++ b/packages/hmatrix/src/Numeric/GSL/Minimization.hs | |||
@@ -1,13 +1,9 @@ | |||
1 | {-# LANGUAGE ForeignFunctionInterface #-} | ||
2 | ----------------------------------------------------------------------------- | ||
3 | {- | | 1 | {- | |
4 | Module : Numeric.GSL.Minimization | 2 | Module : Numeric.GSL.Minimization |
5 | Copyright : (c) Alberto Ruiz 2006-9 | 3 | Copyright : (c) Alberto Ruiz 2006-9 |
6 | License : GPL-style | 4 | License : GPL |
7 | 5 | Maintainer : Alberto Ruiz | |
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
9 | Stability : provisional | 6 | Stability : provisional |
10 | Portability : uses ffi | ||
11 | 7 | ||
12 | Minimization of a multidimensional function using some of the algorithms described in: | 8 | Minimization of a multidimensional function using some of the algorithms described in: |
13 | 9 | ||
@@ -48,7 +44,7 @@ The nmsimplex2 version is a new O(N) implementation of the earlier O(N^2) nmsimp | |||
48 | 44 | ||
49 | -} | 45 | -} |
50 | 46 | ||
51 | ----------------------------------------------------------------------------- | 47 | |
52 | module Numeric.GSL.Minimization ( | 48 | module Numeric.GSL.Minimization ( |
53 | minimize, minimizeV, MinimizeMethod(..), | 49 | minimize, minimizeV, MinimizeMethod(..), |
54 | minimizeD, minimizeVD, MinimizeMethodD(..), | 50 | minimizeD, minimizeVD, MinimizeMethodD(..), |
@@ -60,8 +56,7 @@ module Numeric.GSL.Minimization ( | |||
60 | ) where | 56 | ) where |
61 | 57 | ||
62 | 58 | ||
63 | import Data.Packed.Internal | 59 | import Data.Packed |
64 | import Data.Packed.Matrix | ||
65 | import Numeric.GSL.Internal | 60 | import Numeric.GSL.Internal |
66 | 61 | ||
67 | import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) | 62 | import Foreign.Ptr(Ptr, FunPtr, freeHaskellFunPtr) |
@@ -112,7 +107,7 @@ uniMinimizeGen m f xmin xl xu epsrel maxit = unsafePerformIO $ do | |||
112 | 107 | ||
113 | 108 | ||
114 | foreign import ccall safe "uniMinimize" | 109 | foreign import ccall safe "uniMinimize" |
115 | c_uniMinize:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> Double -> TM | 110 | c_uniMinize:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> Double -> TM Res |
116 | 111 | ||
117 | data MinimizeMethod = NMSimplex | 112 | data MinimizeMethod = NMSimplex |
118 | | NMSimplex2 | 113 | | NMSimplex2 |
@@ -150,13 +145,13 @@ minimizeV method eps maxit szv f xiv = unsafePerformIO $ do | |||
150 | "minimize" | 145 | "minimize" |
151 | let it = round (rawpath @@> (maxit-1,0)) | 146 | let it = round (rawpath @@> (maxit-1,0)) |
152 | path = takeRows it rawpath | 147 | path = takeRows it rawpath |
153 | sol = cdat $ dropColumns 3 $ dropRows (it-1) path | 148 | sol = flatten $ dropColumns 3 $ dropRows (it-1) path |
154 | freeHaskellFunPtr fp | 149 | freeHaskellFunPtr fp |
155 | return (sol, path) | 150 | return (sol, path) |
156 | 151 | ||
157 | 152 | ||
158 | foreign import ccall safe "gsl-aux.h minimize" | 153 | foreign import ccall safe "gsl-aux.h minimize" |
159 | c_minimize:: CInt -> FunPtr (CInt -> Ptr Double -> Double) -> Double -> CInt -> TVVM | 154 | c_minimize:: CInt -> FunPtr (CInt -> Ptr Double -> Double) -> Double -> CInt -> TV(TV(TM Res)) |
160 | 155 | ||
161 | ---------------------------------------------------------------------------------- | 156 | ---------------------------------------------------------------------------------- |
162 | 157 | ||
@@ -207,7 +202,7 @@ minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do | |||
207 | "minimizeD" | 202 | "minimizeD" |
208 | let it = round (rawpath @@> (maxit-1,0)) | 203 | let it = round (rawpath @@> (maxit-1,0)) |
209 | path = takeRows it rawpath | 204 | path = takeRows it rawpath |
210 | sol = cdat $ dropColumns 2 $ dropRows (it-1) path | 205 | sol = flatten $ dropColumns 2 $ dropRows (it-1) path |
211 | freeHaskellFunPtr fp | 206 | freeHaskellFunPtr fp |
212 | freeHaskellFunPtr dfp | 207 | freeHaskellFunPtr dfp |
213 | return (sol,path) | 208 | return (sol,path) |
@@ -215,9 +210,9 @@ minimizeVD method eps maxit istep tol f df xiv = unsafePerformIO $ do | |||
215 | foreign import ccall safe "gsl-aux.h minimizeD" | 210 | foreign import ccall safe "gsl-aux.h minimizeD" |
216 | c_minimizeD :: CInt | 211 | c_minimizeD :: CInt |
217 | -> FunPtr (CInt -> Ptr Double -> Double) | 212 | -> FunPtr (CInt -> Ptr Double -> Double) |
218 | -> FunPtr TVV | 213 | -> FunPtr (TV (TV Res)) |
219 | -> Double -> Double -> Double -> CInt | 214 | -> Double -> Double -> Double -> CInt |
220 | -> TVM | 215 | -> TV (TM Res) |
221 | 216 | ||
222 | --------------------------------------------------------------------- | 217 | --------------------------------------------------------------------- |
223 | 218 | ||
diff --git a/packages/hmatrix/src/Numeric/GSL/ODE.hs b/packages/hmatrix/src/Numeric/GSL/ODE.hs index 9a29085..7549a65 100644 --- a/packages/hmatrix/src/Numeric/GSL/ODE.hs +++ b/packages/hmatrix/src/Numeric/GSL/ODE.hs | |||
@@ -2,10 +2,8 @@ | |||
2 | Module : Numeric.GSL.ODE | 2 | Module : Numeric.GSL.ODE |
3 | Copyright : (c) Alberto Ruiz 2010 | 3 | Copyright : (c) Alberto Ruiz 2010 |
4 | License : GPL | 4 | License : GPL |
5 | 5 | Maintainer : Alberto Ruiz | |
6 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
7 | Stability : provisional | 6 | Stability : provisional |
8 | Portability : uses ffi | ||
9 | 7 | ||
10 | Solution of ordinary differential equation (ODE) initial value problems. | 8 | Solution of ordinary differential equation (ODE) initial value problems. |
11 | 9 | ||
@@ -34,7 +32,7 @@ module Numeric.GSL.ODE ( | |||
34 | odeSolve, odeSolveV, ODEMethod(..), Jacobian | 32 | odeSolve, odeSolveV, ODEMethod(..), Jacobian |
35 | ) where | 33 | ) where |
36 | 34 | ||
37 | import Data.Packed.Internal | 35 | import Data.Packed |
38 | import Numeric.GSL.Internal | 36 | import Numeric.GSL.Internal |
39 | 37 | ||
40 | import Foreign.Ptr(FunPtr, nullFunPtr, freeHaskellFunPtr) | 38 | import Foreign.Ptr(FunPtr, nullFunPtr, freeHaskellFunPtr) |
@@ -43,6 +41,10 @@ import System.IO.Unsafe(unsafePerformIO) | |||
43 | 41 | ||
44 | ------------------------------------------------------------------------- | 42 | ------------------------------------------------------------------------- |
45 | 43 | ||
44 | type TVV = TV (TV Res) | ||
45 | type TVM = TV (TM Res) | ||
46 | type TVVM = TV (TV (TM Res)) | ||
47 | |||
46 | type Jacobian = Double -> Vector Double -> Matrix Double | 48 | type Jacobian = Double -> Vector Double -> Matrix Double |
47 | 49 | ||
48 | -- | Stepping functions | 50 | -- | Stepping functions |
diff --git a/packages/hmatrix/src/Numeric/GSL/Polynomials.hs b/packages/hmatrix/src/Numeric/GSL/Polynomials.hs index 290c615..b1be85d 100644 --- a/packages/hmatrix/src/Numeric/GSL/Polynomials.hs +++ b/packages/hmatrix/src/Numeric/GSL/Polynomials.hs | |||
@@ -1,25 +1,23 @@ | |||
1 | {-# LANGUAGE CPP, ForeignFunctionInterface #-} | ||
2 | ----------------------------------------------------------------------------- | ||
3 | {- | | 1 | {- | |
4 | Module : Numeric.GSL.Polynomials | 2 | Module : Numeric.GSL.Polynomials |
5 | Copyright : (c) Alberto Ruiz 2006 | 3 | Copyright : (c) Alberto Ruiz 2006 |
6 | License : GPL-style | 4 | License : GPL |
7 | 5 | Maintainer : Alberto Ruiz | |
8 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
9 | Stability : provisional | 6 | Stability : provisional |
10 | Portability : uses ffi | ||
11 | 7 | ||
12 | Polynomials. | 8 | Polynomials. |
13 | 9 | ||
14 | <http://www.gnu.org/software/gsl/manual/html_node/General-Polynomial-Equations.html#General-Polynomial-Equations> | 10 | <http://www.gnu.org/software/gsl/manual/html_node/General-Polynomial-Equations.html#General-Polynomial-Equations> |
15 | 11 | ||
16 | -} | 12 | -} |
17 | ----------------------------------------------------------------------------- | 13 | |
14 | |||
18 | module Numeric.GSL.Polynomials ( | 15 | module Numeric.GSL.Polynomials ( |
19 | polySolve | 16 | polySolve |
20 | ) where | 17 | ) where |
21 | 18 | ||
22 | import Data.Packed.Internal | 19 | import Data.Packed |
20 | import Numeric.GSL.Internal | ||
23 | import Data.Complex | 21 | import Data.Complex |
24 | import System.IO.Unsafe (unsafePerformIO) | 22 | import System.IO.Unsafe (unsafePerformIO) |
25 | 23 | ||
@@ -55,4 +53,5 @@ polySolve' v | dim v > 1 = unsafePerformIO $ do | |||
55 | return r | 53 | return r |
56 | | otherwise = error "polySolve on a polynomial of degree zero" | 54 | | otherwise = error "polySolve on a polynomial of degree zero" |
57 | 55 | ||
58 | foreign import ccall unsafe "gsl-aux.h polySolve" c_polySolve:: TVCV | 56 | foreign import ccall unsafe "gsl-aux.h polySolve" c_polySolve:: TV (TCV Res) |
57 | |||
diff --git a/packages/hmatrix/src/Numeric/GSL/Root.hs b/packages/hmatrix/src/Numeric/GSL/Root.hs index 9d561c4..b9f3b94 100644 --- a/packages/hmatrix/src/Numeric/GSL/Root.hs +++ b/packages/hmatrix/src/Numeric/GSL/Root.hs | |||
@@ -2,10 +2,8 @@ | |||
2 | Module : Numeric.GSL.Root | 2 | Module : Numeric.GSL.Root |
3 | Copyright : (c) Alberto Ruiz 2009 | 3 | Copyright : (c) Alberto Ruiz 2009 |
4 | License : GPL | 4 | License : GPL |
5 | 5 | Maintainer : Alberto Ruiz | |
6 | Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
7 | Stability : provisional | 6 | Stability : provisional |
8 | Portability : uses ffi | ||
9 | 7 | ||
10 | Multidimensional root finding. | 8 | Multidimensional root finding. |
11 | 9 | ||
@@ -41,14 +39,16 @@ module Numeric.GSL.Root ( | |||
41 | rootJ, RootMethodJ(..), | 39 | rootJ, RootMethodJ(..), |
42 | ) where | 40 | ) where |
43 | 41 | ||
44 | import Data.Packed.Internal | 42 | import Data.Packed |
45 | import Data.Packed.Matrix | ||
46 | import Numeric.GSL.Internal | 43 | import Numeric.GSL.Internal |
47 | import Foreign.Ptr(FunPtr, freeHaskellFunPtr) | 44 | import Foreign.Ptr(FunPtr, freeHaskellFunPtr) |
48 | import Foreign.C.Types | 45 | import Foreign.C.Types |
49 | import System.IO.Unsafe(unsafePerformIO) | 46 | import System.IO.Unsafe(unsafePerformIO) |
50 | 47 | ||
51 | ------------------------------------------------------------------------- | 48 | ------------------------------------------------------------------------- |
49 | type TVV = TV (TV Res) | ||
50 | type TVM = TV (TM Res) | ||
51 | |||
52 | 52 | ||
53 | data UniRootMethod = Bisection | 53 | data UniRootMethod = Bisection |
54 | | FalsePos | 54 | | FalsePos |
@@ -76,7 +76,7 @@ uniRootGen m f xl xu epsrel maxit = unsafePerformIO $ do | |||
76 | return (sol !! 1, path) | 76 | return (sol !! 1, path) |
77 | 77 | ||
78 | foreign import ccall safe "root" | 78 | foreign import ccall safe "root" |
79 | c_root:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> TM | 79 | c_root:: CInt -> FunPtr (Double -> Double) -> Double -> CInt -> Double -> Double -> TM Res |
80 | 80 | ||
81 | ------------------------------------------------------------------------- | 81 | ------------------------------------------------------------------------- |
82 | data UniRootMethodJ = UNewton | 82 | data UniRootMethodJ = UNewton |
@@ -108,7 +108,7 @@ uniRootJGen m f df x epsrel maxit = unsafePerformIO $ do | |||
108 | 108 | ||
109 | foreign import ccall safe "rootj" | 109 | foreign import ccall safe "rootj" |
110 | c_rootj :: CInt -> FunPtr (Double -> Double) -> FunPtr (Double -> Double) | 110 | c_rootj :: CInt -> FunPtr (Double -> Double) -> FunPtr (Double -> Double) |
111 | -> Double -> CInt -> Double -> TM | 111 | -> Double -> CInt -> Double -> TM Res |
112 | 112 | ||
113 | ------------------------------------------------------------------------- | 113 | ------------------------------------------------------------------------- |
114 | 114 | ||
diff --git a/packages/hmatrix/src/Numeric/GSL/Vector.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs index 6204b8e..29c8bb7 100644 --- a/packages/hmatrix/src/Numeric/GSL/Vector.hs +++ b/packages/hmatrix/src/Numeric/GSL/Vector.hs | |||
@@ -2,11 +2,9 @@ | |||
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.GSL.Vector | 3 | -- Module : Numeric.GSL.Vector |
4 | -- Copyright : (c) Alberto Ruiz 2007 | 4 | -- Copyright : (c) Alberto Ruiz 2007 |
5 | -- License : GPL-style | 5 | -- License : GPL |
6 | -- | 6 | -- Maintainer : Alberto Ruiz |
7 | -- Maintainer : Alberto Ruiz <aruiz@um.es> | ||
8 | -- Stability : provisional | 7 | -- Stability : provisional |
9 | -- Portability : portable (uses FFI) | ||
10 | -- | 8 | -- |
11 | -- Low level interface to vector operations. | 9 | -- Low level interface to vector operations. |
12 | -- | 10 | -- |
@@ -20,18 +18,20 @@ module Numeric.GSL.Vector ( | |||
20 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, | 18 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, |
21 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, | 19 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, |
22 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, | 20 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, |
23 | RandDist(..), randomVector | 21 | RandDist(..), randomVector, |
22 | saveMatrix, | ||
23 | fwriteVector, freadVector, fprintfVector, fscanfVector | ||
24 | ) where | 24 | ) where |
25 | 25 | ||
26 | import Data.Packed.Internal.Common | 26 | import Data.Packed |
27 | import Data.Packed.Internal.Signatures | 27 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
28 | import Data.Packed.Internal.Vector | ||
29 | 28 | ||
30 | import Data.Complex | 29 | import Data.Complex |
31 | import Foreign.Marshal.Alloc(free) | 30 | import Foreign.Marshal.Alloc(free) |
32 | import Foreign.Marshal.Array(newArray) | 31 | import Foreign.Marshal.Array(newArray) |
33 | import Foreign.Ptr(Ptr) | 32 | import Foreign.Ptr(Ptr) |
34 | import Foreign.C.Types | 33 | import Foreign.C.Types |
34 | import Foreign.C.String(newCString) | ||
35 | import System.IO.Unsafe(unsafePerformIO) | 35 | import System.IO.Unsafe(unsafePerformIO) |
36 | import Control.Monad(when) | 36 | import Control.Monad(when) |
37 | 37 | ||
@@ -186,7 +186,7 @@ foreign import ccall unsafe "gsl-aux.h dotC" c_dotC :: TCVCVCV | |||
186 | toScalarAux fun code v = unsafePerformIO $ do | 186 | toScalarAux fun code v = unsafePerformIO $ do |
187 | r <- createVector 1 | 187 | r <- createVector 1 |
188 | app2 (fun (fromei code)) vec v vec r "toScalarAux" | 188 | app2 (fun (fromei code)) vec v vec r "toScalarAux" |
189 | return (r `at` 0) | 189 | return (r @> 0) |
190 | 190 | ||
191 | vectorMapAux fun code v = unsafePerformIO $ do | 191 | vectorMapAux fun code v = unsafePerformIO $ do |
192 | r <- createVector (dim v) | 192 | r <- createVector (dim v) |
@@ -326,3 +326,118 @@ randomVector seed dist n = unsafePerformIO $ do | |||
326 | return r | 326 | return r |
327 | 327 | ||
328 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV | 328 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV |
329 | |||
330 | -------------------------------------------------------------------------------- | ||
331 | |||
332 | -- | Saves a matrix as 2D ASCII table. | ||
333 | saveMatrix :: FilePath | ||
334 | -> String -- ^ format (%f, %g, %e) | ||
335 | -> Matrix Double | ||
336 | -> IO () | ||
337 | saveMatrix filename fmt m = do | ||
338 | charname <- newCString filename | ||
339 | charfmt <- newCString fmt | ||
340 | let o = if orderOf m == RowMajor then 1 else 0 | ||
341 | app1 (matrix_fprintf charname charfmt o) mat m "matrix_fprintf" | ||
342 | free charname | ||
343 | free charfmt | ||
344 | |||
345 | foreign import ccall unsafe "matrix_fprintf" matrix_fprintf :: Ptr CChar -> Ptr CChar -> CInt -> TM | ||
346 | |||
347 | -------------------------------------------------------------------------------- | ||
348 | |||
349 | -- | Loads a vector from an ASCII file (the number of elements must be known in advance). | ||
350 | fscanfVector :: FilePath -> Int -> IO (Vector Double) | ||
351 | fscanfVector filename n = do | ||
352 | charname <- newCString filename | ||
353 | res <- createVector n | ||
354 | app1 (gsl_vector_fscanf charname) vec res "gsl_vector_fscanf" | ||
355 | free charname | ||
356 | return res | ||
357 | |||
358 | foreign import ccall unsafe "vector_fscanf" gsl_vector_fscanf:: Ptr CChar -> TV | ||
359 | |||
360 | -- | Saves the elements of a vector, with a given format (%f, %e, %g), to an ASCII file. | ||
361 | fprintfVector :: FilePath -> String -> Vector Double -> IO () | ||
362 | fprintfVector filename fmt v = do | ||
363 | charname <- newCString filename | ||
364 | charfmt <- newCString fmt | ||
365 | app1 (gsl_vector_fprintf charname charfmt) vec v "gsl_vector_fprintf" | ||
366 | free charname | ||
367 | free charfmt | ||
368 | |||
369 | foreign import ccall unsafe "vector_fprintf" gsl_vector_fprintf :: Ptr CChar -> Ptr CChar -> TV | ||
370 | |||
371 | -- | Loads a vector from a binary file (the number of elements must be known in advance). | ||
372 | freadVector :: FilePath -> Int -> IO (Vector Double) | ||
373 | freadVector filename n = do | ||
374 | charname <- newCString filename | ||
375 | res <- createVector n | ||
376 | app1 (gsl_vector_fread charname) vec res "gsl_vector_fread" | ||
377 | free charname | ||
378 | return res | ||
379 | |||
380 | foreign import ccall unsafe "vector_fread" gsl_vector_fread:: Ptr CChar -> TV | ||
381 | |||
382 | -- | Saves the elements of a vector to a binary file. | ||
383 | fwriteVector :: FilePath -> Vector Double -> IO () | ||
384 | fwriteVector filename v = do | ||
385 | charname <- newCString filename | ||
386 | app1 (gsl_vector_fwrite charname) vec v "gsl_vector_fwrite" | ||
387 | free charname | ||
388 | |||
389 | foreign import ccall unsafe "vector_fwrite" gsl_vector_fwrite :: Ptr CChar -> TV | ||
390 | |||
391 | type PF = Ptr Float -- | ||
392 | type PD = Ptr Double -- | ||
393 | type PQ = Ptr (Complex Float) -- | ||
394 | type PC = Ptr (Complex Double) -- | ||
395 | type TF = CInt -> PF -> IO CInt -- | ||
396 | type TFF = CInt -> PF -> TF -- | ||
397 | type TFV = CInt -> PF -> TV -- | ||
398 | type TVF = CInt -> PD -> TF -- | ||
399 | type TFFF = CInt -> PF -> TFF -- | ||
400 | type TV = CInt -> PD -> IO CInt -- | ||
401 | type TVV = CInt -> PD -> TV -- | ||
402 | type TVVV = CInt -> PD -> TVV -- | ||
403 | type TFM = CInt -> CInt -> PF -> IO CInt -- | ||
404 | type TFMFM = CInt -> CInt -> PF -> TFM -- | ||
405 | type TFMFMFM = CInt -> CInt -> PF -> TFMFM -- | ||
406 | type TM = CInt -> CInt -> PD -> IO CInt -- | ||
407 | type TMM = CInt -> CInt -> PD -> TM -- | ||
408 | type TVMM = CInt -> PD -> TMM -- | ||
409 | type TMVMM = CInt -> CInt -> PD -> TVMM -- | ||
410 | type TMMM = CInt -> CInt -> PD -> TMM -- | ||
411 | type TVM = CInt -> PD -> TM -- | ||
412 | type TVVM = CInt -> PD -> TVM -- | ||
413 | type TMV = CInt -> CInt -> PD -> TV -- | ||
414 | type TMMV = CInt -> CInt -> PD -> TMV -- | ||
415 | type TMVM = CInt -> CInt -> PD -> TVM -- | ||
416 | type TMMVM = CInt -> CInt -> PD -> TMVM -- | ||
417 | type TCM = CInt -> CInt -> PC -> IO CInt -- | ||
418 | type TCVCM = CInt -> PC -> TCM -- | ||
419 | type TCMCVCM = CInt -> CInt -> PC -> TCVCM -- | ||
420 | type TMCMCVCM = CInt -> CInt -> PD -> TCMCVCM -- | ||
421 | type TCMCMCVCM = CInt -> CInt -> PC -> TCMCVCM -- | ||
422 | type TCMCM = CInt -> CInt -> PC -> TCM -- | ||
423 | type TVCM = CInt -> PD -> TCM -- | ||
424 | type TCMVCM = CInt -> CInt -> PC -> TVCM -- | ||
425 | type TCMCMVCM = CInt -> CInt -> PC -> TCMVCM -- | ||
426 | type TCMCMCM = CInt -> CInt -> PC -> TCMCM -- | ||
427 | type TCV = CInt -> PC -> IO CInt -- | ||
428 | type TCVCV = CInt -> PC -> TCV -- | ||
429 | type TCVCVCV = CInt -> PC -> TCVCV -- | ||
430 | type TCVV = CInt -> PC -> TV -- | ||
431 | type TQV = CInt -> PQ -> IO CInt -- | ||
432 | type TQVQV = CInt -> PQ -> TQV -- | ||
433 | type TQVQVQV = CInt -> PQ -> TQVQV -- | ||
434 | type TQVF = CInt -> PQ -> TF -- | ||
435 | type TQM = CInt -> CInt -> PQ -> IO CInt -- | ||
436 | type TQMQM = CInt -> CInt -> PQ -> TQM -- | ||
437 | type TQMQMQM = CInt -> CInt -> PQ -> TQMQM -- | ||
438 | type TCMCV = CInt -> CInt -> PC -> TCV -- | ||
439 | type TVCV = CInt -> PD -> TCV -- | ||
440 | type TCVM = CInt -> PC -> TM -- | ||
441 | type TMCVM = CInt -> CInt -> PD -> TCVM -- | ||
442 | type TMMCVM = CInt -> CInt -> PD -> TMCVM -- | ||
443 | |||
diff --git a/packages/hmatrix/src/Numeric/IO.hs b/packages/hmatrix/src/Numeric/IO.hs index 836f352..58fa2b4 100644 --- a/packages/hmatrix/src/Numeric/IO.hs +++ b/packages/hmatrix/src/Numeric/IO.hs | |||
@@ -20,11 +20,12 @@ module Numeric.IO ( | |||
20 | ) where | 20 | ) where |
21 | 21 | ||
22 | import Data.Packed | 22 | import Data.Packed |
23 | import Data.Packed.Internal | 23 | import Data.Packed.Development |
24 | import System.Process(readProcess) | 24 | import System.Process(readProcess) |
25 | import Text.Printf(printf) | 25 | import Text.Printf(printf) |
26 | import Data.List(intersperse) | 26 | import Data.List(intersperse) |
27 | import Data.Complex | 27 | import Data.Complex |
28 | import Numeric.GSL.Vector | ||
28 | 29 | ||
29 | {- | Creates a string from a matrix given a separator and a function to show each entry. Using | 30 | {- | Creates a string from a matrix given a separator and a function to show each entry. Using |
30 | this function the user can easily define any desired display function: | 31 | this function the user can easily define any desired display function: |
diff --git a/packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs b/packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs index 8c4b610..0a6eaa1 100644 --- a/packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs +++ b/packages/hmatrix/src/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -79,8 +79,8 @@ module Numeric.LinearAlgebra.Algorithms ( | |||
79 | ) where | 79 | ) where |
80 | 80 | ||
81 | 81 | ||
82 | import Data.Packed.Internal hiding ((//)) | 82 | import Data.Packed.Development hiding ((//)) |
83 | import Data.Packed.Matrix | 83 | import Data.Packed |
84 | import Numeric.LinearAlgebra.LAPACK as LAPACK | 84 | import Numeric.LinearAlgebra.LAPACK as LAPACK |
85 | import Data.List(foldl1') | 85 | import Data.List(foldl1') |
86 | import Data.Array | 86 | import Data.Array |
diff --git a/packages/special/hmatrix-special.cabal b/packages/special/hmatrix-special.cabal index bcaed95..3d1cc2d 100644 --- a/packages/special/hmatrix-special.cabal +++ b/packages/special/hmatrix-special.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix-special | 1 | Name: hmatrix-special |
2 | Version: 0.2.0 | 2 | Version: 0.3.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -27,7 +27,7 @@ flag safe-cheap | |||
27 | default: False | 27 | default: False |
28 | 28 | ||
29 | library | 29 | library |
30 | Build-Depends: base >= 3 && < 5, hmatrix >= 0.9 | 30 | Build-Depends: base, hmatrix-base, hmatrix |
31 | 31 | ||
32 | Extensions: ForeignFunctionInterface, | 32 | Extensions: ForeignFunctionInterface, |
33 | CPP | 33 | CPP |
diff --git a/packages/tests/hmatrix-tests.cabal b/packages/tests/hmatrix-tests.cabal index 65254f4..7f77f4a 100644 --- a/packages/tests/hmatrix-tests.cabal +++ b/packages/tests/hmatrix-tests.cabal | |||
@@ -21,7 +21,7 @@ extra-source-files: CHANGES | |||
21 | library | 21 | library |
22 | 22 | ||
23 | Build-Depends: base >= 4 && < 5, | 23 | Build-Depends: base >= 4 && < 5, |
24 | hmatrix >= 0.16, | 24 | hmatrix >= 0.16, hmatrix-base, |
25 | QuickCheck >= 2, HUnit, random | 25 | QuickCheck >= 2, HUnit, random |
26 | 26 | ||
27 | hs-source-dirs: src | 27 | hs-source-dirs: src |