diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-06-04 19:10:28 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-06-04 19:10:28 +0000 |
commit | 7430630fa0504296b796223e01cbd417b88650ef (patch) | |
tree | c338dea8b82867a4c161fcee5817ed2ca27c7258 /examples | |
parent | 0a9817cc481fb09f1962eb2c272125e56a123814 (diff) |
separation of Internal
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pru.hs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/examples/pru.hs b/examples/pru.hs index 963ee17..d6dc5d4 100644 --- a/examples/pru.hs +++ b/examples/pru.hs | |||
@@ -1,7 +1,10 @@ | |||
1 | --{-# OPTIONS_GHC #-} | 1 | --{-# OPTIONS_GHC #-} |
2 | --module Main where | 2 | --module Main where |
3 | 3 | ||
4 | import Data.Packed.Internal | 4 | import Data.Packed.Internal.Vector |
5 | import Data.Packed.Internal.Matrix | ||
6 | import Data.Packed.Internal.Tensor | ||
7 | |||
5 | import Complex | 8 | import Complex |
6 | import Numeric(showGFloat) | 9 | import Numeric(showGFloat) |
7 | import Data.List(transpose,intersperse) | 10 | import Data.List(transpose,intersperse) |
@@ -50,4 +53,43 @@ rd = (2><2) | |||
50 | [ 43492.0, 50572.0 | 53 | [ 43492.0, 50572.0 |
51 | , 102550.0, 119242.0 ] | 54 | , 102550.0, 119242.0 ] |
52 | 55 | ||
53 | main = print $ r |=| rd | 56 | main = do |
57 | print $ r |=| rd | ||
58 | print $ foldl part t [("p",1),("r",2),("q",0)] | ||
59 | |||
60 | t = T [(4,(Covariant,"p")),(2,(Covariant,"q")),(3,(Contravariant,"r"))] $ fromList [1..24::Double] | ||
61 | |||
62 | |||
63 | findIdx name t = ((d1,d2),m) where | ||
64 | (d1,d2) = span (\(_,(_,n)) -> n /=name) (dims t) | ||
65 | c = product (map fst (tail d2)) | ||
66 | m = matrixFromVector RowMajor c (ten t) | ||
67 | |||
68 | |||
69 | putFirstIdx name t = | ||
70 | if null d1 | ||
71 | then (nd,m) | ||
72 | else (nd,m') | ||
73 | where ((d1,d2),m) = findIdx name t | ||
74 | m' = trans $ matrixFromVector RowMajor (fst $ head d2) $ dat m | ||
75 | nd = d2++d1 | ||
76 | |||
77 | part t (name,k) = if k<0 || k>=l | ||
78 | then error $ "part "++show (name,k)++" out of range in "++show t | ||
79 | else T {dims = ds, ten = toRows m !! k} | ||
80 | where (d:ds,m) = putFirstIdx name t | ||
81 | (l,_) = d | ||
82 | |||
83 | parts t name = map f (toRows m) | ||
84 | where (d:ds,m) = putFirstIdx name t | ||
85 | (l,_) = d | ||
86 | f t = T {dims=ds, ten=t} | ||
87 | |||
88 | t1 = T [(4,(Covariant,"p")),(4,(Contravariant,"q")),(2,(Covariant,"r"))] $ fromList [1..32::Double] | ||
89 | t2 = T [(4,(Covariant,"p")),(4,(Contravariant,"q"))] $ fromList [1..16::Double] | ||
90 | |||
91 | --contract1 t name1 name2 = map head $ zipWith drop [0..] (map (flip parts name2) (parts t name1)) | ||
92 | |||
93 | --sumT ls = foldl (zipWith (+)) [0,0..] (map (toList.ten) ls) | ||
94 | |||
95 | on f g = \x y -> f (g x) (g y) \ No newline at end of file | ||