summaryrefslogtreecommitdiff
path: root/examples/experiments/Static.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/experiments/Static.hs')
-rw-r--r--examples/experiments/Static.hs22
1 files changed, 7 insertions, 15 deletions
diff --git a/examples/experiments/Static.hs b/examples/experiments/Static.hs
index 385bb7b..2e4ef4e 100644
--- a/examples/experiments/Static.hs
+++ b/examples/experiments/Static.hs
@@ -6,23 +6,15 @@ 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(..))
10 9
11instance Lift Double where 10instance Lift Double where
12 lift x = return (LitE (RationalL (toRational x))) 11 lift x = return (LitE (RationalL (toRational x)))
13 12
14instance Lift (Ptr Double) where 13instance Lift (Vector a ) where
15 lift p = [e| p |] 14 lift v = [e| v |]
16 15
17instance Lift (ForeignPtr Double) where 16instance Lift (Matrix a) where
18 lift p = [e| p |] 17 lift m = [e| m |]
19
20instance (Lift a, Storable a, Lift (Ptr a), Lift (ForeignPtr a)) => Lift (Vector a ) where
21 lift (V n fp) = [e| V $(lift n) $(lift fp) |]
22
23instance (Lift (Vector a)) => Lift (Matrix a) where
24 lift (MC r c v) = [e| MC $(lift r) $(lift c) $(lift v) |]
25 lift (MF r c v) = [e| MF $(lift r) $(lift c) $(lift v) |]
26 18
27tdim :: Int -> ExpQ 19tdim :: Int -> ExpQ
28tdim 0 = [| Z |] 20tdim 0 = [| Z |]
@@ -52,7 +44,7 @@ createl d l = SVec (fromList l)
52createv :: Storable t => d -> Vector t -> SVec d t 44createv :: Storable t => d -> Vector t -> SVec d t
53createv d v = SVec v 45createv d v = SVec v
54 46
55--vec'' v = [|createv ($(tdim (dim v))) v|] 47vec'' v = [|createv ($(tdim (dim v))) v|]
56 48
57vec' :: [Double] -> ExpQ 49vec' :: [Double] -> ExpQ
58vec' d = [| createl ($(tdim (length d))) d |] 50vec' d = [| createl ($(tdim (length d))) d |]
@@ -71,8 +63,8 @@ vec :: [Double] -> ExpQ
71vec d = mat (length d) 1 d 63vec d = mat (length d) 1 d
72 64
73 65
74mat' :: Matrix Double -> ExpQ 66--mat' :: Matrix Double -> ExpQ
75mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] 67--mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |]
76 68
77covec :: [Double] -> ExpQ 69covec :: [Double] -> ExpQ
78covec d = mat 1 (length d) d 70covec d = mat 1 (length d) d