diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-09-14 11:06:57 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-09-14 11:06:57 +0000 |
commit | 9e2f7fb0ca902665b430a96f77959522976a97f9 (patch) | |
tree | c2f258fe28df79a645f3908655b46fbaf89ecf16 /lib | |
parent | 620d5008ea9a931a91907cd0c902bb64f005121f (diff) |
code refactoring
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 2 | ||||
-rw-r--r-- | lib/Data/Packed/Vector.hs | 15 | ||||
-rw-r--r-- | lib/GSL.hs | 36 | ||||
-rw-r--r-- | lib/GSLHaskell.hs (renamed from lib/GSL/Compat.hs) | 58 | ||||
-rw-r--r-- | lib/Graphics/Plot.hs (renamed from lib/Data/Packed/Plot.hs) | 4 | ||||
-rw-r--r-- | lib/LinearAlgebra/Linear.hs | 4 |
6 files changed, 66 insertions, 53 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index f9dd9a9..89a162a 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -171,7 +171,7 @@ compat m1 m2 = rows m1 == rows m2 && cols m1 == cols m2 | |||
171 | ---------------------------------------------------------------- | 171 | ---------------------------------------------------------------- |
172 | 172 | ||
173 | -- | Optimized matrix computations are provided for elements in the Field class. | 173 | -- | Optimized matrix computations are provided for elements in the Field class. |
174 | class Storable a => Field a where | 174 | class (Storable a, Num a) => Field a where |
175 | constantD :: a -> Int -> Vector a | 175 | constantD :: a -> Int -> Vector a |
176 | transdata :: Int -> Vector a -> Int -> Vector a | 176 | transdata :: Int -> Vector a -> Int -> Vector a |
177 | multiplyD :: Matrix a -> Matrix a -> Matrix a | 177 | multiplyD :: Matrix a -> Matrix a -> Matrix a |
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs index 9818d58..3fc625c 100644 --- a/lib/Data/Packed/Vector.hs +++ b/lib/Data/Packed/Vector.hs | |||
@@ -18,12 +18,13 @@ module Data.Packed.Vector ( | |||
18 | dim, (@>), | 18 | dim, (@>), |
19 | subVector, join, | 19 | subVector, join, |
20 | constant, linspace, | 20 | constant, linspace, |
21 | 21 | vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex, | |
22 | liftVector, liftVector2 | 22 | liftVector, liftVector2 |
23 | ) where | 23 | ) where |
24 | 24 | ||
25 | import Data.Packed.Internal | 25 | import Data.Packed.Internal |
26 | import Complex | 26 | import Complex |
27 | import GSL.Vector | ||
27 | 28 | ||
28 | {- | Creates a real vector containing a range of values: | 29 | {- | Creates a real vector containing a range of values: |
29 | 30 | ||
@@ -33,3 +34,15 @@ import Complex | |||
33 | linspace :: Int -> (Double, Double) -> Vector Double | 34 | linspace :: Int -> (Double, Double) -> Vector Double |
34 | linspace n (a,b) = fromList [a, a+delta .. b] | 35 | linspace n (a,b) = fromList [a, a+delta .. b] |
35 | where delta = (b-a)/(fromIntegral n -1) | 36 | where delta = (b-a)/(fromIntegral n -1) |
37 | |||
38 | vectorMax :: Vector Double -> Double | ||
39 | vectorMax = toScalarR Max | ||
40 | |||
41 | vectorMin :: Vector Double -> Double | ||
42 | vectorMin = toScalarR Min | ||
43 | |||
44 | vectorMaxIndex :: Vector Double -> Int | ||
45 | vectorMaxIndex = round . toScalarR MaxIdx | ||
46 | |||
47 | vectorMinIndex :: Vector Double -> Int | ||
48 | vectorMinIndex = round . toScalarR MinIdx | ||
@@ -8,43 +8,25 @@ Maintainer : Alberto Ruiz (aruiz at um dot es) | |||
8 | Stability : provisional | 8 | Stability : provisional |
9 | Portability : uses -fffi and -fglasgow-exts | 9 | Portability : uses -fffi and -fglasgow-exts |
10 | 10 | ||
11 | This module reexports the basic functionality and a collection of utilities (old interface) | 11 | This module reexports all the GSL functions (except those in "LinearAlgebra"). |
12 | 12 | ||
13 | -} | 13 | -} |
14 | 14 | ||
15 | module GSL ( | 15 | module GSL ( |
16 | 16 | module GSL.Integration | |
17 | module Data.Packed.Vector, | 17 | , module GSL.Differentiation |
18 | module Data.Packed.Matrix, | 18 | , module GSL.Fourier |
19 | --module Data.Packed.Tensor, | 19 | , module GSL.Polynomials |
20 | module LinearAlgebra.Algorithms, | 20 | , module GSL.Minimization |
21 | module LAPACK, | 21 | , module GSL.Special |
22 | module GSL.Integration, | 22 | , module Complex |
23 | module GSL.Differentiation, | ||
24 | module GSL.Fourier, | ||
25 | module GSL.Polynomials, | ||
26 | module GSL.Minimization, | ||
27 | module GSL.Matrix, | ||
28 | module GSL.Compat, | ||
29 | module Data.Packed.Plot, | ||
30 | module Complex, | ||
31 | |||
32 | setErrorHandlerOff | ||
33 | |||
34 | ) where | 23 | ) where |
35 | 24 | ||
36 | import Data.Packed.Vector hiding (constant) | ||
37 | import Data.Packed.Matrix hiding ((><)) | ||
38 | import LinearAlgebra.Algorithms hiding (pnorm) | ||
39 | import LAPACK | ||
40 | import GSL.Integration | 25 | import GSL.Integration |
41 | import GSL.Differentiation | 26 | import GSL.Differentiation |
42 | import GSL.Special | 27 | import GSL.Special |
43 | import GSL.Fourier | 28 | import GSL.Fourier |
44 | import GSL.Polynomials | 29 | import GSL.Polynomials |
45 | import GSL.Minimization | 30 | import GSL.Minimization |
46 | import GSL.Matrix | ||
47 | import GSL.Compat | ||
48 | import Data.Packed.Plot | ||
49 | import Complex | 31 | import Complex |
50 | import GSL.Special(setErrorHandlerOff) | 32 | import GSL.Special |
diff --git a/lib/GSL/Compat.hs b/lib/GSLHaskell.hs index 8a59915..e65ff28 100644 --- a/lib/GSL/Compat.hs +++ b/lib/GSLHaskell.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} | 1 | {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} |
2 | ----------------------------------------------------------------------------- | 2 | ----------------------------------------------------------------------------- |
3 | {- | | 3 | {- | |
4 | Module : GSL.Compat | 4 | Module : GSLHaskell |
5 | Copyright : (c) Alberto Ruiz 2006 | 5 | Copyright : (c) Alberto Ruiz 2006 |
6 | License : GPL-style | 6 | License : GPL-style |
7 | 7 | ||
@@ -9,23 +9,53 @@ Maintainer : Alberto Ruiz (aruiz at um dot es) | |||
9 | Stability : provisional | 9 | Stability : provisional |
10 | Portability : uses -fffi and -fglasgow-exts | 10 | Portability : uses -fffi and -fglasgow-exts |
11 | 11 | ||
12 | Creates reasonable numeric instances for Vectors and Matrices. In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. | 12 | GSLHaskell interface, with reasonable numeric instances for Vectors and Matrices. In the context of the standard numeric operators, one-component vectors and matrices automatically expand to match the dimensions of the other operand. |
13 | 13 | ||
14 | -} | 14 | -} |
15 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
16 | 16 | ||
17 | module GSL.Compat( | 17 | module GSLHaskell( |
18 | Mul,(<>), readMatrix, size, dispR, dispC, format, gmap, Joinable, (<|>),(<->), GSL.Compat.constant, | 18 | module Data.Packed.Vector, |
19 | vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex, fromArray2D, fromComplex, GSL.Compat.pnorm, scale | 19 | module Data.Packed.Matrix, |
20 | module LinearAlgebra.Algorithms, | ||
21 | module LAPACK, | ||
22 | module GSL.Integration, | ||
23 | module GSL.Differentiation, | ||
24 | module GSL.Fourier, | ||
25 | module GSL.Polynomials, | ||
26 | module GSL.Minimization, | ||
27 | module GSL.Matrix, | ||
28 | module GSL.Special, | ||
29 | module Graphics.Plot, | ||
30 | module Complex, | ||
31 | Mul,(<>), readMatrix, size, dispR, dispC, format, gmap, Joinable, (<|>),(<->), GSLHaskell.constant, | ||
32 | fromArray2D, fromComplex, toComplex, GSLHaskell.pnorm, scale, outer | ||
20 | ) where | 33 | ) where |
21 | 34 | ||
35 | |||
36 | import LAPACK | ||
37 | import GSL.Integration | ||
38 | import GSL.Differentiation | ||
39 | import GSL.Fourier | ||
40 | import GSL.Polynomials | ||
41 | import GSL.Minimization | ||
42 | import GSL.Matrix | ||
43 | import Graphics.Plot | ||
44 | import Complex | ||
45 | import GSL.Special(setErrorHandlerOff, | ||
46 | erf, | ||
47 | erf_Z, | ||
48 | bessel_J0_e, | ||
49 | exp_e10_e, | ||
50 | gamma) | ||
22 | import Data.Packed.Internal hiding (dsp) | 51 | import Data.Packed.Internal hiding (dsp) |
23 | import Data.Packed.Vector | 52 | import Data.Packed.Vector hiding (constant) |
24 | import Data.Packed.Matrix | 53 | import Data.Packed.Matrix |
54 | import Data.Packed.Matrix hiding ((><)) | ||
25 | import GSL.Vector | 55 | import GSL.Vector |
26 | import LinearAlgebra.Linear | 56 | import LinearAlgebra.Linear |
27 | import GSL.Matrix | 57 | import qualified LinearAlgebra.Algorithms |
28 | import LinearAlgebra.Algorithms | 58 | import LinearAlgebra.Algorithms hiding (pnorm) |
29 | import Complex | 59 | import Complex |
30 | import Numeric(showGFloat) | 60 | import Numeric(showGFloat) |
31 | import Data.List(transpose,intersperse) | 61 | import Data.List(transpose,intersperse) |
@@ -437,18 +467,6 @@ a <-> b = joinV a b | |||
437 | 467 | ||
438 | ---------------------------------------------------------- | 468 | ---------------------------------------------------------- |
439 | 469 | ||
440 | vectorMax :: Vector Double -> Double | ||
441 | vectorMax = toScalarR Max | ||
442 | |||
443 | vectorMin :: Vector Double -> Double | ||
444 | vectorMin = toScalarR Min | ||
445 | |||
446 | vectorMaxIndex :: Vector Double -> Int | ||
447 | vectorMaxIndex = round . toScalarR MaxIdx | ||
448 | |||
449 | vectorMinIndex :: Vector Double -> Int | ||
450 | vectorMinIndex = round . toScalarR MinIdx | ||
451 | |||
452 | fromArray2D :: (Field e) => Array (Int, Int) e -> Matrix e | 470 | fromArray2D :: (Field e) => Array (Int, Int) e -> Matrix e |
453 | fromArray2D m = (r><c) (elems m) | 471 | fromArray2D m = (r><c) (elems m) |
454 | where ((r0,c0),(r1,c1)) = bounds m | 472 | where ((r0,c0),(r1,c1)) = bounds m |
diff --git a/lib/Data/Packed/Plot.hs b/lib/Graphics/Plot.hs index 7d63426..9f719ab 100644 --- a/lib/Data/Packed/Plot.hs +++ b/lib/Graphics/Plot.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Data.Packed.Plot | 3 | -- Module : Graphics.Plot |
4 | -- Copyright : (c) Alberto Ruiz 2005 | 4 | -- Copyright : (c) Alberto Ruiz 2005 |
5 | -- License : GPL-style | 5 | -- License : GPL-style |
6 | -- | 6 | -- |
@@ -12,7 +12,7 @@ | |||
12 | -- | 12 | -- |
13 | ----------------------------------------------------------------------------- | 13 | ----------------------------------------------------------------------------- |
14 | 14 | ||
15 | module Data.Packed.Plot( | 15 | module Graphics.Plot( |
16 | 16 | ||
17 | gnuplotX, mplot, | 17 | gnuplotX, mplot, |
18 | 18 | ||
diff --git a/lib/LinearAlgebra/Linear.hs b/lib/LinearAlgebra/Linear.hs index 51b32f5..53e011f 100644 --- a/lib/LinearAlgebra/Linear.hs +++ b/lib/LinearAlgebra/Linear.hs | |||
@@ -27,7 +27,7 @@ import GSL.Vector | |||
27 | import Complex | 27 | import Complex |
28 | 28 | ||
29 | 29 | ||
30 | class (Num e, Field e) => Linear c e where | 30 | class (Field e) => Linear c e where |
31 | scale :: e -> c e -> c e | 31 | scale :: e -> c e -> c e |
32 | addConstant :: e -> c e -> c e | 32 | addConstant :: e -> c e -> c e |
33 | add :: c e -> c e -> c e | 33 | add :: c e -> c e -> c e |
@@ -68,5 +68,5 @@ dot u v = dat (multiply r c) `at` 0 | |||
68 | , 10.0, 4.0, 6.0 | 68 | , 10.0, 4.0, 6.0 |
69 | , 15.0, 6.0, 9.0 ]@ | 69 | , 15.0, 6.0, 9.0 ]@ |
70 | -} | 70 | -} |
71 | outer :: (Num t, Field t) => Vector t -> Vector t -> Matrix t | 71 | outer :: (Field t) => Vector t -> Vector t -> Matrix t |
72 | outer u v = asColumn u `multiply` asRow v | 72 | outer u v = asColumn u `multiply` asRow v |