diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-06 06:20:04 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-06 06:20:04 +0000 |
commit | 7ddccab219ab64f066d8913c9f3c60afe2831d4b (patch) | |
tree | bdf412693130e067f3b4b865bfe9807640ca6028 /lib/Numeric/LinearAlgebra | |
parent | 305360d31d6cc81c405df84e098c46e5b461a20a (diff) |
complex implementations for Vectors typeclass
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Interface.hs | 2 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 49 |
2 files changed, 24 insertions, 27 deletions
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs index f8917a0..8d2b52a 100644 --- a/lib/Numeric/LinearAlgebra/Interface.hs +++ b/lib/Numeric/LinearAlgebra/Interface.hs | |||
@@ -28,7 +28,7 @@ import Numeric.LinearAlgebra.Instances() | |||
28 | import Data.Packed.Vector | 28 | import Data.Packed.Vector |
29 | import Data.Packed.Matrix | 29 | import Data.Packed.Matrix |
30 | import Numeric.LinearAlgebra.Algorithms | 30 | import Numeric.LinearAlgebra.Algorithms |
31 | import Numeric.LinearAlgebra.Linear | 31 | import Numeric.LinearAlgebra.Linear() |
32 | 32 | ||
33 | --import Numeric.GSL.Vector | 33 | --import Numeric.GSL.Vector |
34 | 34 | ||
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index 1651247..e718e83 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -16,7 +16,7 @@ Basic optimized operations on vectors and matrices. | |||
16 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
17 | 17 | ||
18 | module Numeric.LinearAlgebra.Linear ( | 18 | module Numeric.LinearAlgebra.Linear ( |
19 | Vectors(..), normalise, | 19 | Vectors(..), |
20 | Linear(..) | 20 | Linear(..) |
21 | ) where | 21 | ) where |
22 | 22 | ||
@@ -25,21 +25,18 @@ import Data.Packed.Matrix | |||
25 | import Data.Complex | 25 | import Data.Complex |
26 | import Numeric.GSL.Vector | 26 | import Numeric.GSL.Vector |
27 | 27 | ||
28 | -- | normalise a vector to unit length | 28 | import Control.Monad(ap) |
29 | normalise :: (Floating a, Vectors Vector a, | ||
30 | Linear Vector a, Fractional (Vector a)) => Vector a -> Vector a | ||
31 | normalise v = scaleRecip (vectorSum v) v | ||
32 | 29 | ||
33 | -- | basic Vector functions | 30 | -- | basic Vector functions |
34 | class (Num b) => Vectors a b where | 31 | class Num e => Vectors a e where |
35 | vectorSum :: a b -> b | 32 | vectorSum :: a e -> e |
36 | euclidean :: a b -> b | 33 | euclidean :: a e -> e |
37 | absSum :: a b -> b | 34 | absSum :: a e -> e |
38 | vectorMin :: a b -> b | 35 | vectorMin :: a e -> e |
39 | vectorMax :: a b -> b | 36 | vectorMax :: a e -> e |
40 | minIdx :: a b -> Int | 37 | minIdx :: a e -> Int |
41 | maxIdx :: a b -> Int | 38 | maxIdx :: a e -> Int |
42 | dot :: a b -> a b -> b | 39 | dot :: a e -> a e -> e |
43 | 40 | ||
44 | instance Vectors Vector Float where | 41 | instance Vectors Vector Float where |
45 | vectorSum = sumF | 42 | vectorSum = sumF |
@@ -63,22 +60,22 @@ instance Vectors Vector Double where | |||
63 | 60 | ||
64 | instance Vectors Vector (Complex Float) where | 61 | instance Vectors Vector (Complex Float) where |
65 | vectorSum = sumQ | 62 | vectorSum = sumQ |
66 | euclidean = undefined | 63 | euclidean = (:+ 0) . toScalarQ Norm2 |
67 | absSum = undefined | 64 | absSum = (:+ 0) . toScalarQ AbsSum |
68 | vectorMin = undefined | 65 | vectorMin = ap (@>) minIdx |
69 | vectorMax = undefined | 66 | vectorMax = ap (@>) maxIdx |
70 | minIdx = undefined | 67 | minIdx = minIdx . (zipVector (*) `ap` mapVector conjugate) |
71 | maxIdx = undefined | 68 | maxIdx = maxIdx . (zipVector (*) `ap` mapVector conjugate) |
72 | dot = dotQ | 69 | dot = dotQ |
73 | 70 | ||
74 | instance Vectors Vector (Complex Double) where | 71 | instance Vectors Vector (Complex Double) where |
75 | vectorSum = sumC | 72 | vectorSum = sumC |
76 | euclidean = undefined | 73 | euclidean = (:+ 0) . toScalarC Norm2 |
77 | absSum = undefined | 74 | absSum = (:+ 0) . toScalarC AbsSum |
78 | vectorMin = undefined | 75 | vectorMin = ap (@>) minIdx |
79 | vectorMax = undefined | 76 | vectorMax = ap (@>) maxIdx |
80 | minIdx = undefined | 77 | minIdx = minIdx . (zipVector (*) `ap` mapVector conjugate) |
81 | maxIdx = undefined | 78 | maxIdx = maxIdx . (zipVector (*) `ap` mapVector conjugate) |
82 | dot = dotC | 79 | dot = dotC |
83 | 80 | ||
84 | ---------------------------------------------------- | 81 | ---------------------------------------------------- |