summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Interface.hs
diff options
context:
space:
mode:
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