summaryrefslogtreecommitdiff
path: root/lib/Data/Packed
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-09 16:58:11 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-07-09 16:58:11 +0000
commitebfbc2f82813362e4840d134c57e1c9ce9518c36 (patch)
tree5b4d6a52e44eb36400fea33c8a04854c3de1b1cc /lib/Data/Packed
parent48d2f412115b56af091d54c93cee057b1ba7d382 (diff)
generalised linspace
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r--lib/Data/Packed/Matrix.hs10
-rw-r--r--lib/Data/Packed/Vector.hs10
2 files changed, 9 insertions, 11 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index e7ee781..438dabc 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -37,7 +37,7 @@ module Data.Packed.Matrix (
37 37
38import Data.Packed.Internal 38import Data.Packed.Internal
39import qualified Data.Packed.ST as ST 39import qualified Data.Packed.ST as ST
40import Data.Packed.Vector 40--import Data.Packed.Vector
41import Data.Array 41import Data.Array
42import System.Process(readProcess) 42import System.Process(readProcess)
43import Text.Printf(printf) 43import Text.Printf(printf)
@@ -113,7 +113,7 @@ adaptBlocks ms = ms' where
113 113
114 g [Just nr,Just nc] m 114 g [Just nr,Just nc] m
115 | nr == r && nc == c = m 115 | nr == r && nc == c = m
116 | r == 1 && c == 1 = reshape nc (constant x (nr*nc)) 116 | r == 1 && c == 1 = reshape nc (constantD x (nr*nc))
117 | r == 1 = fromRows (replicate nr (flatten m)) 117 | r == 1 = fromRows (replicate nr (flatten m))
118 | otherwise = fromColumns (replicate nc (flatten m)) 118 | otherwise = fromColumns (replicate nc (flatten m))
119 where 119 where
@@ -165,7 +165,7 @@ takeDiag m = fromList [flatten m `at` (k*cols m+k) | k <- [0 .. min (rows m) (co
165 165
166-- | creates the identity matrix of given dimension 166-- | creates the identity matrix of given dimension
167ident :: Element a => Int -> Matrix a 167ident :: Element a => Int -> Matrix a
168ident n = diag (constant 1 n) 168ident n = diag (constantD 1 n)
169 169
170------------------------------------------------------------ 170------------------------------------------------------------
171 171
@@ -459,7 +459,7 @@ class (Element e) => Container c e where
459instance Container Vector Float where 459instance Container Vector Float where
460 toComplex = toComplexV 460 toComplex = toComplexV
461 fromComplex = fromComplexV 461 fromComplex = fromComplexV
462 comp v = toComplex (v,constant 0 (dim v)) 462 comp v = toComplex (v,constantD 0 (dim v))
463 conj = conjV 463 conj = conjV
464 real = mapVector realToFrac 464 real = mapVector realToFrac
465 complex = (mapVector (\(r :+ i) -> (realToFrac r :+ realToFrac i))) . comp 465 complex = (mapVector (\(r :+ i) -> (realToFrac r :+ realToFrac i))) . comp
@@ -467,7 +467,7 @@ instance Container Vector Float where
467instance Container Vector Double where 467instance Container Vector Double where
468 toComplex = toComplexV 468 toComplex = toComplexV
469 fromComplex = fromComplexV 469 fromComplex = fromComplexV
470 comp v = toComplex (v,constant 0 (dim v)) 470 comp v = toComplex (v,constantD 0 (dim v))
471 conj = conjV 471 conj = conjV
472 real = id 472 real = id
473 complex = comp 473 complex = comp
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index b87372f..760f724 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -33,7 +33,7 @@ module Data.Packed.Vector (
33import Data.Packed.Internal 33import Data.Packed.Internal
34import Numeric.GSL.Vector 34import Numeric.GSL.Vector
35-- import Data.Packed.ST 35-- import Data.Packed.ST
36 36import Numeric.LinearAlgebra.Linear
37 37
38import Data.Binary 38import Data.Binary
39import Foreign.Storable 39import Foreign.Storable
@@ -81,11 +81,9 @@ Logarithmic spacing can be defined as follows:
81 81
82@logspace n (a,b) = 10 ** linspace n (a,b)@ 82@logspace n (a,b) = 10 ** linspace n (a,b)@
83-} 83-}
84linspace :: Int -> (Double, Double) -> Vector Double 84linspace :: (Enum e, Linear Vector e, Element e) => Int -> (e, e) -> Vector e
85linspace n (a,b) = add a $ scale s $ fromList [0 .. fromIntegral n-1] 85linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1]
86 where scale = vectorMapValR Scale 86 where s = (b-a)/fromIntegral (n-1)
87 add = vectorMapValR AddConstant
88 s = (b-a)/fromIntegral (n-1)
89 87
90{- 88{-
91vectorFMax :: Vector Float -> Float 89vectorFMax :: Vector Float -> Float