summaryrefslogtreecommitdiff
path: root/examples/pru.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pru.hs')
-rw-r--r--examples/pru.hs27
1 files changed, 6 insertions, 21 deletions
diff --git a/examples/pru.hs b/examples/pru.hs
index 10789d2..a90aa6f 100644
--- a/examples/pru.hs
+++ b/examples/pru.hs
@@ -1,9 +1,11 @@
1--{-# OPTIONS_GHC #-} 1--{-# OPTIONS_GHC #-}
2--module Main where 2--module Main where
3 3
4import Data.Packed.Internal
4import Data.Packed.Internal.Vector 5import Data.Packed.Internal.Vector
5import Data.Packed.Internal.Matrix 6import Data.Packed.Internal.Matrix
6import Data.Packed.Internal.Tensor 7import Data.Packed.Internal.Tensor
8import Data.Packed.Matrix
7import LAPACK 9import LAPACK
8 10
9import Complex 11import Complex
@@ -11,17 +13,6 @@ import Numeric(showGFloat)
11import Data.List(transpose,intersperse,sort) 13import Data.List(transpose,intersperse,sort)
12import Foreign.Storable 14import Foreign.Storable
13 15
14r >< c = f where
15 f l | dim v == r*c = matrixFromVector RowMajor c v
16 | otherwise = error $ "inconsistent list size = "
17 ++show (dim v) ++"in ("++show r++"><"++show c++")"
18 where v = fromList l
19
20r >|< c = f where
21 f l | dim v == r*c = matrixFromVector ColumnMajor c v
22 | otherwise = error $ "inconsistent list size = "
23 ++show (dim v) ++"in ("++show r++"><"++show c++")"
24 where v = fromList l
25 16
26vr = fromList [1..15::Double] 17vr = fromList [1..15::Double]
27vc = fromList (map (\x->x :+ (x+1)) [1..15::Double]) 18vc = fromList (map (\x->x :+ (x+1)) [1..15::Double])
@@ -49,8 +40,10 @@ cf = mulF af bc
49r = mulC cc (trans cf) 40r = mulC cc (trans cf)
50 41
51rd = (2><2) 42rd = (2><2)
52 [ 43492.0, 50572.0 43 [ 27736.0, 65356.0
53 , 102550.0, 119242.0 ] 44 , 65356.0, 154006.0 ]
45
46
54 47
55main = do 48main = do
56 print $ r |=| rd 49 print $ r |=| rd
@@ -77,7 +70,6 @@ e i n = fromList [ delta k i | k <- [1..n]]
77 70
78diagl = diag.fromList 71diagl = diag.fromList
79 72
80ident n = diag (constant n 1)
81 73
82tensorFromVector idx v = T {dims = [(dim v,idx)], ten = v} 74tensorFromVector idx v = T {dims = [(dim v,idx)], ten = v}
83tensorFromMatrix idxr idxc m = T {dims = [(rows m,idxr),(cols m,idxc)], ten = cdat m} 75tensorFromMatrix idxr idxc m = T {dims = [(rows m,idxr),(cols m,idxc)], ten = cdat m}
@@ -107,10 +99,3 @@ pru = do
107 print $ normal t2 99 print $ normal t2
108 print $ foldl part t2 [("j'",0),("p",1),("r",1)] 100 print $ foldl part t2 [("j'",0),("p",1),("r",1)]
109 101
110
111names t = sort $ map (snd.snd) (dims t)
112
113normal t = tridx (names t) t
114
115contractions t1 t2 = [ contraction t1 n1 t2 n2 | n1 <- names t1, n2 <- names t2, compatIdx t1 n1 t2 n2 ]
116