diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-06-04 08:34:45 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-06-04 08:34:45 +0000 |
commit | 0a9817cc481fb09f1962eb2c272125e56a123814 (patch) | |
tree | e444abd9f1918e9a25e2b99f6c8498d0f03fcdf3 /examples/pru.hs | |
parent | 80673221e704b451e0d9468d6dfe1a38ad676c07 (diff) |
fortran/C
Diffstat (limited to 'examples/pru.hs')
-rw-r--r-- | examples/pru.hs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/pru.hs b/examples/pru.hs new file mode 100644 index 0000000..963ee17 --- /dev/null +++ b/examples/pru.hs | |||
@@ -0,0 +1,53 @@ | |||
1 | --{-# OPTIONS_GHC #-} | ||
2 | --module Main where | ||
3 | |||
4 | import Data.Packed.Internal | ||
5 | import Complex | ||
6 | import Numeric(showGFloat) | ||
7 | import Data.List(transpose,intersperse) | ||
8 | import Foreign.Storable | ||
9 | |||
10 | r >< c = f where | ||
11 | f l | dim v == r*c = matrixFromVector RowMajor c v | ||
12 | | otherwise = error $ "inconsistent list size = " | ||
13 | ++show (dim v) ++"in ("++show r++"><"++show c++")" | ||
14 | where v = fromList l | ||
15 | |||
16 | r >|< c = f where | ||
17 | f l | dim v == r*c = matrixFromVector ColumnMajor c v | ||
18 | | otherwise = error $ "inconsistent list size = " | ||
19 | ++show (dim v) ++"in ("++show r++"><"++show c++")" | ||
20 | where v = fromList l | ||
21 | |||
22 | |||
23 | |||
24 | vr = fromList [1..15::Double] | ||
25 | vc = fromList (map (\x->x :+ (x+1)) [1..15::Double]) | ||
26 | |||
27 | mi = (2 >< 3) [1 .. 6::Int] | ||
28 | mz = (2 >< 3) [1,2,3,4,5,6:+(1::Double)] | ||
29 | |||
30 | ac = (2><3) [1 .. 6::Double] | ||
31 | bc = (3><4) [7 .. 18::Double] | ||
32 | |||
33 | af = (2>|<3) [1,4,2,5,3,6::Double] | ||
34 | bf = (3>|<4) [7,11,15,8,12,16,9,13,17,10,14,18::Double] | ||
35 | |||
36 | |||
37 | a |=| b = rows a == rows b && | ||
38 | cols a == cols b && | ||
39 | toList (dat a) == toList (dat b) | ||
40 | |||
41 | mulC a b = multiply RowMajor a b | ||
42 | mulF a b = multiply ColumnMajor a b | ||
43 | |||
44 | cc = mulC ac bf | ||
45 | cf = mulF af bc | ||
46 | |||
47 | r = mulC cc (trans cf) | ||
48 | |||
49 | rd = (2><2) | ||
50 | [ 43492.0, 50572.0 | ||
51 | , 102550.0, 119242.0 ] | ||
52 | |||
53 | main = print $ r |=| rd | ||