diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Linear.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 72 |
1 files changed, 28 insertions, 44 deletions
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 | ||