diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-05-13 09:58:48 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-05-13 09:58:48 +0000 |
commit | 37f71ca5188ba487d4e1c274873b187ddcb30576 (patch) | |
tree | c752b450f8d5829d2eacbe94222aeab358ceb255 /examples/experiments/speed.hs | |
parent | 6809103cf34a9345f8cb60a0ec3a8f55dd18d5ef (diff) |
removed old examples
Diffstat (limited to 'examples/experiments/speed.hs')
-rw-r--r-- | examples/experiments/speed.hs | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/examples/experiments/speed.hs b/examples/experiments/speed.hs deleted file mode 100644 index 22d7220..0000000 --- a/examples/experiments/speed.hs +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | {- speed tests | ||
2 | |||
3 | GNU-Octave (see speed.m in this folder): | ||
4 | |||
5 | ./speed.m | ||
6 | -0.017877255967426 0.000000000000000 -0.999840189089781 | ||
7 | 0.000000000000000 1.000000000000000 0.000000000000000 | ||
8 | 0.999840189089763 0.000000000000000 -0.017877255967417 | ||
9 | 9.69 seconds | ||
10 | |||
11 | Mathematica: | ||
12 | |||
13 | rot[a_]:={{ Cos[a], 0, Sin[a]}, | ||
14 | { 0, 1, 0}, | ||
15 | { -Sin[a],0,Cos[a]}}//N | ||
16 | |||
17 | test := Timing[ | ||
18 | n = 100000; | ||
19 | angles = Range[0.,n-1]/(n-1); | ||
20 | Fold[Dot,IdentityMatrix[3],rot/@angles] // MatrixForm | ||
21 | ] | ||
22 | |||
23 | 2.08013 Second | ||
24 | {{\(-0.017877255967432837`\), "0.`", \(-0.9998401890898042`\)}, | ||
25 | {"0.`", "1.`", "0.`"}, | ||
26 | {"0.9998401890898042`", "0.`", \(-0.017877255967432837`\)}} | ||
27 | |||
28 | $ ghc --make -O speed | ||
29 | |||
30 | $ ./speed 5 100000 1 | ||
31 | (3><3) | ||
32 | [ -1.7877255967425523e-2, 0.0, -0.9998401890897632 | ||
33 | , 0.0, 1.0, 0.0 | ||
34 | , 0.999840189089781, 0.0, -1.7877255967416586e-2 ] | ||
35 | 0.33 CPU seconds | ||
36 | |||
37 | cos 50000 = -0.0178772559665563 | ||
38 | sin 50000 = -0.999840189089790 | ||
39 | |||
40 | -} | ||
41 | |||
42 | import Numeric.LinearAlgebra | ||
43 | import System | ||
44 | import Data.List(foldl1') | ||
45 | import System.CPUTime | ||
46 | import Text.Printf | ||
47 | import Debug.Trace | ||
48 | |||
49 | debug x = trace (show x) x | ||
50 | |||
51 | timing act = do | ||
52 | t0 <- getCPUTime | ||
53 | act | ||
54 | t1 <- getCPUTime | ||
55 | printf "%.2f CPU seconds\n" $ (fromIntegral ((t1 - t0) `div` (10^10)) / 100 :: Double) :: IO () | ||
56 | |||
57 | op a b = trans $ (trans a) <> (trans b) | ||
58 | |||
59 | op2 a b = trans $ (trans a) + (trans b) | ||
60 | |||
61 | rot' :: Double -> Matrix Double | ||
62 | rot' a = matrix [[ c,0,s], | ||
63 | [ 0,1,0], | ||
64 | [-s,0,c]] | ||
65 | where c = cos a | ||
66 | s = sin a | ||
67 | matrix = fromLists | ||
68 | |||
69 | rot :: Double -> Matrix Double | ||
70 | rot a = (3><3) [ c,0,s | ||
71 | , 0,1,0 | ||
72 | ,-s,0,c ] | ||
73 | where c = cos a | ||
74 | s = sin a | ||
75 | |||
76 | fun n r = foldl1' (<>) (map r angles) | ||
77 | where angles = toList $ linspace n (0,1) | ||
78 | |||
79 | main = do | ||
80 | args <- getArgs | ||
81 | let [p,n,d] = map read args | ||
82 | let ms = replicate n ((ident d :: Matrix Double)) | ||
83 | let mz = replicate n (diag (constant (0::Double) d)) | ||
84 | timing $ case p of | ||
85 | 0 -> print $ foldl1' (<>) ms | ||
86 | 1 -> print $ foldl1' (<>) (map trans ms) | ||
87 | 2 -> print $ foldl1' op ms | ||
88 | 3 -> print $ foldl1' op2 mz | ||
89 | 4 -> print $ fun n rot' | ||
90 | 5 -> print $ fun n rot | ||