diff options
Diffstat (limited to 'examples/experiments/Static.hs')
-rw-r--r-- | examples/experiments/Static.hs | 22 |
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 | |||
6 | import Numeric.LinearAlgebra | 6 | import Numeric.LinearAlgebra |
7 | import Foreign | 7 | import Foreign |
8 | import Language.Haskell.TH.Syntax | 8 | import Language.Haskell.TH.Syntax |
9 | import Data.Packed.Internal(Vector(..),Matrix(..)) | ||
10 | 9 | ||
11 | instance Lift Double where | 10 | instance Lift Double where |
12 | lift x = return (LitE (RationalL (toRational x))) | 11 | lift x = return (LitE (RationalL (toRational x))) |
13 | 12 | ||
14 | instance Lift (Ptr Double) where | 13 | instance Lift (Vector a ) where |
15 | lift p = [e| p |] | 14 | lift v = [e| v |] |
16 | 15 | ||
17 | instance Lift (ForeignPtr Double) where | 16 | instance Lift (Matrix a) where |
18 | lift p = [e| p |] | 17 | lift m = [e| m |] |
19 | |||
20 | instance (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 | |||
23 | instance (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 | ||
27 | tdim :: Int -> ExpQ | 19 | tdim :: Int -> ExpQ |
28 | tdim 0 = [| Z |] | 20 | tdim 0 = [| Z |] |
@@ -52,7 +44,7 @@ createl d l = SVec (fromList l) | |||
52 | createv :: Storable t => d -> Vector t -> SVec d t | 44 | createv :: Storable t => d -> Vector t -> SVec d t |
53 | createv d v = SVec v | 45 | createv d v = SVec v |
54 | 46 | ||
55 | --vec'' v = [|createv ($(tdim (dim v))) v|] | 47 | vec'' v = [|createv ($(tdim (dim v))) v|] |
56 | 48 | ||
57 | vec' :: [Double] -> ExpQ | 49 | vec' :: [Double] -> ExpQ |
58 | vec' d = [| createl ($(tdim (length d))) d |] | 50 | vec' d = [| createl ($(tdim (length d))) d |] |
@@ -71,8 +63,8 @@ vec :: [Double] -> ExpQ | |||
71 | vec d = mat (length d) 1 d | 63 | vec d = mat (length d) 1 d |
72 | 64 | ||
73 | 65 | ||
74 | mat' :: Matrix Double -> ExpQ | 66 | --mat' :: Matrix Double -> ExpQ |
75 | mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] | 67 | --mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] |
76 | 68 | ||
77 | covec :: [Double] -> ExpQ | 69 | covec :: [Double] -> ExpQ |
78 | covec d = mat 1 (length d) d | 70 | covec d = mat 1 (length d) d |