summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Vector.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/Data/Packed/Vector.hs
parent007960d648485d5c161cd366d16282bc29fac68b (diff)
refactored Data.Packed.Vector to remove any numerics
Diffstat (limited to 'lib/Data/Packed/Vector.hs')
-rw-r--r--lib/Data/Packed/Vector.hs50
1 files changed, 7 insertions, 43 deletions
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index 40dd6b5..81dfa37 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -18,9 +18,11 @@ module Data.Packed.Vector (
18 fromList, (|>), toList, buildVector, 18 fromList, (|>), toList, buildVector,
19 dim, (@>), 19 dim, (@>),
20 subVector, takesV, join, 20 subVector, takesV, join,
21 constant, linspace, 21-- moved to Numeric.LinearAlgebra.Linear
22 vecdisp, 22-- constant, linspace,
23-- moved to Numeric.LinearAlgebra.Interface typeclass 23-- moved to Data.Packed.Matrix
24-- vecdisp,
25-- moved to Numeric.LinearAlgebra.Linear typeclass
24-- vectorFMax, vectorFMin, vectorFMaxIndex, vectorFMinIndex, 26-- vectorFMax, vectorFMin, vectorFMaxIndex, vectorFMinIndex,
25-- vectorMax, vectorMin, 27-- vectorMax, vectorMin,
26 vectorMaxIndex, vectorMinIndex, 28 vectorMaxIndex, vectorMinIndex,
@@ -30,10 +32,9 @@ module Data.Packed.Vector (
30 foldLoop, foldVector, foldVectorG 32 foldLoop, foldVector, foldVectorG
31) where 33) where
32 34
33import Data.Packed.Internal 35import Data.Packed.Internal.Vector
34import Numeric.GSL.Vector 36import Numeric.GSL.Vector
35-- import Data.Packed.ST 37-- import Data.Packed.ST
36import Numeric.LinearAlgebra.Linear
37 38
38import Data.Binary 39import Data.Binary
39import Foreign.Storable 40import Foreign.Storable
@@ -72,19 +73,6 @@ instance (Binary a, Storable a) => Binary (Vector a) where
72------------------------------------------------------------------- 73-------------------------------------------------------------------
73 74
74 75
75{- | Creates a real vector containing a range of values:
76
77@\> linspace 5 (-3,7)
785 |> [-3.0,-0.5,2.0,4.5,7.0]@
79
80Logarithmic spacing can be defined as follows:
81
82@logspace n (a,b) = 10 ** linspace n (a,b)@
83-}
84linspace :: (Enum e, Linear Vector e, Element e) => Int -> (e, e) -> Vector e
85linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1]
86 where s = (b-a)/fromIntegral (n-1)
87
88{- 76{-
89vectorFMax :: Vector Float -> Float 77vectorFMax :: Vector Float -> Float
90vectorFMax = toScalarF Max 78vectorFMax = toScalarF Max
@@ -114,15 +102,6 @@ vectorMinIndex :: Vector Double -> Int
114vectorMinIndex = round . toScalarR MinIdx 102vectorMinIndex = round . toScalarR MinIdx
115 103
116 104
117{- | creates a vector with a given number of equal components:
118
119@> constant 2 7
1207 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@
121-}
122constant :: Element a => a -> Int -> Vector a
123-- constant x n = runSTVector (newVector x n)
124constant = constantD -- about 2x faster
125
126{- | creates a Vector of the specified length using the supplied function to 105{- | creates a Vector of the specified length using the supplied function to
127 to map the index to the value at that index. 106 to map the index to the value at that index.
128 107
@@ -130,26 +109,11 @@ constant = constantD -- about 2x faster
1304 |> [0.0,1.0,2.0,3.0]@ 1094 |> [0.0,1.0,2.0,3.0]@
131 110
132-} 111-}
133buildVector :: Element a => Int -> (Int -> a) -> Vector a 112buildVector :: Storable a => Int -> (Int -> a) -> Vector a
134buildVector len f = 113buildVector len f =
135 fromList $ map f [0 .. (len - 1)] 114 fromList $ map f [0 .. (len - 1)]
136 115
137 116
138{- | Show a vector using a function for showing matrices.
139
140@disp = putStr . vecdisp ('dispf' 2)
141
142\> disp ('linspace' 10 (0,1))
14310 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00
144@
145-}
146vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String
147vecdisp f v
148 = ((show (dim v) ++ " |> ") ++) . (++"\n")
149 . unwords . lines . tail . dropWhile (not . (`elem` " \n"))
150 . f . trans . reshape 1
151 $ v
152
153-- | unzip for Vectors 117-- | unzip for Vectors
154unzipVector :: (Storable a, Storable b, Storable (a,b)) => Vector (a,b) -> (Vector a,Vector b) 118unzipVector :: (Storable a, Storable b, Storable (a,b)) => Vector (a,b) -> (Vector a,Vector b)
155unzipVector = unzipVectorWith id 119unzipVector = unzipVectorWith id