diff options
Diffstat (limited to 'packages/base/src/Numeric')
-rw-r--r-- | packages/base/src/Numeric/Container.hs | 37 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra.hs | 14 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Data.hs | 7 |
3 files changed, 35 insertions, 23 deletions
diff --git a/packages/base/src/Numeric/Container.hs b/packages/base/src/Numeric/Container.hs index 264a619..0633640 100644 --- a/packages/base/src/Numeric/Container.hs +++ b/packages/base/src/Numeric/Container.hs | |||
@@ -32,11 +32,11 @@ module Numeric.Container ( | |||
32 | diag, ident, | 32 | diag, ident, |
33 | ctrans, | 33 | ctrans, |
34 | -- * Generic operations | 34 | -- * Generic operations |
35 | Container(..), | 35 | Container(..), Transposable(..), Linear(..), |
36 | -- * Matrix product | 36 | -- * Matrix product |
37 | Product(..), udot, dot, (◇), | 37 | Product(..), udot, dot, (◇), |
38 | Mul(..), | 38 | Mul(..), |
39 | Contraction(..), | 39 | Contraction(..),(<.>), |
40 | optimiseMult, | 40 | optimiseMult, |
41 | mXm,mXv,vXm,LSDiv(..), | 41 | mXm,mXv,vXm,LSDiv(..), |
42 | outer, kronecker, | 42 | outer, kronecker, |
@@ -55,7 +55,9 @@ module Numeric.Container ( | |||
55 | IndexOf, | 55 | IndexOf, |
56 | module Data.Complex, | 56 | module Data.Complex, |
57 | -- * IO | 57 | -- * IO |
58 | module Data.Packed.IO | 58 | module Data.Packed.IO, |
59 | -- * Misc | ||
60 | Testable(..) | ||
59 | ) where | 61 | ) where |
60 | 62 | ||
61 | import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) | 63 | import Data.Packed hiding (stepD, stepF, condD, condF, conjugateC, conjugateQ) |
@@ -87,10 +89,9 @@ linspace n (a,b) = addConstant a $ scale s $ fromList $ map fromIntegral [0 .. n | |||
87 | 89 | ||
88 | -------------------------------------------------------- | 90 | -------------------------------------------------------- |
89 | 91 | ||
90 | class Contraction a b c | a b -> c | 92 | {- | Matrix product, matrix - vector product, and dot product (equivalent to 'contraction') |
91 | where | 93 | |
92 | infixl 7 <.> | 94 | (This operator can also be written using the unicode symbol ◇ (25c7).) |
93 | {- | Matrix product, matrix - vector product, and dot product | ||
94 | 95 | ||
95 | Examples: | 96 | Examples: |
96 | 97 | ||
@@ -129,22 +130,28 @@ For complex vectors the first argument is conjugated: | |||
129 | 130 | ||
130 | >>> fromList [1,i,1-i] <.> complex a | 131 | >>> fromList [1,i,1-i] <.> complex a |
131 | fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] | 132 | fromList [10.0 :+ 4.0,12.0 :+ 4.0,14.0 :+ 4.0,16.0 :+ 4.0] |
132 | |||
133 | -} | 133 | -} |
134 | (<.>) :: a -> b -> c | 134 | infixl 7 <.> |
135 | (<.>) :: Contraction a b c => a -> b -> c | ||
136 | (<.>) = contraction | ||
135 | 137 | ||
136 | 138 | ||
139 | class Contraction a b c | a b -> c | ||
140 | where | ||
141 | -- | Matrix product, matrix - vector product, and dot product | ||
142 | contraction :: a -> b -> c | ||
143 | |||
137 | instance (Product t, Container Vector t) => Contraction (Vector t) (Vector t) t where | 144 | instance (Product t, Container Vector t) => Contraction (Vector t) (Vector t) t where |
138 | u <.> v = conj u `udot` v | 145 | u `contraction` v = conj u `udot` v |
139 | 146 | ||
140 | instance Product t => Contraction (Matrix t) (Vector t) (Vector t) where | 147 | instance Product t => Contraction (Matrix t) (Vector t) (Vector t) where |
141 | (<.>) = mXv | 148 | contraction = mXv |
142 | 149 | ||
143 | instance (Container Vector t, Product t) => Contraction (Vector t) (Matrix t) (Vector t) where | 150 | instance (Container Vector t, Product t) => Contraction (Vector t) (Matrix t) (Vector t) where |
144 | (<.>) v m = (conj v) `vXm` m | 151 | contraction v m = (conj v) `vXm` m |
145 | 152 | ||
146 | instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where | 153 | instance Product t => Contraction (Matrix t) (Matrix t) (Matrix t) where |
147 | (<.>) = mXm | 154 | contraction = mXm |
148 | 155 | ||
149 | 156 | ||
150 | -------------------------------------------------------------------------------- | 157 | -------------------------------------------------------------------------------- |
@@ -229,10 +236,10 @@ instance Container Matrix e => Build (Int,Int) (e -> e -> e) Matrix e | |||
229 | 236 | ||
230 | -------------------------------------------------------------------------------- | 237 | -------------------------------------------------------------------------------- |
231 | 238 | ||
232 | -- | alternative unicode symbol (25c7) for the contraction operator '(\<.\>)' | 239 | -- | alternative unicode symbol (25c7) for 'contraction' |
233 | (◇) :: Contraction a b c => a -> b -> c | 240 | (◇) :: Contraction a b c => a -> b -> c |
234 | infixl 7 ◇ | 241 | infixl 7 ◇ |
235 | (◇) = (<.>) | 242 | (◇) = contraction |
236 | 243 | ||
237 | -- | dot product: @cdot u v = 'udot' ('conj' u) v@ | 244 | -- | dot product: @cdot u v = 'udot' ('conj' u) v@ |
238 | dot :: (Container Vector t, Product t) => Vector t -> Vector t -> t | 245 | dot :: (Container Vector t, Product t) => Vector t -> Vector t -> t |
diff --git a/packages/base/src/Numeric/LinearAlgebra.hs b/packages/base/src/Numeric/LinearAlgebra.hs index 96bf29f..549ebd0 100644 --- a/packages/base/src/Numeric/LinearAlgebra.hs +++ b/packages/base/src/Numeric/LinearAlgebra.hs | |||
@@ -37,11 +37,11 @@ module Numeric.LinearAlgebra ( | |||
37 | 37 | ||
38 | -- * Matrix product | 38 | -- * Matrix product |
39 | (<.>), | 39 | (<.>), |
40 | 40 | ||
41 | -- | This operator can also be written using the unicode symbol ◇ (25c7). | 41 | -- | The overloaded multiplication operator may need type annotations to remove |
42 | -- ambiguity. In those cases we can also use the specific functions 'mXm', 'mXv', and 'dot'. | ||
42 | -- | 43 | -- |
43 | 44 | -- The matrix x matrix product is also implemented in the "Data.Monoid" instance, where | |
44 | -- | The matrix x matrix product is also implemented in the "Data.Monoid" instance, where | ||
45 | -- single-element matrices (created from numeric literals or using 'scalar') | 45 | -- single-element matrices (created from numeric literals or using 'scalar') |
46 | -- are used for scaling. | 46 | -- are used for scaling. |
47 | -- | 47 | -- |
@@ -52,6 +52,7 @@ module Numeric.LinearAlgebra ( | |||
52 | -- , 4.0, 10.0, 0.0 ] | 52 | -- , 4.0, 10.0, 0.0 ] |
53 | -- | 53 | -- |
54 | -- 'mconcat' uses 'optimiseMult' to get the optimal association order. | 54 | -- 'mconcat' uses 'optimiseMult' to get the optimal association order. |
55 | |||
55 | 56 | ||
56 | -- * Other products | 57 | -- * Other products |
57 | outer, kronecker, cross, | 58 | outer, kronecker, cross, |
@@ -125,7 +126,7 @@ module Numeric.LinearAlgebra ( | |||
125 | RandDist(..), randomVector, rand, randn, gaussianSample, uniformSample, | 126 | RandDist(..), randomVector, rand, randn, gaussianSample, uniformSample, |
126 | 127 | ||
127 | -- * Misc | 128 | -- * Misc |
128 | meanCov, peps, relativeError, haussholder, optimiseMult, udot, Seed, (◇) | 129 | meanCov, peps, relativeError, haussholder, optimiseMult, dot, udot, mXm, mXv, smXv, (<>), (◇), Seed, checkT |
129 | ) where | 130 | ) where |
130 | 131 | ||
131 | import Numeric.LinearAlgebra.Data | 132 | import Numeric.LinearAlgebra.Data |
@@ -136,6 +137,5 @@ import Numeric.Container | |||
136 | import Numeric.LinearAlgebra.Algorithms | 137 | import Numeric.LinearAlgebra.Algorithms |
137 | import Numeric.LinearAlgebra.Util | 138 | import Numeric.LinearAlgebra.Util |
138 | import Numeric.LinearAlgebra.Random | 139 | import Numeric.LinearAlgebra.Random |
139 | 140 | import Data.Packed.Internal.Sparse(smXv) | |
140 | |||
141 | 141 | ||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 7e8af03..49bc1c0 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs | |||
@@ -48,6 +48,10 @@ module Numeric.LinearAlgebra.Data( | |||
48 | latexFormat, | 48 | latexFormat, |
49 | dispf, disps, dispcf, format, | 49 | dispf, disps, dispcf, format, |
50 | 50 | ||
51 | -- * Sparse | ||
52 | SMatrix, AssocMatrix, mkCSR, toDense, | ||
53 | mkDiag, | ||
54 | |||
51 | -- * Conversion | 55 | -- * Conversion |
52 | Convert(..), | 56 | Convert(..), |
53 | 57 | ||
@@ -56,7 +60,7 @@ module Numeric.LinearAlgebra.Data( | |||
56 | rows, cols, | 60 | rows, cols, |
57 | separable, | 61 | separable, |
58 | 62 | ||
59 | module Data.Complex | 63 | module Data.Complex, |
60 | 64 | ||
61 | ) where | 65 | ) where |
62 | 66 | ||
@@ -65,4 +69,5 @@ import Data.Packed.Matrix | |||
65 | import Numeric.Container | 69 | import Numeric.Container |
66 | import Numeric.LinearAlgebra.Util | 70 | import Numeric.LinearAlgebra.Util |
67 | import Data.Complex | 71 | import Data.Complex |
72 | import Data.Packed.Internal.Sparse | ||
68 | 73 | ||