summaryrefslogtreecommitdiff
path: root/packages/base/src/Data/Packed/Numeric.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Data/Packed/Numeric.hs')
-rw-r--r--packages/base/src/Data/Packed/Numeric.hs41
1 files changed, 35 insertions, 6 deletions
diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs
index 01cf6c5..7d88cbc 100644
--- a/packages/base/src/Data/Packed/Numeric.hs
+++ b/packages/base/src/Data/Packed/Numeric.hs
@@ -32,7 +32,7 @@ module Data.Packed.Numeric (
32 diag, ident, 32 diag, ident,
33 ctrans, 33 ctrans,
34 -- * Generic operations 34 -- * Generic operations
35 Container(..), 35 Container(..), Numeric,
36 -- add, mul, sub, divide, equal, scaleRecip, addConstant, 36 -- add, mul, sub, divide, equal, scaleRecip, addConstant,
37 scalar, conj, scale, arctan2, cmap, 37 scalar, conj, scale, arctan2, cmap,
38 atIndex, minIndex, maxIndex, minElement, maxElement, 38 atIndex, minIndex, maxIndex, minElement, maxElement,
@@ -40,7 +40,7 @@ module Data.Packed.Numeric (
40 step, cond, find, assoc, accum, 40 step, cond, find, assoc, accum,
41 Transposable(..), Linear(..), 41 Transposable(..), Linear(..),
42 -- * Matrix product 42 -- * Matrix product
43 Product(..), udot, dot, (◇), 43 Product(..), udot, dot, (◇), (<·>), (#>),
44 Mul(..), 44 Mul(..),
45 Contraction(..),(<.>), 45 Contraction(..),(<.>),
46 optimiseMult, 46 optimiseMult,
@@ -96,7 +96,7 @@ linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n
96 96
97-------------------------------------------------------- 97--------------------------------------------------------
98 98
99{- | Matrix product, matrix - vector product, and dot product (equivalent to 'contraction') 99{- Matrix product, matrix - vector product, and dot product (equivalent to 'contraction')
100 100
101(This operator can also be written using the unicode symbol ◇ (25c7).) 101(This operator can also be written using the unicode symbol ◇ (25c7).)
102 102
@@ -138,9 +138,8 @@ For complex vectors the first argument is conjugated:
138>>> fromList [1,i,1-i] <.> complex a 138>>> fromList [1,i,1-i] <.> complex a
139fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] 139fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0]
140-} 140-}
141infixl 7 <.> 141
142(<.>) :: Contraction a b c => a -> b -> c 142
143(<.>) = contraction
144 143
145 144
146class Contraction a b c | a b -> c 145class Contraction a b c | a b -> c
@@ -160,6 +159,23 @@ instance (Container Vector t, Product t) => Contraction (Vector t) (Matrix t) (V
160instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where 159instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where
161 contraction = mXm 160 contraction = mXm
162 161
162--------------------------------------------------------------------------------
163
164infixl 7 <.>
165-- | An infix synonym for 'dot'
166(<.>) :: Numeric t => Vector t -> Vector t -> t
167(<.>) = dot
168
169
170infixr 8 <·>, #>
171-- | dot product
172(<·>) :: Numeric t => Vector t -> Vector t -> t
173(<·>) = dot
174
175
176-- | matrix-vector product
177(#>) :: Numeric t => Matrix t -> Vector t -> Vector t
178(#>) = mXv
163 179
164-------------------------------------------------------------------------------- 180--------------------------------------------------------------------------------
165 181
@@ -286,3 +302,16 @@ meanCov x = (med,cov) where
286 302
287-------------------------------------------------------------------------------- 303--------------------------------------------------------------------------------
288 304
305class ( Container Vector t
306 , Container Matrix t
307 , Konst t Int Vector
308 , Konst t (Int,Int) Matrix
309 , Product t
310 ) => Numeric t
311
312instance Numeric Double
313instance Numeric (Complex Double)
314instance Numeric Float
315instance Numeric (Complex Float)
316
317--------------------------------------------------------------------------------