summaryrefslogtreecommitdiff
path: root/lib/Numeric/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/Vector.hs')
-rw-r--r--lib/Numeric/Vector.hs48
1 files changed, 46 insertions, 2 deletions
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
29import Control.Monad(ap) 29import Control.Monad(ap)
30 30
31import Data.Packed.Vector 31import Data.Packed.Vector
32import Data.Packed.Matrix(Element(..)) 32import Data.Packed.Internal.Matrix(Element(..))
33import Numeric.GSL.Vector 33import Numeric.GSL.Vector
34 34
35import Numeric.Container 35import Numeric.Container
36import 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
268instance 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
272instance Linear Vector Double where 274instance 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
285instance 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
302instance 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
319instance 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
327instance 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
336instance 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
345instance 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
354instance 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