diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Static.hs | 23 |
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 | |||
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(..)) | ||
9 | 10 | ||
10 | instance Lift Double where | 11 | instance 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 | 14 | instance Lift (Ptr Double) where |
15 | lift p = [e| p |] | ||
16 | |||
17 | instance Lift (ForeignPtr Double) where | ||
18 | lift p = [e| p |] | ||
19 | |||
20 | instance (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 | |||
23 | instance (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 | ||
15 | tdim :: Int -> ExpQ | 27 | tdim :: Int -> ExpQ |
16 | tdim 0 = [| Z |] | 28 | tdim 0 = [| Z |] |
@@ -46,6 +58,9 @@ vec' :: [Double] -> ExpQ | |||
46 | vec' d = [| createl ($(tdim (length d))) d |] | 58 | vec' d = [| createl ($(tdim (length d))) d |] |
47 | 59 | ||
48 | 60 | ||
61 | createm :: (Dim r, Dim c) => r -> c -> (Matrix Double) -> SMat r c Double | ||
62 | createm _ _ m = SMat m | ||
63 | |||
49 | createml :: (Dim r, Dim c) => r -> c -> Int -> Int -> [Double] -> SMat r c Double | 64 | createml :: (Dim r, Dim c) => r -> c -> Int -> Int -> [Double] -> SMat r c Double |
50 | createml _ _ r c l = SMat ((r><c) l) | 65 | createml _ _ r c l = SMat ((r><c) l) |
51 | 66 | ||
@@ -53,7 +68,11 @@ mat :: Int -> Int -> [Double] -> ExpQ | |||
53 | mat r c l = [| createml ($(tdim r)) ($(tdim c)) r c l |] | 68 | mat r c l = [| createml ($(tdim r)) ($(tdim c)) r c l |] |
54 | 69 | ||
55 | vec :: [Double] -> ExpQ | 70 | vec :: [Double] -> ExpQ |
56 | vec d = [|mat (length d) 1 d|] | 71 | vec d = mat (length d) 1 d |
72 | |||
73 | |||
74 | mat' :: Matrix Double -> ExpQ | ||
75 | mat' m = [| createm ($(tdim (rows m))) ($(tdim (cols m))) m |] | ||
57 | 76 | ||
58 | covec :: [Double] -> ExpQ | 77 | covec :: [Double] -> ExpQ |
59 | covec d = mat 1 (length d) d | 78 | covec d = mat 1 (length d) d |