summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2008-06-19 17:25:58 +0000
committerAlberto Ruiz <aruiz@um.es>2008-06-19 17:25:58 +0000
commitfe795ee9b1e71666d408879ce30fe6d4ca80830e (patch)
tree81e691ee455832823bebad6febde9fdf216b0b86
parent8dce18602825da9914832114283748244fa9b859 (diff)
ST bug fixed with NOINLINE newVector/Matrix
-rw-r--r--examples/inplace.hs27
-rw-r--r--lib/Data/Packed/ST.hs2
2 files changed, 29 insertions, 0 deletions
diff --git a/examples/inplace.hs b/examples/inplace.hs
index 29fac6f..9f23e0c 100644
--- a/examples/inplace.hs
+++ b/examples/inplace.hs
@@ -18,6 +18,7 @@ main = sequence_[
18 test5, 18 test5,
19 test6, 19 test6,
20 print test7, 20 print test7,
21 test8,
21 test0] 22 test0]
22 23
23-- helper functions 24-- helper functions
@@ -112,3 +113,29 @@ test0 = do
112 print m 113 print m
113 --print hv 114 --print hv
114 --print hm 115 --print hm
116
117-------------------------------------------------
118
119histogram n ds = runSTVector $ do
120 h <- newVector (0::Double) n -- number of bins
121 let inc k = modifyVector h k (+1)
122 mapM_ inc ds
123 return h
124
125-- check that newVector is really called with a fresh new array
126histoCheck ds = runSTVector $ do
127 h <- newVector (0::Double) 15 -- > constant for this test
128 let inc k = modifyVector h k (+1)
129 mapM_ inc ds
130 return h
131
132
133test8 = do
134 let ds = [0..14]
135 print $ histogram 15 ds
136 print $ histogram 15 ds
137 print $ histogram 15 ds
138 print $ histoCheck ds
139 print $ histoCheck ds
140 print $ histoCheck ds
141 putStrLn "----------------------"
diff --git a/lib/Data/Packed/ST.hs b/lib/Data/Packed/ST.hs
index 1311ff9..ed0a05e 100644
--- a/lib/Data/Packed/ST.hs
+++ b/lib/Data/Packed/ST.hs
@@ -89,6 +89,7 @@ readVector = safeIndexV unsafeReadVector
89writeVector :: Storable t => STVector s t -> Int -> t -> ST s () 89writeVector :: Storable t => STVector s t -> Int -> t -> ST s ()
90writeVector = safeIndexV unsafeWriteVector 90writeVector = safeIndexV unsafeWriteVector
91 91
92{-# NOINLINE newVector #-}
92newVector :: Element t => t -> Int -> ST s (STVector s t) 93newVector :: Element t => t -> Int -> ST s (STVector s t)
93newVector v = unsafeThawVector . constant v 94newVector v = unsafeThawVector . constant v
94 95
@@ -154,5 +155,6 @@ readMatrix = safeIndexM unsafeReadMatrix
154writeMatrix :: Storable t => STMatrix s t -> Int -> Int -> t -> ST s () 155writeMatrix :: Storable t => STMatrix s t -> Int -> Int -> t -> ST s ()
155writeMatrix = safeIndexM unsafeWriteMatrix 156writeMatrix = safeIndexM unsafeWriteMatrix
156 157
158{-# NOINLINE newMatrix #-}
157newMatrix :: Element t => t -> Int -> Int -> ST s (STMatrix s t) 159newMatrix :: Element t => t -> Int -> Int -> ST s (STMatrix s t)
158newMatrix v r c = unsafeThawMatrix . reshape c . constant v $ r*c 160newMatrix v r c = unsafeThawMatrix . reshape c . constant v $ r*c