diff options
Diffstat (limited to 'lib/GSLHaskell.hs')
-rw-r--r-- | lib/GSLHaskell.hs | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/lib/GSLHaskell.hs b/lib/GSLHaskell.hs index e65ff28..3158458 100644 --- a/lib/GSLHaskell.hs +++ b/lib/GSLHaskell.hs | |||
@@ -18,6 +18,7 @@ module GSLHaskell( | |||
18 | module Data.Packed.Vector, | 18 | module Data.Packed.Vector, |
19 | module Data.Packed.Matrix, | 19 | module Data.Packed.Matrix, |
20 | module LinearAlgebra.Algorithms, | 20 | module LinearAlgebra.Algorithms, |
21 | module LinearAlgebra.Linear, | ||
21 | module LAPACK, | 22 | module LAPACK, |
22 | module GSL.Integration, | 23 | module GSL.Integration, |
23 | module GSL.Differentiation, | 24 | module GSL.Differentiation, |
@@ -28,18 +29,15 @@ module GSLHaskell( | |||
28 | module GSL.Special, | 29 | module GSL.Special, |
29 | module Graphics.Plot, | 30 | module Graphics.Plot, |
30 | module Complex, | 31 | module Complex, |
31 | Mul,(<>), readMatrix, size, dispR, dispC, format, gmap, Joinable, (<|>),(<->), GSLHaskell.constant, | 32 | Mul,(<>), readMatrix, size, dispR, dispC, format, gmap, Joinable, (<|>),(<->), |
32 | fromArray2D, fromComplex, toComplex, GSLHaskell.pnorm, scale, outer | 33 | fromArray2D, GSLHaskell.pnorm, |
33 | ) where | 34 | ) where |
34 | 35 | ||
35 | |||
36 | import LAPACK | ||
37 | import GSL.Integration | 36 | import GSL.Integration |
38 | import GSL.Differentiation | 37 | import GSL.Differentiation |
39 | import GSL.Fourier | 38 | import GSL.Fourier |
40 | import GSL.Polynomials | 39 | import GSL.Polynomials |
41 | import GSL.Minimization | 40 | import GSL.Minimization |
42 | import GSL.Matrix | ||
43 | import Graphics.Plot | 41 | import Graphics.Plot |
44 | import Complex | 42 | import Complex |
45 | import GSL.Special(setErrorHandlerOff, | 43 | import GSL.Special(setErrorHandlerOff, |
@@ -48,14 +46,16 @@ import GSL.Special(setErrorHandlerOff, | |||
48 | bessel_J0_e, | 46 | bessel_J0_e, |
49 | exp_e10_e, | 47 | exp_e10_e, |
50 | gamma) | 48 | gamma) |
51 | import Data.Packed.Internal hiding (dsp) | 49 | --import Data.Packed.Internal hiding (dsp,comp) |
52 | import Data.Packed.Vector hiding (constant) | 50 | import Data.Packed.Vector |
53 | import Data.Packed.Matrix | 51 | import Data.Packed.Matrix |
54 | import Data.Packed.Matrix hiding ((><)) | 52 | import Data.Packed.Matrix hiding ((><)) |
55 | import GSL.Vector | 53 | import GSL.Vector |
56 | import LinearAlgebra.Linear | ||
57 | import qualified LinearAlgebra.Algorithms | 54 | import qualified LinearAlgebra.Algorithms |
55 | import LAPACK | ||
56 | import GSL.Matrix | ||
58 | import LinearAlgebra.Algorithms hiding (pnorm) | 57 | import LinearAlgebra.Algorithms hiding (pnorm) |
58 | import LinearAlgebra.Linear | ||
59 | import Complex | 59 | import Complex |
60 | import Numeric(showGFloat) | 60 | import Numeric(showGFloat) |
61 | import Data.List(transpose,intersperse) | 61 | import Data.List(transpose,intersperse) |
@@ -69,7 +69,7 @@ adaptScalar f1 f2 f3 x y | |||
69 | | otherwise = f2 x y | 69 | | otherwise = f2 x y |
70 | 70 | ||
71 | liftMatrix2' :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t | 71 | liftMatrix2' :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t |
72 | liftMatrix2' f m1 m2 | compat' m1 m2 = reshape (max (cols m1) (cols m2)) (f (cdat m1) (cdat m2)) | 72 | liftMatrix2' f m1 m2 | compat' m1 m2 = reshape (max (cols m1) (cols m2)) (f (flatten m1) (flatten m2)) |
73 | | otherwise = error "nonconformant matrices in liftMatrix2'" | 73 | | otherwise = error "nonconformant matrices in liftMatrix2'" |
74 | 74 | ||
75 | compat' :: Matrix a -> Matrix b -> Bool | 75 | compat' :: Matrix a -> Matrix b -> Bool |
@@ -89,7 +89,7 @@ instance (Linear Vector a) => Num (Vector a) where | |||
89 | fromInteger = fromList . return . fromInteger | 89 | fromInteger = fromList . return . fromInteger |
90 | 90 | ||
91 | instance (Eq a, Field a) => Eq (Matrix a) where | 91 | instance (Eq a, Field a) => Eq (Matrix a) where |
92 | a == b = rows a == rows b && cols a == cols b && cdat a == cdat b && fdat a == fdat b | 92 | a == b = cols a == cols b && flatten a == flatten b |
93 | 93 | ||
94 | instance (Field a, Linear Vector a) => Num (Matrix a) where | 94 | instance (Field a, Linear Vector a) => Num (Matrix a) where |
95 | (+) = liftMatrix2' (+) | 95 | (+) = liftMatrix2' (+) |
@@ -377,9 +377,6 @@ size = dim | |||
377 | gmap :: (Storable a, Storable b) => (a->b) -> Vector a -> Vector b | 377 | gmap :: (Storable a, Storable b) => (a->b) -> Vector a -> Vector b |
378 | gmap f v = liftVector f v | 378 | gmap f v = liftVector f v |
379 | 379 | ||
380 | constant :: Double -> Int -> Vector Double | ||
381 | constant = constantR | ||
382 | |||
383 | -- shows a Double with n digits after the decimal point | 380 | -- shows a Double with n digits after the decimal point |
384 | shf :: (RealFloat a) => Int -> a -> String | 381 | shf :: (RealFloat a) => Int -> a -> String |
385 | shf dec n | abs n < 1e-10 = "0." | 382 | shf dec n | abs n < 1e-10 = "0." |
@@ -473,27 +470,6 @@ fromArray2D m = (r><c) (elems m) | |||
473 | r = r1-r0+1 | 470 | r = r1-r0+1 |
474 | c = c1-c0+1 | 471 | c = c1-c0+1 |
475 | 472 | ||
476 | -- | creates a complex vector from vectors with real and imaginary parts | ||
477 | toComplexV :: (Vector Double, Vector Double) -> Vector (Complex Double) | ||
478 | toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i] | ||
479 | |||
480 | -- | extracts the real and imaginary parts of a complex vector | ||
481 | fromComplexV :: Vector (Complex Double) -> (Vector Double, Vector Double) | ||
482 | fromComplexV m = (a,b) where [a,b] = toColumns $ reshape 2 $ asReal m | ||
483 | |||
484 | -- | creates a complex matrix from matrices with real and imaginary parts | ||
485 | toComplexM :: (Matrix Double, Matrix Double) -> Matrix (Complex Double) | ||
486 | toComplexM (r,i) = reshape (cols r) $ asComplex $ flatten $ fromColumns [flatten r, flatten i] | ||
487 | |||
488 | -- | extracts the real and imaginary parts of a complex matrix | ||
489 | fromComplexM :: Matrix (Complex Double) -> (Matrix Double, Matrix Double) | ||
490 | fromComplexM m = (reshape c a, reshape c b) | ||
491 | where c = cols m | ||
492 | [a,b] = toColumns $ reshape 2 $ asReal $ flatten m | ||
493 | |||
494 | fromComplex :: Matrix (Complex Double) -> (Matrix Double, Matrix Double) | ||
495 | fromComplex = fromComplexM | ||
496 | |||
497 | 473 | ||
498 | pnorm :: (Normed t1, Num t) => t -> t1 -> Double | 474 | pnorm :: (Normed t1, Num t) => t -> t1 -> Double |
499 | pnorm 0 = LinearAlgebra.Algorithms.pnorm Infinity | 475 | pnorm 0 = LinearAlgebra.Algorithms.pnorm Infinity |