summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-09-06 07:37:18 +0000
committerAlberto Ruiz <aruiz@um.es>2010-09-06 07:37:18 +0000
commit29099e3bfb4eec87ac3d4d675d7cfc82234c20d6 (patch)
tree82124829d5e2a51e1b272430cee2617b7e182e0e /lib/Numeric/LinearAlgebra
parentfa4e2233a873bbfee26939c013b56acc160bca7b (diff)
working on conversion / linear
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs72
2 files changed, 30 insertions, 44 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 14bf5d8..ac46847 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -81,6 +81,8 @@ import Numeric.LinearAlgebra.Linear
81import Numeric.LinearAlgebra.LAPACK as LAPACK 81import Numeric.LinearAlgebra.LAPACK as LAPACK
82import Data.List(foldl1') 82import Data.List(foldl1')
83import Data.Array 83import Data.Array
84import Numeric.Vector
85import Numeric.Matrix()
84 86
85-- | Auxiliary typeclass used to define generic computations for both real and complex matrices. 87-- | Auxiliary typeclass used to define generic computations for both real and complex matrices.
86class (Product t, Linear Vector t, Linear Matrix t) => Field t where 88class (Product t, Linear Vector t, Linear Matrix t) => Field t where
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
19module Numeric.LinearAlgebra.Linear ( 19module 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
32import Data.Packed.Internal.Common 32import Data.Packed.Internal.Common
33import Data.Packed.Matrix 33import Data.Packed.Matrix
34import Data.Packed.Vector
34import Data.Complex 35import Data.Complex
35import Numeric.Container 36import Numeric.Container
36import Numeric.Vector 37--import Numeric.Vector
37import Numeric.Matrix 38--import Numeric.Matrix
38import Numeric.GSL.Vector 39--import Numeric.GSL.Vector
39import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) 40import 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
53instance 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
62instance 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
71instance 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
80instance 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
91class Element t => Product t where 55class 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.
134class (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