diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-12 22:23:14 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-12 22:23:14 +0000 |
commit | 7659d9c67f75e1f665d6b02663ee8767e97762b4 (patch) | |
tree | cddaaf3156cadef9aaf564abf9d033b72f6e2e67 /lib/Numeric/LinearAlgebra | |
parent | 007960d648485d5c161cd366d16282bc29fac68b (diff) |
refactored Data.Packed.Vector to remove any numerics
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 4 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Interface.hs | 2 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Linear.hs | 33 |
3 files changed, 34 insertions, 5 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 5191480..1109296 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -21,7 +21,6 @@ imported from "Numeric.LinearAlgebra.LAPACK". | |||
21 | module Numeric.LinearAlgebra.Algorithms ( | 21 | module Numeric.LinearAlgebra.Algorithms ( |
22 | -- * Supported types | 22 | -- * Supported types |
23 | Field(), | 23 | Field(), |
24 | Vectors(..), | ||
25 | -- * Products | 24 | -- * Products |
26 | multiply, -- dot, moved dot to typeclass | 25 | multiply, -- dot, moved dot to typeclass |
27 | outer, kronecker, | 26 | outer, kronecker, |
@@ -67,7 +66,6 @@ module Numeric.LinearAlgebra.Algorithms ( | |||
67 | -- * Misc | 66 | -- * Misc |
68 | ctrans, | 67 | ctrans, |
69 | eps, i, | 68 | eps, i, |
70 | Linear(..), | ||
71 | -- * Util | 69 | -- * Util |
72 | haussholder, | 70 | haussholder, |
73 | unpackQR, unpackHess, | 71 | unpackQR, unpackHess, |
@@ -78,7 +76,7 @@ module Numeric.LinearAlgebra.Algorithms ( | |||
78 | 76 | ||
79 | 77 | ||
80 | import Data.Packed.Internal hiding ((//)) | 78 | import Data.Packed.Internal hiding ((//)) |
81 | import Data.Packed.Vector | 79 | --import Data.Packed.Vector |
82 | import Data.Packed.Matrix | 80 | import Data.Packed.Matrix |
83 | import Data.Complex | 81 | import Data.Complex |
84 | import Numeric.GSL.Vector | 82 | import Numeric.GSL.Vector |
diff --git a/lib/Numeric/LinearAlgebra/Interface.hs b/lib/Numeric/LinearAlgebra/Interface.hs index 8d2b52a..f8917a0 100644 --- a/lib/Numeric/LinearAlgebra/Interface.hs +++ b/lib/Numeric/LinearAlgebra/Interface.hs | |||
@@ -28,7 +28,7 @@ import Numeric.LinearAlgebra.Instances() | |||
28 | import Data.Packed.Vector | 28 | import Data.Packed.Vector |
29 | import Data.Packed.Matrix | 29 | import Data.Packed.Matrix |
30 | import Numeric.LinearAlgebra.Algorithms | 30 | import Numeric.LinearAlgebra.Algorithms |
31 | import Numeric.LinearAlgebra.Linear() | 31 | import Numeric.LinearAlgebra.Linear |
32 | 32 | ||
33 | --import Numeric.GSL.Vector | 33 | --import Numeric.GSL.Vector |
34 | 34 | ||
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs index 8922e51..9a7e65f 100644 --- a/lib/Numeric/LinearAlgebra/Linear.hs +++ b/lib/Numeric/LinearAlgebra/Linear.hs | |||
@@ -16,11 +16,15 @@ Basic optimized operations on vectors and matrices. | |||
16 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
17 | 17 | ||
18 | module Numeric.LinearAlgebra.Linear ( | 18 | module Numeric.LinearAlgebra.Linear ( |
19 | -- * Linear Algebra Typeclasses | ||
19 | Vectors(..), | 20 | Vectors(..), |
20 | Linear(..) | 21 | Linear(..), |
22 | -- * Creation of numeric vectors | ||
23 | constant, linspace | ||
21 | ) where | 24 | ) where |
22 | 25 | ||
23 | import Data.Packed.Internal.Vector | 26 | import Data.Packed.Internal.Vector |
27 | import Data.Packed.Internal.Matrix | ||
24 | import Data.Packed.Matrix | 28 | import Data.Packed.Matrix |
25 | import Data.Complex | 29 | import Data.Complex |
26 | import Numeric.GSL.Vector | 30 | import Numeric.GSL.Vector |
@@ -29,6 +33,7 @@ import Control.Monad(ap) | |||
29 | 33 | ||
30 | -- | basic Vector functions | 34 | -- | basic Vector functions |
31 | class Num e => Vectors a e where | 35 | class Num e => Vectors a e where |
36 | -- the C functions sumX are twice as fast as using foldVector | ||
32 | vectorSum :: a e -> e | 37 | vectorSum :: a e -> e |
33 | euclidean :: a e -> e | 38 | euclidean :: a e -> e |
34 | absSum :: a e -> e | 39 | absSum :: a e -> e |
@@ -153,3 +158,29 @@ instance (Linear Vector a, Container Matrix a) => (Linear Matrix a) where | |||
153 | divide = liftMatrix2 divide | 158 | divide = liftMatrix2 divide |
154 | equal a b = cols a == cols b && flatten a `equal` flatten b | 159 | equal a b = cols a == cols b && flatten a `equal` flatten b |
155 | scalar x = (1><1) [x] | 160 | scalar x = (1><1) [x] |
161 | |||
162 | |||
163 | ---------------------------------------------------- | ||
164 | |||
165 | {- | creates a vector with a given number of equal components: | ||
166 | |||
167 | @> constant 2 7 | ||
168 | 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ | ||
169 | -} | ||
170 | constant :: Element a => a -> Int -> Vector a | ||
171 | -- constant x n = runSTVector (newVector x n) | ||
172 | constant = constantD -- about 2x faster | ||
173 | |||
174 | {- | Creates a real vector containing a range of values: | ||
175 | |||
176 | @\> linspace 5 (-3,7) | ||
177 | 5 |> [-3.0,-0.5,2.0,4.5,7.0]@ | ||
178 | |||
179 | Logarithmic spacing can be defined as follows: | ||
180 | |||
181 | @logspace n (a,b) = 10 ** linspace n (a,b)@ | ||
182 | -} | ||
183 | linspace :: (Enum e, Linear Vector e) => Int -> (e, e) -> Vector e | ||
184 | linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1] | ||
185 | where s = (b-a)/fromIntegral (n-1) | ||
186 | |||