summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Interface.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-08-31 16:52:26 +0000
committerAlberto Ruiz <aruiz@um.es>2010-08-31 16:52:26 +0000
commit4486e93da02c7ef9e1fdf785c88f78986048c332 (patch)
treec0d84fce23a39a307fd12041fdd570be93aca15d /lib/Numeric/LinearAlgebra/Interface.hs
parent0b48e6b34a1a4ec590f2d17833f713f42f5e0955 (diff)
refactoring norms
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Interface.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Interface.hs55
1 files changed, 52 insertions, 3 deletions
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs
index 542d76e..ec08694 100644
--- a/lib/Numeric/LinearAlgebra/Interface.hs
+++ b/lib/Numeric/LinearAlgebra/Interface.hs
@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -fglasgow-exts #-} 1{-# OPTIONS_GHC -fglasgow-exts #-}
2{-# LANGUAGE UndecidableInstances #-}
2----------------------------------------------------------------------------- 3-----------------------------------------------------------------------------
3{- | 4{- |
4Module : Numeric.LinearAlgebra.Interface 5Module : Numeric.LinearAlgebra.Interface
@@ -18,7 +19,7 @@ In the context of the standard numeric operators, one-component vectors and matr
18----------------------------------------------------------------------------- 19-----------------------------------------------------------------------------
19 20
20module Numeric.LinearAlgebra.Interface( 21module Numeric.LinearAlgebra.Interface(
21 (<>),(<.>), 22 (<>),(<.>),mulG, Adapt, adaptElements,
22 (<\>), 23 (<\>),
23 (.*),(*/), 24 (.*),(*/),
24 (<|>),(<->), 25 (<|>),(<->),
@@ -28,22 +29,28 @@ import Data.Packed.Vector
28import Data.Packed.Matrix 29import Data.Packed.Matrix
29import Numeric.LinearAlgebra.Algorithms 30import Numeric.LinearAlgebra.Algorithms
30import Numeric.LinearAlgebra.Linear 31import Numeric.LinearAlgebra.Linear
32import Data.Complex
33import Control.Arrow((***))
31 34
32--import Numeric.GSL.Vector 35--import Numeric.GSL.Vector
33 36
34class Mul a b c | a b -> c where 37class Mul a b c | a b -> c where
35 infixl 7 <> 38 infixl 7 <>
36 -- | Matrix-matrix, matrix-vector, and vector-matrix products. 39 -- | Matrix-matrix, matrix-vector, and vector-matrix products.
37 (<>) :: Prod t => a t -> b t -> c t 40 (<>) :: Product t => a t -> b t -> c t
41 mulG :: (Element r, Element s, Adapt r s t t, Product t) => a r -> b s -> c t
38 42
39instance Mul Matrix Matrix Matrix where 43instance Mul Matrix Matrix Matrix where
40 (<>) = multiply 44 (<>) = mXm
45 mulG a b = uncurry mXm (curry adapt a b)
41 46
42instance Mul Matrix Vector Vector where 47instance Mul Matrix Vector Vector where
43 (<>) m v = flatten $ m <> (asColumn v) 48 (<>) m v = flatten $ m <> (asColumn v)
49 mulG m v = flatten $ m `mulG` (asColumn v)
44 50
45instance Mul Vector Matrix Vector where 51instance Mul Vector Matrix Vector where
46 (<>) v m = flatten $ (asRow v) <> m 52 (<>) v m = flatten $ (asRow v) <> m
53 mulG v m = flatten $ (asRow v) `mulG` m
47 54
48--------------------------------------------------- 55---------------------------------------------------
49 56
@@ -120,3 +127,45 @@ a <-> b = joinV a b
120 127
121---------------------------------------------------- 128----------------------------------------------------
122 129
130class Adapt a b c d | a b -> c, a b -> d where
131 adapt :: Container k => (k a, k b) -> (k c, k d)
132
133--instance Adapt a a a a where
134-- adapt = id *** id
135
136instance Adapt Float Float Float Float where
137 adapt = id *** id
138
139instance Adapt Double Double Double Double where
140 adapt = id *** id
141
142instance Adapt (Complex Float) (Complex Float) (Complex Float) (Complex Float) where
143 adapt = id *** id
144
145instance Adapt Float Double Double Double where
146 adapt = double *** id
147
148instance Adapt Double Float Double Double where
149 adapt = id *** double
150
151instance Adapt Float (Complex Float) (Complex Float) (Complex Float) where
152 adapt = complex *** id
153
154instance Adapt (Complex Float) Float (Complex Float) (Complex Float) where
155 adapt = id *** complex
156
157instance (Convert a, Convert (DoubleOf a), ComplexOf (DoubleOf a) ~ Complex Double) => Adapt a (Complex Double) (Complex Double) (Complex Double) where
158 adapt = complex.double *** id
159
160instance (Convert a, Convert (DoubleOf a), ComplexOf (DoubleOf a) ~ Complex Double) => Adapt (Complex Double) a (Complex Double) (Complex Double) where
161 adapt = id *** complex.double
162
163instance Adapt Double (Complex Float) (Complex Double) (Complex Double) where
164 adapt = complex *** double
165
166instance Adapt (Complex Float) Double (Complex Double) (Complex Double) where
167 adapt = double *** complex
168
169adaptElements:: (Adapt a b c d, Container k) => (k a, k b) -> (k c, k d)
170adaptElements p = adapt p
171