diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-09-06 09:59:08 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-09-06 09:59:08 +0000 |
commit | 9004922ad91c0b4ad8498c31171a3a1a1e27d9f2 (patch) | |
tree | c6d4759e584b7933029e405a73974e173046ddcc /lib/Numeric/LinearAlgebra/Linear.hs | |
parent | 29099e3bfb4eec87ac3d4d675d7cfc82234c20d6 (diff) |
Merged changes with conversion-linear
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Linear.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index 952661d..775060e 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -18,7 +18,7 @@ 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(..), Linear(..), | 21 | Vectors(..), |
22 | -- * Products | 22 | -- * Products |
23 | Product(..), | 23 | Product(..), |
24 | mXm,mXv,vXm, | 24 | mXm,mXv,vXm, |
@@ -34,22 +34,52 @@ import Data.Packed.Matrix | |||
34 | import Data.Packed.Vector | 34 | import Data.Packed.Vector |
35 | import Data.Complex | 35 | import Data.Complex |
36 | import Numeric.Container | 36 | import Numeric.Container |
37 | --import Numeric.Vector | 37 | import Numeric.Vector() |
38 | --import Numeric.Matrix | 38 | import Numeric.Matrix() |
39 | --import Numeric.GSL.Vector | 39 | import Numeric.GSL.Vector |
40 | import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) | 40 | import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) |
41 | 41 | ||
42 | -- | basic Vector functions | 42 | -- | Linear algebraic properties of objects |
43 | class Num e => Vectors a e where | 43 | class Num e => Vectors a e where |
44 | -- the C functions sumX are twice as fast as using foldVector | 44 | -- | dot (inner) product |
45 | vectorSum :: a e -> e | ||
46 | vectorProd :: a e -> e | ||
47 | absSum :: a e -> e | ||
48 | dot :: a e -> a e -> e | 45 | dot :: a e -> a e -> e |
46 | -- | sum of absolute value of elements (differs in complex case from @norm1@ | ||
47 | absSum :: a e -> e | ||
48 | -- | sum of absolute value of elements | ||
49 | norm1 :: a e -> e | 49 | norm1 :: a e -> e |
50 | -- | euclidean norm | ||
50 | norm2 :: a e -> e | 51 | norm2 :: a e -> e |
52 | -- | element of maximum magnitude | ||
51 | normInf :: a e -> e | 53 | normInf :: a e -> e |
52 | 54 | ||
55 | instance Vectors Vector Float where | ||
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 | norm2 = toScalarR Norm2 | ||
64 | absSum = toScalarR AbsSum | ||
65 | dot = dotR | ||
66 | norm1 = toScalarR AbsSum | ||
67 | normInf = maxElement . vectorMapR Abs | ||
68 | |||
69 | instance Vectors Vector (Complex Float) where | ||
70 | norm2 = (:+ 0) . toScalarQ Norm2 | ||
71 | absSum = (:+ 0) . toScalarQ AbsSum | ||
72 | dot = dotQ | ||
73 | norm1 = (:+ 0) . sumElements . fst . fromComplex . vectorMapQ Abs | ||
74 | normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapQ Abs | ||
75 | |||
76 | instance Vectors Vector (Complex Double) where | ||
77 | norm2 = (:+ 0) . toScalarC Norm2 | ||
78 | absSum = (:+ 0) . toScalarC AbsSum | ||
79 | dot = dotC | ||
80 | norm1 = (:+ 0) . sumElements . fst . fromComplex . vectorMapC Abs | ||
81 | normInf = (:+ 0) . maxElement . fst . fromComplex . vectorMapC Abs | ||
82 | |||
53 | ---------------------------------------------------- | 83 | ---------------------------------------------------- |
54 | 84 | ||
55 | class Element t => Product t where | 85 | class Element t => Product t where |
@@ -128,22 +158,3 @@ kronecker a b = fromBlocks | |||
128 | 158 | ||
129 | 159 | ||
130 | ------------------------------------------------------------------- | 160 | ------------------------------------------------------------------- |
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 | ||