summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-12 22:23:14 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-12 22:23:14 +0000
commit7659d9c67f75e1f665d6b02663ee8767e97762b4 (patch)
treecddaaf3156cadef9aaf564abf9d033b72f6e2e67 /lib/Numeric/LinearAlgebra
parent007960d648485d5c161cd366d16282bc29fac68b (diff)
refactored Data.Packed.Vector to remove any numerics
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs4
-rw-r--r--lib/Numeric/LinearAlgebra/Interface.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs33
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".
21module Numeric.LinearAlgebra.Algorithms ( 21module 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
80import Data.Packed.Internal hiding ((//)) 78import Data.Packed.Internal hiding ((//))
81import Data.Packed.Vector 79--import Data.Packed.Vector
82import Data.Packed.Matrix 80import Data.Packed.Matrix
83import Data.Complex 81import Data.Complex
84import Numeric.GSL.Vector 82import 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()
28import Data.Packed.Vector 28import Data.Packed.Vector
29import Data.Packed.Matrix 29import Data.Packed.Matrix
30import Numeric.LinearAlgebra.Algorithms 30import Numeric.LinearAlgebra.Algorithms
31import Numeric.LinearAlgebra.Linear() 31import 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
18module Numeric.LinearAlgebra.Linear ( 18module 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
23import Data.Packed.Internal.Vector 26import Data.Packed.Internal.Vector
27import Data.Packed.Internal.Matrix
24import Data.Packed.Matrix 28import Data.Packed.Matrix
25import Data.Complex 29import Data.Complex
26import Numeric.GSL.Vector 30import Numeric.GSL.Vector
@@ -29,6 +33,7 @@ import Control.Monad(ap)
29 33
30-- | basic Vector functions 34-- | basic Vector functions
31class Num e => Vectors a e where 35class 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
1687 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@
169-}
170constant :: Element a => a -> Int -> Vector a
171-- constant x n = runSTVector (newVector x n)
172constant = constantD -- about 2x faster
173
174{- | Creates a real vector containing a range of values:
175
176@\> linspace 5 (-3,7)
1775 |> [-3.0,-0.5,2.0,4.5,7.0]@
178
179Logarithmic spacing can be defined as follows:
180
181@logspace n (a,b) = 10 ** linspace n (a,b)@
182-}
183linspace :: (Enum e, Linear Vector e) => Int -> (e, e) -> Vector e
184linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1]
185 where s = (b-a)/fromIntegral (n-1)
186