summaryrefslogtreecommitdiff
path: root/lib/GSLHaskell.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/GSLHaskell.hs')
-rw-r--r--lib/GSLHaskell.hs44
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
36import LAPACK
37import GSL.Integration 36import GSL.Integration
38import GSL.Differentiation 37import GSL.Differentiation
39import GSL.Fourier 38import GSL.Fourier
40import GSL.Polynomials 39import GSL.Polynomials
41import GSL.Minimization 40import GSL.Minimization
42import GSL.Matrix
43import Graphics.Plot 41import Graphics.Plot
44import Complex 42import Complex
45import GSL.Special(setErrorHandlerOff, 43import 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)
51import Data.Packed.Internal hiding (dsp) 49--import Data.Packed.Internal hiding (dsp,comp)
52import Data.Packed.Vector hiding (constant) 50import Data.Packed.Vector
53import Data.Packed.Matrix 51import Data.Packed.Matrix
54import Data.Packed.Matrix hiding ((><)) 52import Data.Packed.Matrix hiding ((><))
55import GSL.Vector 53import GSL.Vector
56import LinearAlgebra.Linear
57import qualified LinearAlgebra.Algorithms 54import qualified LinearAlgebra.Algorithms
55import LAPACK
56import GSL.Matrix
58import LinearAlgebra.Algorithms hiding (pnorm) 57import LinearAlgebra.Algorithms hiding (pnorm)
58import LinearAlgebra.Linear
59import Complex 59import Complex
60import Numeric(showGFloat) 60import Numeric(showGFloat)
61import Data.List(transpose,intersperse) 61import 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
71liftMatrix2' :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t 71liftMatrix2' :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t
72liftMatrix2' f m1 m2 | compat' m1 m2 = reshape (max (cols m1) (cols m2)) (f (cdat m1) (cdat m2)) 72liftMatrix2' 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
75compat' :: Matrix a -> Matrix b -> Bool 75compat' :: 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
91instance (Eq a, Field a) => Eq (Matrix a) where 91instance (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
94instance (Field a, Linear Vector a) => Num (Matrix a) where 94instance (Field a, Linear Vector a) => Num (Matrix a) where
95 (+) = liftMatrix2' (+) 95 (+) = liftMatrix2' (+)
@@ -377,9 +377,6 @@ size = dim
377gmap :: (Storable a, Storable b) => (a->b) -> Vector a -> Vector b 377gmap :: (Storable a, Storable b) => (a->b) -> Vector a -> Vector b
378gmap f v = liftVector f v 378gmap f v = liftVector f v
379 379
380constant :: Double -> Int -> Vector Double
381constant = constantR
382
383-- shows a Double with n digits after the decimal point 380-- shows a Double with n digits after the decimal point
384shf :: (RealFloat a) => Int -> a -> String 381shf :: (RealFloat a) => Int -> a -> String
385shf dec n | abs n < 1e-10 = "0." 382shf 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
477toComplexV :: (Vector Double, Vector Double) -> Vector (Complex Double)
478toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i]
479
480-- | extracts the real and imaginary parts of a complex vector
481fromComplexV :: Vector (Complex Double) -> (Vector Double, Vector Double)
482fromComplexV m = (a,b) where [a,b] = toColumns $ reshape 2 $ asReal m
483
484-- | creates a complex matrix from matrices with real and imaginary parts
485toComplexM :: (Matrix Double, Matrix Double) -> Matrix (Complex Double)
486toComplexM (r,i) = reshape (cols r) $ asComplex $ flatten $ fromColumns [flatten r, flatten i]
487
488-- | extracts the real and imaginary parts of a complex matrix
489fromComplexM :: Matrix (Complex Double) -> (Matrix Double, Matrix Double)
490fromComplexM m = (reshape c a, reshape c b)
491 where c = cols m
492 [a,b] = toColumns $ reshape 2 $ asReal $ flatten m
493
494fromComplex :: Matrix (Complex Double) -> (Matrix Double, Matrix Double)
495fromComplex = fromComplexM
496
497 473
498pnorm :: (Normed t1, Num t) => t -> t1 -> Double 474pnorm :: (Normed t1, Num t) => t -> t1 -> Double
499pnorm 0 = LinearAlgebra.Algorithms.pnorm Infinity 475pnorm 0 = LinearAlgebra.Algorithms.pnorm Infinity