summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-06 10:13:12 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-06 10:13:12 +0000
commit9d2073dd2cf7873006b0e831754928f7c0be52b7 (patch)
tree04e31e1359f599e07e962f2606d87b6fd1250aa5 /examples
parent3017c66ca1a77b55032f75acd529347648dfc59b (diff)
minor doc changes
Diffstat (limited to 'examples')
-rw-r--r--examples/Static.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/examples/Static.hs b/examples/Static.hs
index c4856f5..c0cfcce 100644
--- a/examples/Static.hs
+++ b/examples/Static.hs
@@ -6,11 +6,23 @@ import Language.Haskell.TH
6import Numeric.LinearAlgebra 6import Numeric.LinearAlgebra
7import Foreign 7import Foreign
8import Language.Haskell.TH.Syntax 8import Language.Haskell.TH.Syntax
9import Data.Packed.Internal(Vector(..),Matrix(..))
9 10
10instance Lift Double where 11instance Lift Double where
11 lift x = return (LitE (RationalL (toRational x))) 12 lift x = return (LitE (RationalL (toRational x)))
12 13
13--instance (Lift a, Storable a) => Lift (Vector a ) where 14instance Lift (Ptr Double) where
15 lift p = [e| p |]
16
17instance Lift (ForeignPtr Double) where
18 lift p = [e| p |]
19
20instance (Lift a, Storable a, Lift (Ptr a), Lift (ForeignPtr a)) => Lift (Vector a ) where
21 lift (V n fp p) = [e| V $(lift n) $(lift fp) $(lift p) |]
22
23instance (Lift (Vector a)) => Lift (Matrix a) where
24 lift (MC r c v vt) = [e| MC $(lift r) $(lift c) $(lift v) $(lift vt) |]
25 lift (MF r c v vt) = [e| MF $(lift r) $(lift c) $(lift v) $(lift vt) |]
14 26
15tdim :: Int -> ExpQ 27tdim :: Int -> ExpQ
16tdim 0 = [| Z |] 28tdim 0 = [| Z |]
@@ -46,6 +58,9 @@ vec' :: [Double] -> ExpQ
46vec' d = [| createl ($(tdim (length d))) d |] 58vec' d = [| createl ($(tdim (length d))) d |]
47 59
48 60
61createm :: (Dim r, Dim c) => r -> c -> (Matrix Double) -> SMat r c Double
62createm _ _ m = SMat m
63
49createml :: (Dim r, Dim c) => r -> c -> Int -> Int -> [Double] -> SMat r c Double 64createml :: (Dim r, Dim c) => r -> c -> Int -> Int -> [Double] -> SMat r c Double
50createml _ _ r c l = SMat ((r><c) l) 65createml _ _ r c l = SMat ((r><c) l)
51 66
@@ -53,7 +68,11 @@ mat :: Int -> Int -> [Double] -> ExpQ
53mat r c l = [| createml ($(tdim r)) ($(tdim c)) r c l |] 68mat r c l = [| createml ($(tdim r)) ($(tdim c)) r c l |]
54 69
55vec :: [Double] -> ExpQ 70vec :: [Double] -> ExpQ
56vec d = [|mat (length d) 1 d|] 71vec d = mat (length d) 1 d
72
73
74mat' :: Matrix Double -> ExpQ
75mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |]
57 76
58covec :: [Double] -> ExpQ 77covec :: [Double] -> ExpQ
59covec d = mat 1 (length d) d 78covec d = mat 1 (length d) d