diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Linear.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index 4d7f608..778b976 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -39,65 +39,70 @@ import Control.Monad(ap) | |||
39 | -- | basic Vector functions | 39 | -- | basic Vector functions |
40 | class Num e => Vectors a e where | 40 | class Num e => Vectors a e where |
41 | -- the C functions sumX are twice as fast as using foldVector | 41 | -- the C functions sumX are twice as fast as using foldVector |
42 | vectorSum :: a e -> e | 42 | vectorSum :: a e -> e |
43 | absSum :: a e -> e | 43 | vectorProd :: a e -> e |
44 | vectorMin :: a e -> e | 44 | absSum :: a e -> e |
45 | vectorMax :: a e -> e | 45 | vectorMin :: a e -> e |
46 | minIdx :: a e -> Int | 46 | vectorMax :: a e -> e |
47 | maxIdx :: a e -> Int | 47 | minIdx :: a e -> Int |
48 | dot :: a e -> a e -> e | 48 | maxIdx :: a e -> Int |
49 | norm1 :: a e -> e | 49 | dot :: a e -> a e -> e |
50 | norm2 :: a e -> e | 50 | norm1 :: a e -> e |
51 | normInf :: a e -> e | 51 | norm2 :: a e -> e |
52 | normInf :: a e -> e | ||
52 | 53 | ||
53 | 54 | ||
54 | instance Vectors Vector Float where | 55 | instance Vectors Vector Float where |
55 | vectorSum = sumF | 56 | vectorSum = sumF |
56 | norm2 = toScalarF Norm2 | 57 | vectorProd = prodF |
57 | absSum = toScalarF AbsSum | 58 | norm2 = toScalarF Norm2 |
58 | vectorMin = toScalarF Min | 59 | absSum = toScalarF AbsSum |
59 | vectorMax = toScalarF Max | 60 | vectorMin = toScalarF Min |
60 | minIdx = round . toScalarF MinIdx | 61 | vectorMax = toScalarF Max |
61 | maxIdx = round . toScalarF MaxIdx | 62 | minIdx = round . toScalarF MinIdx |
62 | dot = dotF | 63 | maxIdx = round . toScalarF MaxIdx |
63 | norm1 = toScalarF AbsSum | 64 | dot = dotF |
64 | normInf = vectorMax . vectorMapF Abs | 65 | norm1 = toScalarF AbsSum |
66 | normInf = vectorMax . vectorMapF Abs | ||
65 | 67 | ||
66 | instance Vectors Vector Double where | 68 | instance Vectors Vector Double where |
67 | vectorSum = sumR | 69 | vectorSum = sumR |
68 | norm2 = toScalarR Norm2 | 70 | vectorProd = prodR |
69 | absSum = toScalarR AbsSum | 71 | norm2 = toScalarR Norm2 |
70 | vectorMin = toScalarR Min | 72 | absSum = toScalarR AbsSum |
71 | vectorMax = toScalarR Max | 73 | vectorMin = toScalarR Min |
72 | minIdx = round . toScalarR MinIdx | 74 | vectorMax = toScalarR Max |
73 | maxIdx = round . toScalarR MaxIdx | 75 | minIdx = round . toScalarR MinIdx |
74 | dot = dotR | 76 | maxIdx = round . toScalarR MaxIdx |
75 | norm1 = toScalarR AbsSum | 77 | dot = dotR |
76 | normInf = vectorMax . vectorMapR Abs | 78 | norm1 = toScalarR AbsSum |
79 | normInf = vectorMax . vectorMapR Abs | ||
77 | 80 | ||
78 | instance Vectors Vector (Complex Float) where | 81 | instance Vectors Vector (Complex Float) where |
79 | vectorSum = sumQ | 82 | vectorSum = sumQ |
80 | norm2 = (:+ 0) . toScalarQ Norm2 | 83 | vectorProd = prodQ |
81 | absSum = (:+ 0) . toScalarQ AbsSum | 84 | norm2 = (:+ 0) . toScalarQ Norm2 |
82 | vectorMin = ap (@>) minIdx | 85 | absSum = (:+ 0) . toScalarQ AbsSum |
83 | vectorMax = ap (@>) maxIdx | 86 | vectorMin = ap (@>) minIdx |
84 | minIdx = minIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 87 | vectorMax = ap (@>) maxIdx |
85 | maxIdx = maxIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 88 | minIdx = minIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
86 | dot = dotQ | 89 | maxIdx = maxIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
87 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapQ Abs | 90 | dot = dotQ |
88 | normInf = (:+ 0) . vectorMax . fst . fromComplex . vectorMapQ Abs | 91 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapQ Abs |
92 | normInf = (:+ 0) . vectorMax . fst . fromComplex . vectorMapQ Abs | ||
89 | 93 | ||
90 | instance Vectors Vector (Complex Double) where | 94 | instance Vectors Vector (Complex Double) where |
91 | vectorSum = sumC | 95 | vectorSum = sumC |
92 | norm2 = (:+ 0) . toScalarC Norm2 | 96 | vectorProd = prodC |
93 | absSum = (:+ 0) . toScalarC AbsSum | 97 | norm2 = (:+ 0) . toScalarC Norm2 |
94 | vectorMin = ap (@>) minIdx | 98 | absSum = (:+ 0) . toScalarC AbsSum |
95 | vectorMax = ap (@>) maxIdx | 99 | vectorMin = ap (@>) minIdx |
96 | minIdx = minIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 100 | vectorMax = ap (@>) maxIdx |
97 | maxIdx = maxIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 101 | minIdx = minIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
98 | dot = dotC | 102 | maxIdx = maxIdx . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
99 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapC Abs | 103 | dot = dotC |
100 | normInf = (:+ 0) . vectorMax . fst . fromComplex . vectorMapC Abs | 104 | norm1 = (:+ 0) . vectorSum . fst . fromComplex . vectorMapC Abs |
105 | normInf = (:+ 0) . vectorMax . fst . fromComplex . vectorMapC Abs | ||
101 | 106 | ||
102 | ---------------------------------------------------- | 107 | ---------------------------------------------------- |
103 | 108 | ||