summaryrefslogtreecommitdiff
path: root/lib/Numeric/Conversion.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-09-13 18:21:15 +0000
committerAlberto Ruiz <aruiz@um.es>2010-09-13 18:21:15 +0000
commit9d54e7b9543c22d398ef5097e3ba619ca974820b (patch)
treea71b00a450eb22224b389ad501806b92a6a09864 /lib/Numeric/Conversion.hs
parent5323b5f9c5da53ab413202141667142e646897d4 (diff)
remove ComplexContainer
Diffstat (limited to 'lib/Numeric/Conversion.hs')
-rw-r--r--lib/Numeric/Conversion.hs137
1 files changed, 15 insertions, 122 deletions
diff --git a/lib/Numeric/Conversion.hs b/lib/Numeric/Conversion.hs
index 809ac51..fbf608a 100644
--- a/lib/Numeric/Conversion.hs
+++ b/lib/Numeric/Conversion.hs
@@ -20,24 +20,15 @@
20----------------------------------------------------------------------------- 20-----------------------------------------------------------------------------
21 21
22module Numeric.Conversion ( 22module Numeric.Conversion (
23 RealElement, --Precision, 23 Complexable(..), RealElement,
24 ComplexContainer(toComplex,fromComplex,conj,comp),
25 Convert(..), --AutoReal(..),
26 RealOf, ComplexOf, SingleOf, DoubleOf,
27 module Data.Complex 24 module Data.Complex
28) where 25) where
29 26
30
31import Data.Packed.Internal.Vector 27import Data.Packed.Internal.Vector
32import Data.Packed.Internal.Matrix 28import Data.Packed.Internal.Matrix
33--import Numeric.GSL.Vector
34
35import Data.Complex 29import Data.Complex
36--import Control.Monad(ap)
37import Control.Arrow((***)) 30import Control.Arrow((***))
38 31
39--import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ)
40
41------------------------------------------------------------------- 32-------------------------------------------------------------------
42 33
43-- | Supported single-double precision type pairs 34-- | Supported single-double precision type pairs
@@ -60,24 +51,22 @@ class (Element t, Element (Complex t), RealFloat t
60 => RealElement t 51 => RealElement t
61 52
62instance RealElement Double 53instance RealElement Double
63
64instance RealElement Float 54instance RealElement Float
65 55
66-- | Conversion utilities 56
67class ComplexContainer c where 57-- | Structures that may contain complex numbers
68 toComplex :: (RealElement e) => (c e, c e) -> c (Complex e) 58class Complexable c where
69 fromComplex :: (RealElement e) => c (Complex e) -> (c e, c e) 59 toComplex' :: (RealElement e) => (c e, c e) -> c (Complex e)
70 comp :: (RealElement e) => c e -> c (Complex e) 60 fromComplex' :: (RealElement e) => c (Complex e) -> (c e, c e)
71 conj :: (RealElement e) => c (Complex e) -> c (Complex e) 61 comp' :: (RealElement e) => c e -> c (Complex e)
72 single' :: Precision a b => c b -> c a 62 single' :: Precision a b => c b -> c a
73 double' :: Precision a b => c a -> c b 63 double' :: Precision a b => c a -> c b
74 64
75 65
76instance ComplexContainer Vector where 66instance Complexable Vector where
77 toComplex = toComplexV 67 toComplex' = toComplexV
78 fromComplex = fromComplexV 68 fromComplex' = fromComplexV
79 comp v = toComplex (v,constantD 0 (dim v)) 69 comp' v = toComplex' (v,constantD 0 (dim v))
80 conj = conjugateD
81 single' = double2FloatG 70 single' = double2FloatG
82 double' = float2DoubleG 71 double' = float2DoubleG
83 72
@@ -92,107 +81,11 @@ fromComplexV z = (r,i) where
92 [r,i] = toColumns $ reshape 2 $ asReal z 81 [r,i] = toColumns $ reshape 2 $ asReal z
93 82
94 83
95instance ComplexContainer Matrix where 84instance Complexable Matrix where
96 toComplex = uncurry $ liftMatrix2 $ curry toComplex 85 toComplex' = uncurry $ liftMatrix2 $ curry toComplex'
97 fromComplex z = (reshape c *** reshape c) . fromComplex . flatten $ z 86 fromComplex' z = (reshape c *** reshape c) . fromComplex' . flatten $ z
98 where c = cols z 87 where c = cols z
99 comp = liftMatrix comp 88 comp' = liftMatrix comp'
100 conj = liftMatrix conj
101 single' = liftMatrix single' 89 single' = liftMatrix single'
102 double' = liftMatrix double' 90 double' = liftMatrix double'
103 91
104-------------------------------------------------------------------
105
106type family RealOf x
107
108type instance RealOf Double = Double
109type instance RealOf (Complex Double) = Double
110
111type instance RealOf Float = Float
112type instance RealOf (Complex Float) = Float
113
114type family ComplexOf x
115
116type instance ComplexOf Double = Complex Double
117type instance ComplexOf (Complex Double) = Complex Double
118
119type instance ComplexOf Float = Complex Float
120type instance ComplexOf (Complex Float) = Complex Float
121
122type family SingleOf x
123
124type instance SingleOf Double = Float
125type instance SingleOf Float = Float
126
127type instance SingleOf (Complex a) = Complex (SingleOf a)
128
129type family DoubleOf x
130
131type instance DoubleOf Double = Double
132type instance DoubleOf Float = Double
133
134type instance DoubleOf (Complex a) = Complex (DoubleOf a)
135
136type family ElementOf c
137
138type instance ElementOf (Vector a) = a
139type instance ElementOf (Matrix a) = a
140
141
142-------------------------------------------------------------------
143
144class (Element t, Element (RealOf t)) => Convert t where
145 real :: ComplexContainer c => c (RealOf t) -> c t
146 complex :: ComplexContainer c => c t -> c (ComplexOf t)
147 single :: ComplexContainer c => c t -> c (SingleOf t)
148 double :: ComplexContainer c => c t -> c (DoubleOf t)
149
150
151instance Convert Double where
152 real = id
153 complex = comp
154 single = single'
155 double = id
156
157instance Convert Float where
158 real = id
159 complex = comp
160 single = id
161 double = double'
162
163instance Convert (Complex Double) where
164 real = comp
165 complex = id
166 single = single'
167 double = id
168
169instance Convert (Complex Float) where
170 real = comp
171 complex = id
172 single = id
173 double = double'
174
175-------------------------------------------------------------------
176
177-- | to be replaced by Convert
178class Convert t => AutoReal t where
179 real'' :: ComplexContainer c => c Double -> c t
180 complex'' :: ComplexContainer c => c t -> c (Complex Double)
181
182
183instance AutoReal Double where
184 real'' = real
185 complex'' = complex
186
187instance AutoReal (Complex Double) where
188 real'' = real
189 complex'' = complex
190
191instance AutoReal Float where
192 real'' = real . single
193 complex'' = double . complex
194
195instance AutoReal (Complex Float) where
196 real'' = real . single
197 complex'' = double . complex
198