diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-09-06 07:37:18 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-09-06 07:37:18 +0000 |
commit | 29099e3bfb4eec87ac3d4d675d7cfc82234c20d6 (patch) | |
tree | 82124829d5e2a51e1b272430cee2617b7e182e0e /lib/Numeric | |
parent | fa4e2233a873bbfee26939c013b56acc160bca7b (diff) |
working on conversion / linear
Diffstat (limited to 'lib/Numeric')
-rw-r--r-- | lib/Numeric/Container.hs | 51 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra.hs | 6 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 2 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 72 | ||||
-rw-r--r-- | lib/Numeric/Matrix.hs | 9 | ||||
-rw-r--r-- | lib/Numeric/Vector.hs | 48 |
6 files changed, 108 insertions, 80 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 | ||
21 | module Numeric.Container ( | 21 | module 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 | |||
62 | instance RealElement Float | 66 | instance RealElement Float |
63 | 67 | ||
64 | -- | Conversion utilities | 68 | -- | Conversion utilities |
65 | class Container c where | 69 | class 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'" | ||
79 | comp :: (NumericContainer c, RealElement e) => c e -> c (Complex e) | ||
74 | comp x = complex' x | 80 | comp x = complex' x |
75 | 81 | ||
76 | instance Container Vector where | 82 | instance 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 | ||
85 | instance Container Matrix where | 91 | instance 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 |
140 | class Convert t where | 146 | class 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 | ||
146 | instance Convert Double where | 152 | instance 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 |
173 | class Convert t => AutoReal t where | 179 | class 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 | ||
177 | instance AutoReal Double where | 183 | instance 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. |
196 | class (Element e, Container c) => Linear c e where | 202 | class (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 | |||
diff --git a/lib/Numeric/LinearAlgebra.hs b/lib/Numeric/LinearAlgebra.hs index 3df9bd7..da4a4b5 100644 --- a/lib/Numeric/LinearAlgebra.hs +++ b/lib/Numeric/LinearAlgebra.hs | |||
@@ -15,9 +15,13 @@ This module reexports all normally required functions for Linear Algebra applica | |||
15 | module Numeric.LinearAlgebra ( | 15 | module Numeric.LinearAlgebra ( |
16 | module Numeric.LinearAlgebra.Algorithms, | 16 | module Numeric.LinearAlgebra.Algorithms, |
17 | module Numeric.LinearAlgebra.Interface, | 17 | module Numeric.LinearAlgebra.Interface, |
18 | module Numeric.LinearAlgebra.Linear | 18 | module Numeric.LinearAlgebra.Linear, |
19 | module Numeric.Matrix, | ||
20 | module Numeric.Vector | ||
19 | ) where | 21 | ) where |
20 | 22 | ||
21 | import Numeric.LinearAlgebra.Algorithms | 23 | import Numeric.LinearAlgebra.Algorithms |
22 | import Numeric.LinearAlgebra.Interface | 24 | import Numeric.LinearAlgebra.Interface |
23 | import Numeric.LinearAlgebra.Linear | 25 | import Numeric.LinearAlgebra.Linear |
26 | import Numeric.Matrix | ||
27 | import Numeric.Vector | ||
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 14bf5d8..ac46847 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -81,6 +81,8 @@ import Numeric.LinearAlgebra.Linear | |||
81 | import Numeric.LinearAlgebra.LAPACK as LAPACK | 81 | import Numeric.LinearAlgebra.LAPACK as LAPACK |
82 | import Data.List(foldl1') | 82 | import Data.List(foldl1') |
83 | import Data.Array | 83 | import Data.Array |
84 | import Numeric.Vector | ||
85 | import Numeric.Matrix() | ||
84 | 86 | ||
85 | -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. | 87 | -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. |
86 | class (Product t, Linear Vector t, Linear Matrix t) => Field t where | 88 | class (Product t, Linear Vector t, Linear Matrix t) => Field t where |
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index 9048204..952661d 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -18,24 +18,25 @@ Basic optimized operations on vectors and matrices. | |||
18 | 18 | ||
19 | module Numeric.LinearAlgebra.Linear ( | 19 | module Numeric.LinearAlgebra.Linear ( |
20 | -- * Linear Algebra Typeclasses | 20 | -- * Linear Algebra Typeclasses |
21 | Vectors(..), | 21 | Vectors(..), Linear(..), |
22 | -- * Products | 22 | -- * Products |
23 | Product(..), | 23 | Product(..), |
24 | mXm,mXv,vXm, | 24 | mXm,mXv,vXm, |
25 | outer, kronecker, | 25 | outer, kronecker, |
26 | -- * Modules | 26 | -- * Modules |
27 | module Numeric.Vector, | 27 | --module Numeric.Vector, |
28 | module Numeric.Matrix, | 28 | --module Numeric.Matrix, |
29 | module Numeric.Container | 29 | module Numeric.Container |
30 | ) where | 30 | ) where |
31 | 31 | ||
32 | import Data.Packed.Internal.Common | 32 | import Data.Packed.Internal.Common |
33 | import Data.Packed.Matrix | 33 | import Data.Packed.Matrix |
34 | import Data.Packed.Vector | ||
34 | import Data.Complex | 35 | import Data.Complex |
35 | import Numeric.Container | 36 | import Numeric.Container |
36 | import Numeric.Vector | 37 | --import Numeric.Vector |
37 | import Numeric.Matrix | 38 | --import Numeric.Matrix |
38 | import Numeric.GSL.Vector | 39 | --import Numeric.GSL.Vector |
39 | import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) | 40 | import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) |
40 | 41 | ||
41 | -- | basic Vector functions | 42 | -- | basic Vector functions |
@@ -49,43 +50,6 @@ class Num e => Vectors a e where | |||
49 | norm2 :: a e -> e | 50 | norm2 :: a e -> e |
50 | normInf :: a e -> e | 51 | normInf :: a e -> e |
51 | 52 | ||
52 | |||
53 | instance Vectors Vector Float where | ||
54 | vectorSum = sumF | ||
55 | vectorProd = prodF | ||
56 | norm2 = toScalarF Norm2 | ||
57 | absSum = toScalarF AbsSum | ||
58 | dot = dotF | ||
59 | norm1 = toScalarF AbsSum | ||
60 | normInf = maxElement . vectorMapF Abs | ||
61 | |||
62 | instance Vectors Vector Double where | ||
63 | vectorSum = sumR | ||
64 | vectorProd = prodR | ||
65 | norm2 = toScalarR Norm2 | ||
66 | absSum = toScalarR AbsSum | ||
67 | dot = dotR | ||
68 | norm1 = toScalarR AbsSum | ||
69 | normInf = maxElement . vectorMapR Abs | ||
70 | |||
71 | instance Vectors Vector (Complex Float) where | ||
72 | vectorSum = sumQ | ||
73 | vectorProd = prodQ | ||
74 | norm2 = (:+ 0) . toScalarQ Norm2 | ||
75 | absSum = (:+ 0) . toScalarQ AbsSum | ||
76 | dot = dotQ | ||
77 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapQ Abs | ||
78 | normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapQ Abs | ||
79 | |||
80 | instance Vectors Vector (Complex Double) where | ||
81 | vectorSum = sumC | ||
82 | vectorProd = prodC | ||
83 | norm2 = (:+ 0) . toScalarC Norm2 | ||
84 | absSum = (:+ 0) . toScalarC AbsSum | ||
85 | dot = dotC | ||
86 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapC Abs | ||
87 | normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapC Abs | ||
88 | |||
89 | ---------------------------------------------------- | 53 | ---------------------------------------------------- |
90 | 54 | ||
91 | class Element t => Product t where | 55 | class Element t => Product t where |
@@ -162,4 +126,24 @@ kronecker a b = fromBlocks | |||
162 | . toRows | 126 | . toRows |
163 | $ flatten a `outer` flatten b | 127 | $ flatten a `outer` flatten b |
164 | 128 | ||
165 | -------------------------------------------------- | 129 | |
130 | ------------------------------------------------------------------- | ||
131 | |||
132 | |||
133 | -- | Basic element-by-element functions. | ||
134 | class (Element e, Container c e) => Linear c e where | ||
135 | -- | create a structure with a single element | ||
136 | scalar :: e -> c e | ||
137 | scale :: e -> c e -> c e | ||
138 | -- | scale the element by element reciprocal of the object: | ||
139 | -- | ||
140 | -- @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@ | ||
141 | scaleRecip :: e -> c e -> c e | ||
142 | addConstant :: e -> c e -> c e | ||
143 | add :: c e -> c e -> c e | ||
144 | sub :: c e -> c e -> c e | ||
145 | -- | element by element multiplication | ||
146 | mul :: c e -> c e -> c e | ||
147 | -- | element by element division | ||
148 | divide :: c e -> c e -> c e | ||
149 | equal :: c e -> c e -> Bool | ||
diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs index 8d3764a..f240384 100644 --- a/lib/Numeric/Matrix.hs +++ b/lib/Numeric/Matrix.hs | |||
@@ -27,7 +27,8 @@ module Numeric.Matrix ( | |||
27 | import Data.Packed.Vector | 27 | import Data.Packed.Vector |
28 | import Data.Packed.Matrix | 28 | import Data.Packed.Matrix |
29 | import Numeric.Container | 29 | import Numeric.Container |
30 | import Numeric.Vector() | 30 | import Numeric.LinearAlgebra.Linear |
31 | --import Numeric.Vector | ||
31 | 32 | ||
32 | import Control.Monad(ap) | 33 | import Control.Monad(ap) |
33 | 34 | ||
@@ -74,7 +75,7 @@ instance (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floati | |||
74 | 75 | ||
75 | --------------------------------------------------------------- | 76 | --------------------------------------------------------------- |
76 | 77 | ||
77 | instance (Linear Vector a, Container Matrix) => (Linear Matrix a) where | 78 | instance (Linear Vector a, NumericContainer Matrix) => (Linear Matrix a) where |
78 | scale x = liftMatrix (scale x) | 79 | scale x = liftMatrix (scale x) |
79 | scaleRecip x = liftMatrix (scaleRecip x) | 80 | scaleRecip x = liftMatrix (scaleRecip x) |
80 | addConstant x = liftMatrix (addConstant x) | 81 | addConstant x = liftMatrix (addConstant x) |
@@ -84,6 +85,9 @@ instance (Linear Vector a, Container Matrix) => (Linear Matrix a) where | |||
84 | divide = liftMatrix2 divide | 85 | divide = liftMatrix2 divide |
85 | equal a b = cols a == cols b && flatten a `equal` flatten b | 86 | equal a b = cols a == cols b && flatten a `equal` flatten b |
86 | scalar x = (1><1) [x] | 87 | scalar x = (1><1) [x] |
88 | |||
89 | |||
90 | instance (Linear Vector a, NumericContainer Matrix) => (Container Matrix a) where | ||
87 | minIndex m = let (r,c) = (rows m,cols m) | 91 | minIndex m = let (r,c) = (rows m,cols m) |
88 | i = 1 + (minIndex $ flatten m) | 92 | i = 1 + (minIndex $ flatten m) |
89 | in (i `div` r,i `mod` r) | 93 | in (i `div` r,i `mod` r) |
@@ -94,4 +98,3 @@ instance (Linear Vector a, Container Matrix) => (Linear Matrix a) where | |||
94 | maxElement = ap (@@>) maxIndex | 98 | maxElement = ap (@@>) maxIndex |
95 | 99 | ||
96 | ---------------------------------------------------- | 100 | ---------------------------------------------------- |
97 | |||
diff --git a/lib/Numeric/Vector.hs b/lib/Numeric/Vector.hs index ced202f..d92a5e4 100644 --- a/lib/Numeric/Vector.hs +++ b/lib/Numeric/Vector.hs | |||
@@ -29,10 +29,11 @@ import Data.Complex | |||
29 | import Control.Monad(ap) | 29 | import Control.Monad(ap) |
30 | 30 | ||
31 | import Data.Packed.Vector | 31 | import Data.Packed.Vector |
32 | import Data.Packed.Matrix(Element(..)) | 32 | import Data.Packed.Internal.Matrix(Element(..)) |
33 | import Numeric.GSL.Vector | 33 | import Numeric.GSL.Vector |
34 | 34 | ||
35 | import Numeric.Container | 35 | import Numeric.Container |
36 | import Numeric.LinearAlgebra.Linear | ||
36 | 37 | ||
37 | ------------------------------------------------------------------- | 38 | ------------------------------------------------------------------- |
38 | 39 | ||
@@ -263,12 +264,13 @@ instance Linear Vector Float where | |||
263 | divide = vectorZipF Div | 264 | divide = vectorZipF Div |
264 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 | 265 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 |
265 | scalar x = fromList [x] | 266 | scalar x = fromList [x] |
267 | |||
268 | instance Container Vector Float where | ||
266 | minIndex = round . toScalarF MinIdx | 269 | minIndex = round . toScalarF MinIdx |
267 | maxIndex = round . toScalarF MaxIdx | 270 | maxIndex = round . toScalarF MaxIdx |
268 | minElement = toScalarF Min | 271 | minElement = toScalarF Min |
269 | maxElement = toScalarF Max | 272 | maxElement = toScalarF Max |
270 | 273 | ||
271 | |||
272 | instance Linear Vector Double where | 274 | instance Linear Vector Double where |
273 | scale = vectorMapValR Scale | 275 | scale = vectorMapValR Scale |
274 | scaleRecip = vectorMapValR Recip | 276 | scaleRecip = vectorMapValR Recip |
@@ -279,6 +281,8 @@ instance Linear Vector Double where | |||
279 | divide = vectorZipR Div | 281 | divide = vectorZipR Div |
280 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 | 282 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 |
281 | scalar x = fromList [x] | 283 | scalar x = fromList [x] |
284 | |||
285 | instance Container Vector Double where | ||
282 | minIndex = round . toScalarR MinIdx | 286 | minIndex = round . toScalarR MinIdx |
283 | maxIndex = round . toScalarR MaxIdx | 287 | maxIndex = round . toScalarR MaxIdx |
284 | minElement = toScalarR Min | 288 | minElement = toScalarR Min |
@@ -294,6 +298,8 @@ instance Linear Vector (Complex Double) where | |||
294 | divide = vectorZipC Div | 298 | divide = vectorZipC Div |
295 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 299 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
296 | scalar x = fromList [x] | 300 | scalar x = fromList [x] |
301 | |||
302 | instance Container Vector (Complex Double) where | ||
297 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 303 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
298 | maxIndex = maxIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 304 | maxIndex = maxIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
299 | minElement = ap (@>) minIndex | 305 | minElement = ap (@>) minIndex |
@@ -309,9 +315,47 @@ instance Linear Vector (Complex Float) where | |||
309 | divide = vectorZipQ Div | 315 | divide = vectorZipQ Div |
310 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 316 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
311 | scalar x = fromList [x] | 317 | scalar x = fromList [x] |
318 | |||
319 | instance Container Vector (Complex Float) where | ||
312 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 320 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
313 | maxIndex = maxIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 321 | maxIndex = maxIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
314 | minElement = ap (@>) minIndex | 322 | minElement = ap (@>) minIndex |
315 | maxElement = ap (@>) maxIndex | 323 | maxElement = ap (@>) maxIndex |
316 | 324 | ||
317 | --------------------------------------------------------------- | 325 | --------------------------------------------------------------- |
326 | |||
327 | instance Vectors Vector Float where | ||
328 | vectorSum = sumF | ||
329 | vectorProd = prodF | ||
330 | norm2 = toScalarF Norm2 | ||
331 | absSum = toScalarF AbsSum | ||
332 | dot = dotF | ||
333 | norm1 = toScalarF AbsSum | ||
334 | normInf = maxElement . vectorMapF Abs | ||
335 | |||
336 | instance Vectors Vector Double where | ||
337 | vectorSum = sumR | ||
338 | vectorProd = prodR | ||
339 | norm2 = toScalarR Norm2 | ||
340 | absSum = toScalarR AbsSum | ||
341 | dot = dotR | ||
342 | norm1 = toScalarR AbsSum | ||
343 | normInf = maxElement . vectorMapR Abs | ||
344 | |||
345 | instance Vectors Vector (Complex Float) where | ||
346 | vectorSum = sumQ | ||
347 | vectorProd = prodQ | ||
348 | norm2 = (:+ 0) . toScalarQ Norm2 | ||
349 | absSum = (:+ 0) . toScalarQ AbsSum | ||
350 | dot = dotQ | ||
351 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapQ Abs | ||
352 | normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapQ Abs | ||
353 | |||
354 | instance Vectors Vector (Complex Double) where | ||
355 | vectorSum = sumC | ||
356 | vectorProd = prodC | ||
357 | norm2 = (:+ 0) . toScalarC Norm2 | ||
358 | absSum = (:+ 0) . toScalarC AbsSum | ||
359 | dot = dotC | ||
360 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapC Abs | ||
361 | normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapC Abs \ No newline at end of file | ||