summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Linear.hs
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/Linear.hs
parent007960d648485d5c161cd366d16282bc29fac68b (diff)
refactored Data.Packed.Vector to remove any numerics
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Linear.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs33
1 files changed, 32 insertions, 1 deletions
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