diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-05-12 06:15:35 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-05-12 06:15:35 +0000 |
commit | ff8ba85a52acdd1e30f45ba73ae0c40986c8a9d4 (patch) | |
tree | 1c4ac1d9256a687817633fea426261d6a18ecc31 /lib/Data/Packed.hs | |
parent | aa8debb5ab389de7bc5b47c5ae5f038349b6efc1 (diff) |
more simplification
Diffstat (limited to 'lib/Data/Packed.hs')
-rw-r--r-- | lib/Data/Packed.hs | 54 |
1 files changed, 3 insertions, 51 deletions
diff --git a/lib/Data/Packed.hs b/lib/Data/Packed.hs index 7d6d200..87695ee 100644 --- a/lib/Data/Packed.hs +++ b/lib/Data/Packed.hs | |||
@@ -1,4 +1,3 @@ | |||
1 | {-# OPTIONS_GHC -fglasgow-exts #-} | ||
2 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
3 | {- | | 2 | {- | |
4 | Module : Data.Packed | 3 | Module : Data.Packed |
@@ -17,59 +16,12 @@ The Vector and Matrix types and some utilities. | |||
17 | module Data.Packed ( | 16 | module Data.Packed ( |
18 | module Data.Packed.Vector, | 17 | module Data.Packed.Vector, |
19 | module Data.Packed.Matrix, | 18 | module Data.Packed.Matrix, |
20 | module Data.Complex, | 19 | module Data.Packed.Random, |
21 | Container(..) | 20 | module Data.Complex |
22 | ) where | 21 | ) where |
23 | 22 | ||
24 | import Data.Packed.Vector | 23 | import Data.Packed.Vector |
25 | import Data.Packed.Matrix | 24 | import Data.Packed.Matrix |
25 | import Data.Packed.Random | ||
26 | import Data.Complex | 26 | import Data.Complex |
27 | import Data.Packed.Internal(fromComplex,toComplex,conj) | ||
28 | 27 | ||
29 | -- | conversion utilities | ||
30 | class (Element e) => Container c e where | ||
31 | toComplex :: RealFloat e => (c e, c e) -> c (Complex e) | ||
32 | fromComplex :: RealFloat e => c (Complex e) -> (c e, c e) | ||
33 | comp :: RealFloat e => c e -> c (Complex e) | ||
34 | conj :: RealFloat e => c (Complex e) -> c (Complex e) | ||
35 | real :: c Double -> c e | ||
36 | complex :: c e -> c (Complex Double) | ||
37 | |||
38 | instance Container Vector Double where | ||
39 | toComplex = Data.Packed.Internal.toComplex | ||
40 | fromComplex = Data.Packed.Internal.fromComplex | ||
41 | comp = internalcomp | ||
42 | conj = Data.Packed.Internal.conj | ||
43 | real = id | ||
44 | complex = Data.Packed.comp | ||
45 | |||
46 | instance Container Vector (Complex Double) where | ||
47 | toComplex = undefined -- can't match | ||
48 | fromComplex = undefined | ||
49 | comp = undefined | ||
50 | conj = undefined | ||
51 | real = Data.Packed.comp | ||
52 | complex = id | ||
53 | |||
54 | instance Container Matrix Double where | ||
55 | toComplex = uncurry $ liftMatrix2 $ curry Data.Packed.toComplex | ||
56 | fromComplex z = (reshape c r, reshape c i) | ||
57 | where (r,i) = Data.Packed.fromComplex (flatten z) | ||
58 | c = cols z | ||
59 | comp = liftMatrix internalcomp | ||
60 | conj = liftMatrix Data.Packed.Internal.conj | ||
61 | real = id | ||
62 | complex = Data.Packed.comp | ||
63 | |||
64 | instance Container Matrix (Complex Double) where | ||
65 | toComplex = undefined | ||
66 | fromComplex = undefined | ||
67 | comp = undefined | ||
68 | conj = undefined | ||
69 | real = Data.Packed.comp | ||
70 | complex = id | ||
71 | |||
72 | |||
73 | -- | converts a real vector into a complex representation (with zero imaginary parts) | ||
74 | internalcomp :: Vector Double -> Vector (Complex Double) | ||
75 | internalcomp v = Data.Packed.Internal.toComplex (v,constant 0 (dim v)) | ||