summaryrefslogtreecommitdiff
path: root/testsuite/tests/array/should_run/arr017.hs
diff options
context:
space:
mode:
authorDavid Terei <davidterei@gmail.com>2011-07-20 11:09:03 -0700
committerDavid Terei <davidterei@gmail.com>2011-07-20 11:26:35 -0700
commit16514f272fb42af6e9c7674a9bd6c9dce369231f (patch)
treee4f332b45fe65e2a7a2451be5674f887b42bf199 /testsuite/tests/array/should_run/arr017.hs
parentebd422aed41048476aa61dd4c520d43becd78682 (diff)
downloadhaskell-16514f272fb42af6e9c7674a9bd6c9dce369231f.tar.gz
Move tests from tests/ghc-regress/* to just tests/*
Diffstat (limited to 'testsuite/tests/array/should_run/arr017.hs')
-rw-r--r--testsuite/tests/array/should_run/arr017.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/tests/array/should_run/arr017.hs b/testsuite/tests/array/should_run/arr017.hs
new file mode 100644
index 0000000000..18314b8e28
--- /dev/null
+++ b/testsuite/tests/array/should_run/arr017.hs
@@ -0,0 +1,30 @@
+-- Caused a crash in GHC 6.4 when optimising, due to inlining of runST too early.
+
+-- Spectral Norm benchmark
+
+import Data.Array
+import System.Environment (getArgs)
+
+main = do
+ --[arg] <- getArgs
+ --let n = (read arg) - 1
+ let n = 80
+ let init = listArray (0,n) (repeat 1.0)
+ let (v:u:rest) = drop 19 $ iterate (eval_AtA_times_u n) init
+ let vBv = sum [(u!i)*(v!i) |i<-[0..n]]
+ let vv = sum [(v!i)*(v!i) |i<-[0..n]]
+ print $ sqrt (vBv/vv)
+
+eval_AtA_times_u n u = eval_At_times_u n v
+ where v = eval_A_times_u n u
+
+eval_A x y = 1.0/((i+j)*(i+j+1)/2+i+1)
+ where i = fromIntegral x
+ j = fromIntegral y
+
+eval_A_times_u n u = accumArray (+) 0 (0,n)
+ [(i,(eval_A i j) * u!j)|i<-[0..n], j<-[0..n]]
+
+eval_At_times_u n u = accumArray (+) 0 (0,n)
+ [(i,(eval_A j i) * u!j)|i<-[0..n], j<-[0..n]]
+