summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-04 08:34:45 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-04 08:34:45 +0000
commit0a9817cc481fb09f1962eb2c272125e56a123814 (patch)
treee444abd9f1918e9a25e2b99f6c8498d0f03fcdf3 /examples
parent80673221e704b451e0d9468d6dfe1a38ad676c07 (diff)
fortran/C
Diffstat (limited to 'examples')
-rw-r--r--examples/pru.hs53
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
4import Data.Packed.Internal
5import Complex
6import Numeric(showGFloat)
7import Data.List(transpose,intersperse)
8import Foreign.Storable
9
10r >< 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
16r >|< 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
24vr = fromList [1..15::Double]
25vc = fromList (map (\x->x :+ (x+1)) [1..15::Double])
26
27mi = (2 >< 3) [1 .. 6::Int]
28mz = (2 >< 3) [1,2,3,4,5,6:+(1::Double)]
29
30ac = (2><3) [1 .. 6::Double]
31bc = (3><4) [7 .. 18::Double]
32
33af = (2>|<3) [1,4,2,5,3,6::Double]
34bf = (3>|<4) [7,11,15,8,12,16,9,13,17,10,14,18::Double]
35
36
37a |=| b = rows a == rows b &&
38 cols a == cols b &&
39 toList (dat a) == toList (dat b)
40
41mulC a b = multiply RowMajor a b
42mulF a b = multiply ColumnMajor a b
43
44cc = mulC ac bf
45cf = mulF af bc
46
47r = mulC cc (trans cf)
48
49rd = (2><2)
50 [ 43492.0, 50572.0
51 , 102550.0, 119242.0 ]
52
53main = print $ r |=| rd