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, 1 insertions, 54 deletions
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs
index ec08694..13d175b 100644
--- a/lib/Numeric/LinearAlgebra/Interface.hs
+++ b/lib/Numeric/LinearAlgebra/Interface.hs
@@ -19,7 +19,7 @@ In the context of the standard numeric operators, one-component vectors and matr
19----------------------------------------------------------------------------- 19-----------------------------------------------------------------------------
20 20
21module Numeric.LinearAlgebra.Interface( 21module Numeric.LinearAlgebra.Interface(
22 (<>),(<.>),mulG, Adapt, adaptElements, 22 (<>),(<.>),
23 (<\>), 23 (<\>),
24 (.*),(*/), 24 (.*),(*/),
25 (<|>),(<->), 25 (<|>),(<->),
@@ -29,28 +29,20 @@ import Data.Packed.Vector
29import Data.Packed.Matrix 29import Data.Packed.Matrix
30import Numeric.LinearAlgebra.Algorithms 30import Numeric.LinearAlgebra.Algorithms
31import Numeric.LinearAlgebra.Linear 31import Numeric.LinearAlgebra.Linear
32import Data.Complex
33import Control.Arrow((***))
34
35--import Numeric.GSL.Vector
36 32
37class Mul a b c | a b -> c where 33class Mul a b c | a b -> c where
38 infixl 7 <> 34 infixl 7 <>
39 -- | Matrix-matrix, matrix-vector, and vector-matrix products. 35 -- | Matrix-matrix, matrix-vector, and vector-matrix products.
40 (<>) :: Product t => a t -> b t -> c t 36 (<>) :: 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
42 37
43instance Mul Matrix Matrix Matrix where 38instance Mul Matrix Matrix Matrix where
44 (<>) = mXm 39 (<>) = mXm
45 mulG a b = uncurry mXm (curry adapt a b)
46 40
47instance Mul Matrix Vector Vector where 41instance Mul Matrix Vector Vector where
48 (<>) m v = flatten $ m <> (asColumn v) 42 (<>) m v = flatten $ m <> (asColumn v)
49 mulG m v = flatten $ m `mulG` (asColumn v)
50 43
51instance Mul Vector Matrix Vector where 44instance Mul Vector Matrix Vector where
52 (<>) v m = flatten $ (asRow v) <> m 45 (<>) v m = flatten $ (asRow v) <> m
53 mulG v m = flatten $ (asRow v) `mulG` m
54 46
55--------------------------------------------------- 47---------------------------------------------------
56 48
@@ -124,48 +116,3 @@ a <|> b = joinH a b
124-- -- | Vertical concatenation of matrices and vectors. 116-- -- | Vertical concatenation of matrices and vectors.
125-- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t 117-- (<->) :: (Element t, Joinable a b) => a t -> b t -> Matrix t
126a <-> b = joinV a b 118a <-> b = joinV a b
127
128----------------------------------------------------
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