diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-27 10:41:40 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-27 10:41:40 +0200 |
commit | cf3c788f0c44577ac1a5365e8154200b53a36409 (patch) | |
tree | d667ea10609e74b69b11309bb59b7e000b240a92 /packages/base/src/Data | |
parent | 365e2435e71de10ebe849acac5a107b6f43817c4 (diff) |
static dimensions, cont.
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 7 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/Numeric.hs | 41 |
2 files changed, 39 insertions, 9 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index 3c1c1d0..0205a17 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs | |||
@@ -3,6 +3,7 @@ | |||
3 | {-# LANGUAGE FlexibleContexts #-} | 3 | {-# LANGUAGE FlexibleContexts #-} |
4 | {-# LANGUAGE FlexibleInstances #-} | 4 | {-# LANGUAGE FlexibleInstances #-} |
5 | {-# LANGUAGE MultiParamTypeClasses #-} | 5 | {-# LANGUAGE MultiParamTypeClasses #-} |
6 | {-# LANGUAGE FunctionalDependencies #-} | ||
6 | {-# LANGUAGE UndecidableInstances #-} | 7 | {-# LANGUAGE UndecidableInstances #-} |
7 | 8 | ||
8 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
@@ -692,12 +693,12 @@ condV f a b l e t = f a' b' l' e' t' | |||
692 | 693 | ||
693 | -------------------------------------------------------------------------------- | 694 | -------------------------------------------------------------------------------- |
694 | 695 | ||
695 | class Transposable t | 696 | class Transposable m mt | m -> mt, mt -> m |
696 | where | 697 | where |
697 | -- | (conjugate) transpose | 698 | -- | (conjugate) transpose |
698 | tr :: t -> t | 699 | tr :: m -> mt |
699 | 700 | ||
700 | instance (Container Vector t) => Transposable (Matrix t) | 701 | instance (Container Vector t) => Transposable (Matrix t) (Matrix t) |
701 | where | 702 | where |
702 | tr = ctrans | 703 | tr = ctrans |
703 | 704 | ||
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 |
139 | fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] | 139 | fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] |
140 | -} | 140 | -} |
141 | infixl 7 <.> | 141 | |
142 | (<.>) :: Contraction a b c => a -> b -> c | 142 | |
143 | (<.>) = contraction | ||
144 | 143 | ||
145 | 144 | ||
146 | class Contraction a b c | a b -> c | 145 | class Contraction a b c | a b -> c |
@@ -160,6 +159,23 @@ instance (Container Vector t, Product t) => Contraction (Vector t) (Matrix t) (V | |||
160 | instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where | 159 | instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where |
161 | contraction = mXm | 160 | contraction = mXm |
162 | 161 | ||
162 | -------------------------------------------------------------------------------- | ||
163 | |||
164 | infixl 7 <.> | ||
165 | -- | An infix synonym for 'dot' | ||
166 | (<.>) :: Numeric t => Vector t -> Vector t -> t | ||
167 | (<.>) = dot | ||
168 | |||
169 | |||
170 | infixr 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 | ||
305 | class ( 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 | |||
312 | instance Numeric Double | ||
313 | instance Numeric (Complex Double) | ||
314 | instance Numeric Float | ||
315 | instance Numeric (Complex Float) | ||
316 | |||
317 | -------------------------------------------------------------------------------- | ||