summaryrefslogtreecommitdiff
path: root/lib/Numeric/Container.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/Container.hs')
-rw-r--r--lib/Numeric/Container.hs49
1 files changed, 40 insertions, 9 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index 345c1f1..ed6714f 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -8,8 +8,8 @@
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- | 9-- |
10-- Module : Numeric.Container 10-- Module : Numeric.Container
11-- Copyright : (c) Alberto Ruiz 2010 11-- Copyright : (c) Alberto Ruiz 2010-14
12-- License : GPL-style 12-- License : GPL
13-- 13--
14-- Maintainer : Alberto Ruiz <aruiz@um.es> 14-- Maintainer : Alberto Ruiz <aruiz@um.es>
15-- Stability : provisional 15-- Stability : provisional
@@ -35,8 +35,9 @@ module Numeric.Container (
35 Container(..), 35 Container(..),
36 -- * Matrix product 36 -- * Matrix product
37 Product(..), 37 Product(..),
38 Contraction(..),
38 optimiseMult, 39 optimiseMult,
39 mXm,mXv,vXm,(<.>),Mul(..),LSDiv(..), 40 mXm,mXv,vXm,Mul(..),LSDiv(..), cdot,
40 outer, kronecker, 41 outer, kronecker,
41 -- * Random numbers 42 -- * Random numbers
42 RandDist(..), 43 RandDist(..),
@@ -95,12 +96,9 @@ linspace :: (Enum e, Container Vector e) => Int -> (e, e) -> Vector e
95linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1] 96linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1]
96 where s = (b-a)/fromIntegral (n-1) 97 where s = (b-a)/fromIntegral (n-1)
97 98
98-- | Dot product: @u \<.\> v = dot u v@ 99-- | dot product: @cdot u v = 'udot' ('conj' u) v@
99(<.>) :: Product t => Vector t -> Vector t -> t 100cdot :: (Container Vector t, Product t) => Vector t -> Vector t -> t
100infixl 7 <.> 101cdot u v = udot (conj u) v
101(<.>) = dot
102
103
104 102
105-------------------------------------------------------- 103--------------------------------------------------------
106 104
@@ -143,3 +141,36 @@ meanCov x = (med,cov) where
143 xc = x `sub` meds 141 xc = x `sub` meds
144 cov = scale (recip (fromIntegral (r-1))) (trans xc `mXm` xc) 142 cov = scale (recip (fromIntegral (r-1))) (trans xc `mXm` xc)
145 143
144--------------------------------------------------------------------------------
145
146-- | matrix-matrix product, matrix-vector product, unconjugated dot product, and scaling
147class Contraction a b c | a b -> c
148 where
149 -- ^ 0x00d7 multiplication sign
150 infixl 7 ×
151 (×) :: a -> b -> c
152
153instance Product t => Contraction (Vector t) (Vector t) t where
154 (×) = udot
155
156instance Product t => Contraction (Matrix t) (Vector t) (Vector t) where
157 (×) = mXv
158
159instance Product t => Contraction (Vector t) (Matrix t) (Vector t) where
160 (×) = vXm
161
162instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where
163 (×) = mXm
164
165instance Container Vector t => Contraction t (Vector t) (Vector t) where
166 (×) = scale
167
168instance Container Vector t => Contraction (Vector t) t (Vector t) where
169 (×) = flip scale
170
171instance Container Matrix t => Contraction t (Matrix t) (Matrix t) where
172 (×) = scale
173
174instance Container Matrix t => Contraction (Matrix t) t (Matrix t) where
175 (×) = flip scale
176