summaryrefslogtreecommitdiff
path: root/lib/Numeric/Container.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-09-06 07:37:18 +0000
committerAlberto Ruiz <aruiz@um.es>2010-09-06 07:37:18 +0000
commit29099e3bfb4eec87ac3d4d675d7cfc82234c20d6 (patch)
tree82124829d5e2a51e1b272430cee2617b7e182e0e /lib/Numeric/Container.hs
parentfa4e2233a873bbfee26939c013b56acc160bca7b (diff)
working on conversion / linear
Diffstat (limited to 'lib/Numeric/Container.hs')
-rw-r--r--lib/Numeric/Container.hs51
1 files changed, 21 insertions, 30 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index 0bec2e8..010235f 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -19,10 +19,14 @@
19----------------------------------------------------------------------------- 19-----------------------------------------------------------------------------
20 20
21module Numeric.Container ( 21module Numeric.Container (
22 RealElement, AutoReal(..), 22 Container(..), RealElement, Precision, NumericContainer(..), comp,
23 Container(..), Linear(..), 23 Convert(..), AutoReal(..),
24 Convert(..), RealOf, ComplexOf, SingleOf, DoubleOf, ElementOf, IndexOf, 24 RealOf, ComplexOf, SingleOf, DoubleOf,
25 Precision(..), comp, 25
26-- ElementOf,
27
28 IndexOf,
29
26 module Data.Complex 30 module Data.Complex
27) where 31) where
28 32
@@ -62,7 +66,7 @@ instance RealElement Double
62instance RealElement Float 66instance RealElement Float
63 67
64-- | Conversion utilities 68-- | Conversion utilities
65class Container c where 69class NumericContainer c where
66 toComplex :: (RealElement e) => (c e, c e) -> c (Complex e) 70 toComplex :: (RealElement e) => (c e, c e) -> c (Complex e)
67 fromComplex :: (RealElement e) => c (Complex e) -> (c e, c e) 71 fromComplex :: (RealElement e) => c (Complex e) -> (c e, c e)
68 complex' :: (RealElement e) => c e -> c (Complex e) 72 complex' :: (RealElement e) => c e -> c (Complex e)
@@ -71,9 +75,11 @@ class Container c where
71 single' :: Precision a b => c b -> c a 75 single' :: Precision a b => c b -> c a
72 double' :: Precision a b => c a -> c b 76 double' :: Precision a b => c a -> c b
73 77
78-- | a synonym for "complex'"
79comp :: (NumericContainer c, RealElement e) => c e -> c (Complex e)
74comp x = complex' x 80comp x = complex' x
75 81
76instance Container Vector where 82instance NumericContainer Vector where
77 toComplex = toComplexV 83 toComplex = toComplexV
78 fromComplex = fromComplexV 84 fromComplex = fromComplexV
79 complex' v = toComplex (v,constantD 0 (dim v)) 85 complex' v = toComplex (v,constantD 0 (dim v))
@@ -82,7 +88,7 @@ instance Container Vector where
82 single' = double2FloatG 88 single' = double2FloatG
83 double' = float2DoubleG 89 double' = float2DoubleG
84 90
85instance Container Matrix where 91instance NumericContainer Matrix where
86 toComplex = uncurry $ liftMatrix2 $ curry toComplex 92 toComplex = uncurry $ liftMatrix2 $ curry toComplex
87 fromComplex z = (reshape c *** reshape c) . fromComplex . flatten $ z 93 fromComplex z = (reshape c *** reshape c) . fromComplex . flatten $ z
88 where c = cols z 94 where c = cols z
@@ -138,10 +144,10 @@ type instance IndexOf Matrix = (Int,Int)
138 144
139-- | generic conversion functions 145-- | generic conversion functions
140class Convert t where 146class Convert t where
141 real :: Container c => c (RealOf t) -> c t 147 real :: NumericContainer c => c (RealOf t) -> c t
142 complex :: Container c => c t -> c (ComplexOf t) 148 complex :: NumericContainer c => c t -> c (ComplexOf t)
143 single :: Container c => c t -> c (SingleOf t) 149 single :: NumericContainer c => c t -> c (SingleOf t)
144 double :: Container c => c t -> c (DoubleOf t) 150 double :: NumericContainer c => c t -> c (DoubleOf t)
145 151
146instance Convert Double where 152instance Convert Double where
147 real = id 153 real = id
@@ -171,8 +177,8 @@ instance Convert (Complex Float) where
171 177
172-- | to be replaced by Convert 178-- | to be replaced by Convert
173class Convert t => AutoReal t where 179class Convert t => AutoReal t where
174 real'' :: Container c => c Double -> c t 180 real'' :: NumericContainer c => c Double -> c t
175 complex'' :: Container c => c t -> c (Complex Double) 181 complex'' :: NumericContainer c => c t -> c (Complex Double)
176 182
177instance AutoReal Double where 183instance AutoReal Double where
178 real'' = real 184 real'' = real
@@ -193,23 +199,7 @@ instance AutoReal (Complex Float) where
193------------------------------------------------------------------- 199-------------------------------------------------------------------
194 200
195-- | Basic element-by-element functions. 201-- | Basic element-by-element functions.
196class (Element e, Container c) => Linear c e where 202class (Element e) => Container c e where
197 -- | create a structure with a single element
198 scalar :: e -> c e
199 scale :: e -> c e -> c e
200 -- | scale the element by element reciprocal of the object:
201 --
202 -- @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@
203 scaleRecip :: e -> c e -> c e
204 addConstant :: e -> c e -> c e
205 add :: c e -> c e -> c e
206 sub :: c e -> c e -> c e
207 -- | element by element multiplication
208 mul :: c e -> c e -> c e
209 -- | element by element division
210 divide :: c e -> c e -> c e
211 equal :: c e -> c e -> Bool
212 --
213 minIndex :: c e -> IndexOf c 203 minIndex :: c e -> IndexOf c
214 maxIndex :: c e -> IndexOf c 204 maxIndex :: c e -> IndexOf c
215 minElement :: c e -> e 205 minElement :: c e -> e
@@ -217,3 +207,4 @@ class (Element e, Container c) => Linear c e where
217 207
218 208
219 209
210